mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[simple-diff] Add simple-diff types (#47956)
* [simple-diff] Add simple-diff types * Fix * More lint * Rename * Fix
This commit is contained in:
parent
4fd4a572b9
commit
523b733dbe
101
types/simple-diff/index.d.ts
vendored
Normal file
101
types/simple-diff/index.d.ts
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
// Type definitions for simple-diff 1.6
|
||||
// Project: https://github.com/redexp/simple-diff#readme
|
||||
// Definitions by: Nathan Bierema <https://github.com/Methuselah96>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace simpleDiff {
|
||||
type Path = Array<string | number>;
|
||||
|
||||
interface AddEvent {
|
||||
oldPath: Path;
|
||||
newPath: Path;
|
||||
type: 'add';
|
||||
oldValue: undefined;
|
||||
newValue: unknown;
|
||||
}
|
||||
|
||||
interface RemoveEvent {
|
||||
oldPath: Path;
|
||||
newPath: Path;
|
||||
type: 'remove';
|
||||
oldValue: unknown;
|
||||
newValue: undefined;
|
||||
}
|
||||
|
||||
interface ChangeEvent {
|
||||
oldPath: Path;
|
||||
newPath: Path;
|
||||
type: 'change';
|
||||
oldValue: unknown;
|
||||
newValue: unknown;
|
||||
}
|
||||
|
||||
interface AddItemEvent {
|
||||
oldPath: Path;
|
||||
newPath: Path;
|
||||
type: 'add-item';
|
||||
oldIndex: -1;
|
||||
curIndex: -1;
|
||||
newIndex: number;
|
||||
newValue: unknown;
|
||||
}
|
||||
|
||||
interface RemoveItemEvent {
|
||||
oldPath: Path;
|
||||
newPath: Path;
|
||||
type: 'remove-item';
|
||||
oldIndex: number;
|
||||
curIndex: number;
|
||||
newIndex: -1;
|
||||
oldValue: unknown;
|
||||
}
|
||||
|
||||
interface MoveItemEvent {
|
||||
oldPath: Path;
|
||||
newPath: Path;
|
||||
type: 'move-item';
|
||||
oldIndex: number;
|
||||
curIndex: number;
|
||||
newIndex: number;
|
||||
}
|
||||
|
||||
type Event =
|
||||
| AddEvent
|
||||
| RemoveEvent
|
||||
| ChangeEvent
|
||||
| AddItemEvent
|
||||
| RemoveItemEvent
|
||||
| MoveItemEvent;
|
||||
|
||||
interface Options {
|
||||
idProp?: string;
|
||||
idProps?: {
|
||||
[path: string]: string;
|
||||
};
|
||||
comparators?: Array<[
|
||||
unknown,
|
||||
(
|
||||
oldValue: unknown,
|
||||
newValue: unknown,
|
||||
options: { oldPath: Path; newPath: Path }
|
||||
) => boolean
|
||||
]>;
|
||||
ignore?: (
|
||||
oldValue: unknown,
|
||||
newValue: unknown,
|
||||
options: { oldPath: Path; newPath: Path }
|
||||
) => boolean;
|
||||
callback?: (event: Event) => void;
|
||||
addEvent?: string;
|
||||
changeEvent?: string;
|
||||
removeEvent?: string;
|
||||
addItemEvent?: string;
|
||||
removeItemEvent?: string;
|
||||
moveItemEvent?: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare function simpleDiff(oldObj: unknown, newObj: unknown, options?: simpleDiff.Options): simpleDiff.Event[];
|
||||
|
||||
export as namespace simpleDiff;
|
||||
export = simpleDiff;
|
||||
17
types/simple-diff/simple-diff-tests.ts
Normal file
17
types/simple-diff/simple-diff-tests.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import diff = require('simple-diff');
|
||||
|
||||
declare const oldObject: unknown;
|
||||
declare const newObject: unknown;
|
||||
|
||||
const changes = diff(oldObject, newObject, {
|
||||
idProp: '_id',
|
||||
idProps: {
|
||||
"prop1.prop2.*.prop3": "cid"
|
||||
},
|
||||
comparators: [
|
||||
[Date, (a, b, ops) => true]
|
||||
],
|
||||
ignore: (a, b, { oldPath }) => {
|
||||
return oldPath.join('.') === 'prop.test1';
|
||||
}
|
||||
});
|
||||
23
types/simple-diff/tsconfig.json
Normal file
23
types/simple-diff/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"simple-diff-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/simple-diff/tslint.json
Normal file
1
types/simple-diff/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user