mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
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:
14
types/recase/index.d.ts
vendored
Normal file
14
types/recase/index.d.ts
vendored
Normal 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;
|
||||
33
types/recase/recase-tests.ts
Normal file
33
types/recase/recase-tests.ts
Normal 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']);
|
||||
22
types/recase/tsconfig.json
Normal file
22
types/recase/tsconfig.json
Normal 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
1
types/recase/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
16
types/relaxed-json/index.d.ts
vendored
Normal file
16
types/relaxed-json/index.d.ts
vendored
Normal 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;
|
||||
49
types/relaxed-json/relaxed-json-tests.ts
Normal file
49
types/relaxed-json/relaxed-json-tests.ts
Normal 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');
|
||||
22
types/relaxed-json/tsconfig.json
Normal file
22
types/relaxed-json/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/relaxed-json/tslint.json
Normal file
1
types/relaxed-json/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user