J'essaie de faire fonctionner un package uuid
(v 3.0.1) dans l'application Node/TypeScript, mais je ne suis pas sûr de savoir quoi importer et comment l'utiliser.
Ceci est index.d.ts
(de @types/uuid
v 2.0.29):
declare namespace uuid {
interface V1Options {
node?: number[];
clockseq?: number;
msecs?: number | Date;
nsecs?: number;
}
type V4Options = { random: number[] } | { rng: () => number[]; }
interface UuidStatic {
(options?: V4Options): string;
(options: V4Options | null, buffer: number[], offset?: number): number[];
(options: V4Options | null, buffer: Buffer, offset?: number): Buffer;
v1(options?: V1Options): string;
v1(options: V1Options | null, buffer: number[], offset?: number): number[];
v1(options: V1Options | null, buffer: Buffer, offset?: number): Buffer;
v4: UuidStatic;
parse(id: string): number[];
parse(id: string, buffer: number[], offset?: number): number[];
parse(id: string, buffer: Buffer, offset?: number): Buffer;
unparse(buffer: number[] | Buffer, offset?: number): string;
}
}
declare const uuid: uuid.UuidStatic
export = uuid
Je ne trouve pas la classe exportée ici.
Par exemple, index.d.ts
à partir de angular2-uuid
ressemble à ceci:
export declare class UUID {
constructor();
static UUID(): string;
private static pad4(num);
private static random4();
}
Et c'est assez évident d'utiliser:
let id = UUID.UUID();
Alors. Comment utiliser (importer et appeler) uuid
?
Oui, voici le code de mon projet:
import { v4 as uuid } from 'uuid';
const id: string = uuid();
Selon les tests:
import uuid = require('uuid');
let uuidv4: string = uuid.v4();
import * as uuid from "uuid";
const id: string = uuid.v4();