Add Recase typings (#15744)

* Add Recase typings

* Add relaxed-json type definitions

* Update Recase and Relaxed-JSON types as per PR review

* Update Recase and Relaxed-JSON types
This commit is contained in:
Mikal Madsen
2017-05-02 00:19:16 +02:00
committed by Andy
parent 3a5fa63942
commit ea345679fb
8 changed files with 158 additions and 0 deletions

14
types/recase/index.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
// Type definitions for Recase 1.0
// Project: https://www.npmjs.com/package/recase
// Definitions by: Mikal Madsen <https://github.com/18steps>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface Recase {
camelCopy(orig: any): any;
snakeCopy(orig: any): any;
}
export function create(opts: {
exceptions?: {
[origKey: string]: string;
};
}): Recase;

View File

@@ -0,0 +1,33 @@
import * as Recase from 'recase';
const recase = Recase.create({exceptions: {FOO: 'foo'}});
const snake = recase.snakeCopy(
{
FOO: 1, // Exception
abcXyz: { // Normal
_abcXyz: [ // private
{__abcXyz: 1}, // very private
{___abcXyz: 1}, // very very private
],
},
},
);
const camel = recase.camelCopy(
{
foo: 1, // Exception
abc_xyz: { // Normal
_abc_xyz: [ // private
{__abc_xyz: 1}, // very private
{___abc_xyz: 1}, // very very private
],
},
},
);
recase.snakeCopy(1);
recase.camelCopy(2);
recase.snakeCopy('a');
recase.camelCopy('b');
recase.snakeCopy(['c', '1']);
recase.snakeCopy(['d', '1']);

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"recase-tests.ts"
]
}

1
types/recase/tslint.json Normal file
View File

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

16
types/relaxed-json/index.d.ts vendored Normal file
View File

@@ -0,0 +1,16 @@
// Type definitions for relaxed-json 1.0
// Project: https://github.com/phadej/relaxed-json
// Definitions by: Mikal Madsen <https://github.com/18steps>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export type Reviver = (this: {}, key: string, value: any) => any;
export function transform(text: string): string;
export function parse(text: string, reviver: Reviver): {};
export function parse(text: string, opts?: {
reviver?: Reviver,
relaxed?: boolean,
warnings?: boolean,
tolerant?: boolean,
duplicate?: boolean,
}): {};
export function stringify(obj: any): string;

View File

@@ -0,0 +1,49 @@
import * as RJSON from 'relaxed-json';
const relaxedString = `
{ // comment
foo: "bar", // identifier
"arr": [1,2,3,], // trailing comma in array
"single-quoted": 'string',
'trailing': 4,
},
`;
RJSON.transform(relaxedString);
function revive(key: string, value: any): any {
return typeof value === 'number'
? value * 2 // return value * 2 for numbers
: value; // return everything else unchanged
}
RJSON.parse(relaxedString, revive);
RJSON.parse(relaxedString, {
reviver: revive,
relaxed: true,
warnings: true,
tolerant: true,
duplicate: true,
});
RJSON.parse(relaxedString, {
tolerant: false,
duplicate: true,
});
RJSON.parse(relaxedString, {
reviver: revive,
});
RJSON.parse(relaxedString, {});
const parsed = RJSON.parse(relaxedString);
RJSON.stringify(parsed);
RJSON.stringify({
foo: 'bar',
});
RJSON.stringify([1, 2, 3]);
RJSON.stringify(3);
RJSON.stringify('a');

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"relaxed-json-tests.ts"
]
}

View File

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