From 79c02230b2a05e4ea8f9dc7f6083a62c1f166b95 Mon Sep 17 00:00:00 2001 From: Mathew Rumsey Date: Tue, 1 May 2018 12:19:57 -0400 Subject: [PATCH] cloner - new typings - tested (#25406) --- types/cloner/cloner-tests.ts | 43 ++++++++++++++++++++++++++++++++++ types/cloner/index.d.ts | 45 ++++++++++++++++++++++++++++++++++++ types/cloner/tsconfig.json | 23 ++++++++++++++++++ types/cloner/tslint.json | 1 + 4 files changed, 112 insertions(+) create mode 100644 types/cloner/cloner-tests.ts create mode 100644 types/cloner/index.d.ts create mode 100644 types/cloner/tsconfig.json create mode 100644 types/cloner/tslint.json diff --git a/types/cloner/cloner-tests.ts b/types/cloner/cloner-tests.ts new file mode 100644 index 0000000000..63baf4b950 --- /dev/null +++ b/types/cloner/cloner-tests.ts @@ -0,0 +1,43 @@ +import cloner = require("cloner"); + +interface A { + test: string; + nest: { + test: string; + num: number; + }; +} + +interface B { + somethingElse: string; + nest: { + somethingElse: string; + notNaN: number; + }; +} + +let aO: A; +let aN: A; +let bO: B; +let bN: B; + +aO = { + test: "test", + nest: { + test: "nestTest", + num: 1 + } +}; +bO = { + somethingElse: "se", + nest: { + somethingElse: "nestSe", + notNaN: 0 + } +}; + +aN = cloner.deep.copy(aO); +bN = cloner.shallow.copy(bO); + +aN = cloner.deep.merge(aO, bO); +bN = cloner.shallow.merge(aO, bO); diff --git a/types/cloner/index.d.ts b/types/cloner/index.d.ts new file mode 100644 index 0000000000..6021c9a716 --- /dev/null +++ b/types/cloner/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for cloner 0.4 +// Project: https://github.com/WebReflection/cloner +// Definitions by: matrumz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Deep-style methods that will perform operations by value, instead of reference. + */ +export namespace deep { + /** + * Will loop over all own keys and deeply copy (copy by value) them to a new object. + * + * Preserves inheritance and is recursion aware, meaning it shouldn't fail with recursive properties. + * @param [obj] The object to copy. + */ + function copy(obj: T): T; + /** + * Preserves what's already in the target and merges all own keys found in one or more passed sources. + * + * Properties are merged by value. + * @param [target] Destination object for merged properties. + * @param [sources] Source object(s) for properties to merge. + */ + function merge(target: any, ...sources: any[]): any; +} +/** + * Shallow-style methods that will perform operations by reference, instead of value. + */ +export namespace shallow { + /** + * Will loop over all own keys and shallow copy (copy by reference) them to a new object. + * + * Preserves inheritance and is recursion aware, meaning it shouldn't fail with recursive properties. + * @param [obj] The object to copy. + */ + function copy(obj: T): T; + /** + * Preserves what's already in the target and merges all own keys found in one or more passed sources. + * + * Properties are merged by reference. + * @param [target] Destination object for merged properties. + * @param [sources] Source object(s) for properties to merge. + */ + function merge(target: any, ...sources: any[]): any; +} diff --git a/types/cloner/tsconfig.json b/types/cloner/tsconfig.json new file mode 100644 index 0000000000..9619614ce4 --- /dev/null +++ b/types/cloner/tsconfig.json @@ -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", + "cloner-tests.ts" + ] +} diff --git a/types/cloner/tslint.json b/types/cloner/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cloner/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }