mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-31 19:12:20 +08:00
Merge pull request #25949 from wellth-app/pg-format
adding types and tests for pg-format module
This commit is contained in:
23
types/pg-format/index.d.ts
vendored
Normal file
23
types/pg-format/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
64
types/pg-format/pg-format-tests.ts
Normal file
64
types/pg-format/pg-format-tests.ts
Normal 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);
|
||||
23
types/pg-format/tsconfig.json
Normal file
23
types/pg-format/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
3
types/pg-format/tslint.json
Normal file
3
types/pg-format/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user