santigimeno / node-pcsclite

Bindings over pcsclite to access Smart Cards
ISC License
170 stars 125 forks source link

Typings #63

Closed kainoffke closed 3 years ago

kainoffke commented 7 years ago

Hi,

We will start a new project using your really nice library. Since we are going to use Typescript as our language of choice I sat down and wrote the typings. I asked myself if you would like to incorporate these typings in your project or if you would rather like to see them in the DefinitelyTyped-repository.

They may be not yet perfect but they work ;)

Just let me know if I should create a PR.

santigimeno commented 7 years ago

@kainoffke, hi! tbh I don't know anything about Typescript. What do you think it's the best option? any pros / cons doing one way or the other? Thanks!

kainoffke commented 7 years ago

The only pro I can think of, is that people using your library in a Typescript based project can access the typings without further dependencies.

A con might be, that hosting the typings inside your repo could imply that you are the one keeping them up to date. Which is actually a big con if you don't really care about Typescript. In that case I would rather try to get them published at DefinitelyTyped.

You could then just link to the typings, if you'd like to do so.

santigimeno commented 7 years ago

@kainoffke thanks for the thorough answer and sorry for the delay, somehow I missed your response. From what you say, probably the best option would be the 2nd one: you publish them to DefinitelyTyped and the we could add a link to the typings in the README.md. (maybe you could send a PR for that :) ). Does that sound good? Thanks!

jorispz commented 6 years ago

Hi @kainoffke, I recently moved my pcsclite-based project over to TypeScript, and I would love to reuse the type definitions you have created. Are they available anywhere?

kainoffke commented 6 years ago

Hi @jorispz. We never published them anywhere since we started using a fork of this project (@pokusew/pcsclite). This made it hard to publish them at DefinitelyTyped.

The definitions may not be complete but this is what we are currently working with. Maybe it can get you started:

pcsclite.d.ts

export = PCSCLite;

declare function PCSCLite(): PCSCLite.PcSc

declare namespace PCSCLite {

    export class PcSc {
        on(event: 'reader', callback: (reader: CardReader) => void): void
        on(event: 'error', callback: (error: Error) => void): void
        close(): void
    }

    export class CardReader {
        name: string
        state: number

        connect(options: CardReaderOptions, callback: (error: Error, protocol: number) => void): void
        disconnect(disposition: number, callback: (error: Error) => void): void
        transmit(buffer: Buffer, len: number, protocol: number, callback: (error: Error, data: Buffer) => void): void

        on(event: 'error', callback: (error: Error) => void): void
        on(event: 'status', callback: (status: Status) => void): void
        on(event: 'end', callback: () => void): void

        close(): void
    }

    export class Status {
        state: number
        atr?: string
    }

    export class CardReaderOptions {
        share_mode?: number
        protocol?: number
    }
jorispz commented 6 years ago

I am using the same fork, so this is perfect, thanks!

Op vr 17 aug. 2018 07:20 schreef kainoffke notifications@github.com:

Hi @jorispz https://github.com/jorispz. We never published them anywhere since we started using a fork of this project (@pokusew/pcsclite). This made it hard to publish them at DefinitelyTyped.

The definitions may not be complete but this is what we are currently working with. Maybe it can get you started:

pcsclite.d.ts

export = PCSCLite;

declare function PCSCLite(): PCSCLite.PcSc

declare namespace PCSCLite {

export class PcSc {
    on(event: 'reader', callback: (reader: CardReader) => void): void
    on(event: 'error', callback: (error: Error) => void): void
    close(): void
}

export class CardReader {
    name: string
    state: number

    connect(options: CardReaderOptions, callback: (error: Error, protocol: number) => void): void
    disconnect(disposition: number, callback: (error: Error) => void): void
    transmit(buffer: Buffer, len: number, protocol: number, callback: (error: Error, data: Buffer) => void): void

    on(event: 'error', callback: (error: Error) => void): void
    on(event: 'status', callback: (status: Status) => void): void
    on(event: 'end', callback: () => void): void

    close(): void
}

export class Status {
    state: number
    atr?: string
}

export class CardReaderOptions {
    share_mode?: number
    protocol?: number
}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/santigimeno/node-pcsclite/issues/63#issuecomment-413760490, or mute the thread https://github.com/notifications/unsubscribe-auth/ACGby1zH6Gxe-f5M8JFqhaSWb_8A2Fpyks5uRlKcgaJpZM4Lz5Tx .

lewixlabs commented 5 years ago

Yes thank you! I used the same fork to build my TypeScript wrapper, if anybody is interested is here: https://github.com/lewixlabs/TsCard 👍