From 56604cc972977e29fcaed0f676c595de9b67b95d Mon Sep 17 00:00:00 2001 From: angus croll Date: Sat, 4 Jun 2022 17:13:53 -0700 Subject: [PATCH] update ESMs with latest changes (#464) --- packages/collection-clone/index.mjs | 34 ++++++++++++++++------------ packages/collection-diff/index.mjs | 8 +++++-- packages/number-in-range/index.mjs | 2 +- packages/string-kebab-case/index.mjs | 4 +++- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/packages/collection-clone/index.mjs b/packages/collection-clone/index.mjs index ebf043ce9..4307bfe4d 100644 --- a/packages/collection-clone/index.mjs +++ b/packages/collection-clone/index.mjs @@ -14,24 +14,28 @@ var collectionClone = clone; */ function clone(obj) { - if (typeof obj == 'function') { - return obj; + let result = obj; + var type = {}.toString.call(obj).slice(8, -1); + if (type == 'Set') { + return new Set([...obj].map(value => clone(value))); } - var result = Array.isArray(obj) ? [] : {}; - for (var key in obj) { - // include prototype properties - var value = obj[key]; - var type = {}.toString.call(value).slice(8, -1); - if (type == 'Array' || type == 'Object') { - result[key] = clone(value); - } else if (type == 'Date') { - result[key] = new Date(value.getTime()); - } else if (type == 'RegExp') { - result[key] = RegExp(value.source, getRegExpFlags(value)); - } else { - result[key] = value; + if (type == 'Map') { + return new Map([...obj].map(kv => [clone(kv[0]), clone(kv[1])])); + } + if (type == 'Date') { + return new Date(obj.getTime()); + } + if (type == 'RegExp') { + return RegExp(obj.source, getRegExpFlags(obj)); + } + if (type == 'Array' || type == 'Object') { + result = Array.isArray(obj) ? [] : {}; + for (var key in obj) { + // include prototype properties + result[key] = clone(obj[key]); } } + // primitives and non-supported objects (e.g. functions) land here return result; } diff --git a/packages/collection-diff/index.mjs b/packages/collection-diff/index.mjs index 8da5b5cea..a0c583447 100644 --- a/packages/collection-diff/index.mjs +++ b/packages/collection-diff/index.mjs @@ -124,9 +124,13 @@ function diff(obj1, obj2, pathConverter) { } } - return diffs.remove.reverse().concat(diffs.replace).concat(diffs.add); + return diffs; } - return getDiff(obj1, obj2, [], {remove: [], replace: [], add: []}); + const finalDiffs = getDiff(obj1, obj2, [], {remove: [], replace: [], add: []}); + return finalDiffs.remove + .reverse() + .concat(finalDiffs.replace) + .concat(finalDiffs.add); } function pushReplace(path, basePath, key, diffs, pathConverter, obj2) { diff --git a/packages/number-in-range/index.mjs b/packages/number-in-range/index.mjs index da634e2d2..b54c1f9a4 100644 --- a/packages/number-in-range/index.mjs +++ b/packages/number-in-range/index.mjs @@ -10,7 +10,7 @@ function inRange(number, start, end) { } if (end !== undefined && typeof end !== 'number') { - throw new Error('expected a number or undefined for thrird argument'); + throw new Error('expected a number or undefined for third argument'); } var _start = start; diff --git a/packages/string-kebab-case/index.mjs b/packages/string-kebab-case/index.mjs index cc7a15ecf..888e082d4 100644 --- a/packages/string-kebab-case/index.mjs +++ b/packages/string-kebab-case/index.mjs @@ -32,7 +32,9 @@ function kebabCase(str) { return str .trim() .split(wordSeparators) - .join('-'); + .join('-') + .replace(/^-/, '') + .replace(/-\s*$/, ''); } export {stringKebabCase as default};