Skip to content

Commit

Permalink
update ESMs with latest changes (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
angus-c authored Jun 5, 2022
1 parent e790d81 commit 56604cc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
34 changes: 19 additions & 15 deletions packages/collection-clone/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 6 additions & 2 deletions packages/collection-diff/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/number-in-range/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion packages/string-kebab-case/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function kebabCase(str) {
return str
.trim()
.split(wordSeparators)
.join('-');
.join('-')
.replace(/^-/, '')
.replace(/-\s*$/, '');
}

export {stringKebabCase as default};

0 comments on commit 56604cc

Please sign in to comment.