Merge pull request #25949 from wellth-app/pg-format

adding types and tests for pg-format module
This commit is contained in:
Daniel Rosenwasser
2018-05-27 01:13:22 -07:00
committed by GitHub
4 changed files with 113 additions and 0 deletions

23
types/pg-format/index.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
// Type definitions for pg-format 1.0
// Project: https://github.com/datalanche/node-pg-format
// Definitions by: Alec Zopf <https://github.com/zopf>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="node"/>
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;
}

View File

@@ -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);

View File

@@ -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"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}