diff --git a/types/gtin/gtin-tests.ts b/types/gtin/gtin-tests.ts new file mode 100644 index 0000000000..90d50fdd98 --- /dev/null +++ b/types/gtin/gtin-tests.ts @@ -0,0 +1,10 @@ +import * as gtin from 'gtin'; + +gtin.isGTIN('12341238'); // $ExpectType boolean +gtin.validate('12341238'); // $ExpectType boolean +gtin.minify('0000012341238'); // $ExpectType string +gtin.getFormat('12341238'); // $ExpectType GtinFormat +gtin.getRealFormat('1234123412344'); // $ExpectType GtinFormat + +gtin.upce.compress('1200000789'); // $ExpectType string | null +gtin.upce.expand('127890'); // $ExpectType string diff --git a/types/gtin/index.d.ts b/types/gtin/index.d.ts new file mode 100644 index 0000000000..27e0ec31c8 --- /dev/null +++ b/types/gtin/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for gtin 0.3 +// Project: https://github.com/xbpf/gtin +// Definitions by: RafaelKr +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace gtin; + +export type GtinFormat = 'GTIN-8' | 'GTIN-12' | 'GTIN-13' | 'GTIN-14'; + +export function isGTIN(gtin: string): boolean; +export function validate(gtin: string): boolean; +export function minify(gtin: string): string; +export function getFormat(gtin: string): GtinFormat; +export function getRealFormat(gtin: string): GtinFormat; + +export namespace upce { + function compress(gtin: string): string | null; + function expand(gtin: string): string; +} diff --git a/types/gtin/tsconfig.json b/types/gtin/tsconfig.json new file mode 100644 index 0000000000..1269d22feb --- /dev/null +++ b/types/gtin/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "strictFunctionTypes": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gtin-tests.ts" + ] +} diff --git a/types/gtin/tslint.json b/types/gtin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/gtin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }