diff --git a/README.md b/README.md index 99c5185f..cae62bdb 100644 --- a/README.md +++ b/README.md @@ -595,6 +595,29 @@ Runs the given tasks in a sequence. ``` +#### clone + +Clones the given Date object. + +##### Type signature + + +```typescript +(date: Date) => Date +``` + + +##### Examples + + +```javascript +const date = new new Date('2019-04-24T13:54:33.232Z'); +const cloned = clone(date); + +cloned !== date && cloned.valueOf() === date.valueOf(); // ⇒ true +``` + + #### dateDiff ##### Type signature diff --git a/date/README.md b/date/README.md index d5cb0a97..00604043 100644 --- a/date/README.md +++ b/date/README.md @@ -35,6 +35,29 @@ ``` +# clone + +Clones the given Date object. + +## Type signature + + +```typescript +(date: Date) => Date +``` + + +## Examples + + +```javascript +const date = new new Date('2019-04-24T13:54:33.232Z'); +const cloned = clone(date); + +cloned !== date && cloned.valueOf() === date.valueOf(); // ⇒ true +``` + + # dateDiff ## Type signature diff --git a/date/clone.js b/date/clone.js new file mode 100644 index 00000000..cde10ba1 --- /dev/null +++ b/date/clone.js @@ -0,0 +1 @@ +export default date => new Date(+date); diff --git a/date/clone.json b/date/clone.json new file mode 100644 index 00000000..c1b23dc7 --- /dev/null +++ b/date/clone.json @@ -0,0 +1,12 @@ +{ + "name": "clone", + "description": "Clones the given Date object.", + "signature": "(date: Date) => Date", + "examples": [ + { + "language": "javascript", + "content": "const date = new new Date('2019-04-24T13:54:33.232Z');\nconst cloned = clone(date);\n\ncloned !== date && cloned.valueOf() === date.valueOf(); // ⇒ true" + } + ], + "questions": ["TODO: List questions that may this function answer."] +} diff --git a/date/clone.md b/date/clone.md new file mode 100644 index 00000000..e0c40b95 --- /dev/null +++ b/date/clone.md @@ -0,0 +1,22 @@ +# clone + +Clones the given Date object. + +## Type signature + + +```typescript +(date: Date) => Date +``` + + +## Examples + + +```javascript +const date = new new Date('2019-04-24T13:54:33.232Z'); +const cloned = clone(date); + +cloned !== date && cloned.valueOf() === date.valueOf(); // ⇒ true +``` + diff --git a/date/clone.test.ts b/date/clone.test.ts new file mode 100644 index 00000000..3921b65c --- /dev/null +++ b/date/clone.test.ts @@ -0,0 +1,13 @@ +/* eslint-env jest */ +// @ts-ignore ambiguous import +import clone from "./clone.ts"; + +describe("clone", () => { + it("should return cloned date", () => { + const date = new Date("2019-04-24T13:54:33.232Z"); + const cloned = clone(date); + + expect(cloned).not.toBe(date); + expect(cloned).toEqual(date); + }); +}); diff --git a/date/clone.ts b/date/clone.ts new file mode 100644 index 00000000..773df6f1 --- /dev/null +++ b/date/clone.ts @@ -0,0 +1 @@ +export default (date: Date) => new Date(+date); diff --git a/date/index.js b/date/index.js index bdaf6cbc..09b65a4c 100644 --- a/date/index.js +++ b/date/index.js @@ -1,5 +1,6 @@ import byDateWithFallback from "./byDateWithFallback.js"; import clamp from "./clamp.js"; +import clone from "./clone.js"; import dateDiff from "./dateDiff.js"; import dateInRange from "./dateInRange.js"; import dayRange from "./dayRange.js"; @@ -39,6 +40,7 @@ import valid from "./valid.js"; export { byDateWithFallback, clamp, + clone, dateDiff, dateInRange, dayRange, @@ -79,6 +81,7 @@ export { export default { byDateWithFallback, clamp, + clone, dateDiff, dateInRange, dayRange, diff --git a/date/index.ts b/date/index.ts index 69a2a463..4aec8308 100644 --- a/date/index.ts +++ b/date/index.ts @@ -1,5 +1,6 @@ import byDateWithFallback from "./byDateWithFallback"; import clamp from "./clamp"; +import clone from "./clone"; import dateDiff from "./dateDiff"; import dateInRange from "./dateInRange"; import dayRange from "./dayRange"; @@ -39,6 +40,7 @@ import valid from "./valid"; export { byDateWithFallback, clamp, + clone, dateDiff, dateInRange, dayRange, @@ -79,6 +81,7 @@ export { export default { byDateWithFallback, clamp, + clone, dateDiff, dateInRange, dayRange,