feat: add remotedev-serialize types (#34063)

This commit is contained in:
Julian Hundeloh 2019-03-30 04:54:02 +01:00 committed by Ron Buckton
parent 2fa6645d81
commit 55ebcedca6
5 changed files with 82 additions and 0 deletions

44
types/remotedev-serialize/index.d.ts vendored Normal file
View File

@ -0,0 +1,44 @@
// Type definitions for remotedev-serialize 1.0
// Project: https://github.com/zalmoxisus/remotedev-serialize/
// Definitions by: Julian Hundeloh <https://github.com/jaulz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
import * as Immutable from 'immutable';
export type Options = Record<string, boolean>;
export type Refs = Record<string, any>;
export type DefaultReplacer = (key: string, value: any) => any;
export type Replacer = (
key: string,
value: any,
replacer: DefaultReplacer
) => any;
export type DefaultReviver = (key: string, value: any) => any;
export type Reviver = (key: string, value: any, reviver: DefaultReviver) => any;
export function immutable(
immutable: typeof Immutable,
refs?: Refs,
customReplacer?: Replacer,
customReviver?: Reviver
): {
stringify: (input: any) => string;
parse: (input: string) => any;
serialize: (
immutable: typeof Immutable,
refs?: Refs,
customReplacer?: Replacer,
customReviver?: Reviver
) => {
replacer: Replacer;
reviver: Reviver;
options: Options;
};
};

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"immutable": "^3.8.1"
}
}

View File

@ -0,0 +1,8 @@
import * as Immutable from 'immutable';
import * as Serialize from 'remotedev-serialize';
const { stringify, parse } = Serialize.immutable(Immutable);
const data = Immutable.fromJS({foo: 'bar', baz: {qux: 42}});
const serialized = stringify(data);
const parsed = parse(serialized);

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",
"remotedev-serialize-tests.ts"
]
}

View File

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