diff --git a/types/pg-format/index.d.ts b/types/pg-format/index.d.ts new file mode 100644 index 0000000000..e1de1f2ba4 --- /dev/null +++ b/types/pg-format/index.d.ts @@ -0,0 +1,23 @@ +// Type definitions for pg-format 1.0 +// Project: https://github.com/datalanche/node-pg-format +// Definitions by: Alec Zopf +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 +/// +export = format; + +declare function format(fmt: string, ...args: any[]): string; + +declare namespace format { + function config(config?: { + pattern: { + ident?: string, + literal?: string, + string?: string + } + }): void; + function ident(val: string | number | boolean | any[] | Date): string; + function literal(val: string | number | boolean | any[] | Date | object | null | undefined): string; + function string(val: string | number | boolean | any[] | Date | object | null | undefined): string; + function withArray(fmt: string, array: any[]): string; +} diff --git a/types/pg-format/pg-format-tests.ts b/types/pg-format/pg-format-tests.ts new file mode 100644 index 0000000000..e6239ef575 --- /dev/null +++ b/types/pg-format/pg-format-tests.ts @@ -0,0 +1,64 @@ +import format = require('pg-format'); + +const testDate = new Date(Date.UTC(2012, 11, 14, 13, 6, 43, 152)); +const testArray = [ 'abc', 1, true, null, testDate ]; +const testIdentArray = [ 'abc', 'AbC', 1, true, testDate ]; +const testObject = { a: 1, b: 2 }; +const testNestedArray = [ [1, 2], [3, 4], [5, 6] ]; + +format.config({ + pattern: { + ident: 'V', + literal: 'C', + string: 't' + } +}); +format.config(); + +format('some %s thing %s', 'long', 'here'); +format('%L', testNestedArray); + +format.withArray('some %s thing %s', [ 'long', 'here' ]); +format.withArray('many %s %s', ['things', testNestedArray]); + +format.string(undefined); +format.string(null); +format.string(true); +format.string(false); +format.string(0); +format.string(15); +format.string(-15); +format.string(45.13); +format.string(-45.13); +format.string('something'); +format.string(testArray); +format.string(testNestedArray); +format.string(testDate); +format.string(testObject); + +format.ident(true); +format.ident(false); +format.ident(0); +format.ident(15); +format.ident(-15); +format.ident(45.13); +format.ident(-45.13); +format.ident('something'); +format.ident(testIdentArray); +format.ident(testNestedArray); +format.ident(testDate); + +format.literal(null); +format.literal(undefined); +format.literal(true); +format.literal(false); +format.literal(0); +format.literal(15); +format.literal(-15); +format.literal(45.13); +format.literal(-45.13); +format.literal('something'); +format.literal(testArray); +format.literal(testNestedArray); +format.literal(testDate); +format.literal(testObject); diff --git a/types/pg-format/tsconfig.json b/types/pg-format/tsconfig.json new file mode 100644 index 0000000000..185d95cd07 --- /dev/null +++ b/types/pg-format/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pg-format-tests.ts" + ] +} diff --git a/types/pg-format/tslint.json b/types/pg-format/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/pg-format/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}