New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More β†’
Socket
Sign inDemoInstall
Socket

all-of-just

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

all-of-just - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

668

arrays.js

@@ -1,3 +0,667 @@

export { j as cartesianProduct, f as compact, b as flattenIt, t as groupBy, c as index, d as insert, e as intersect, g as last, n as partition, o as permutations, p as range, q as remove, i as shuffle, m as sortBy, k as split, l as splitAt, h as tail, r as union, a as unique, s as zip } from './index-67dedcb7.js';
export { j as random } from './index-ee0914ac.js';
var justCartesianProduct = cartesianProduct;
/*
cartesianProduct([[1, 2], ['a', 'b']]); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
cartesianProduct(); // throws
*/
function isArray(item) {
if (Object.prototype.toString.call(item) === '[object Array]') {
return true;
}
return false;
}
function baseProduct(arr1, arr2) {
var output = [];
for (var i = 0; i < arr1.length; i++) {
var item = isArray(arr1[i]) ? arr1[i] : [arr1[i]];
for (var j = 0; j < arr2.length; j++) {
var items = item.concat([arr2[j]]);
output.push(items);
}
}
return output;
}
function cartesianProduct(arr) {
if (!isArray(arr)) {
throw new Error('just-array-product expects an array');
}
if (!arr.length) {
return [];
}
var output = arr[0];
for (var i = 1; i < arr.length; i++) {
output = baseProduct(output, arr[i]);
}
return output;
}
var justUnique = unique;
/*
unique([1, 2, 3, 2, 3, 4, 3, 2, 1, 3]); // [1, 2, 3, 4]
var a = {a: 3};
var b = {b: 4};
var c = {c: 5};
unique([a, a, b, c, b]); // [a, b, c]
unique([1, '1', 2, '2', 3, 2]); // [1, '1', 2, '2', 3]
// declaring sorted array for performance
unique([1, 1, '1', 2, 2, 5, '5', '5'], true); // [1, '1', 2, 5, '6']
// declaring strings array for performance
unique(['a', 'c', 'b', 'c', 'a'], false, true); // ['a', 'b', 'c']
*/
function unique(arr, sorted, strings) {
if (!Array.isArray(arr)) {
throw new Error('expected an array for the first argument');
}
if (sorted != null && typeof sorted != 'boolean') {
throw new Error('expected a boolean, null or undefined for the second argument');
}
if (strings != null && typeof strings != 'boolean') {
throw new Error('expected a boolean, null or undefined for the third argument');
}
if (!sorted && strings && arr[0] !== Object(arr[0])) {
return stringUnique(arr);
}
var result = [],
duplicate,
seenNaN,
lastAdded;
var len = arr.length;
for (var i = 0; i < len; i++) {
var elem = arr[i];
if (typeof elem == 'number' && isNaN(elem)) {
duplicate = seenNaN;
seenNaN = true;
}
duplicate = duplicate || (lastAdded && lastAdded === elem);
if (!duplicate && !sorted) {
duplicate = result.indexOf(elem) > -1;
}
if (!duplicate) {
result.push(elem);
lastAdded = elem;
} else {
duplicate = false;
}
}
return result;
}
function stringUnique(arr) {
var lookup = {};
var len = arr.length;
for (var i = 0; i < len; i++) {
lookup[arr[i]] = true;
}
return Object.keys(lookup);
}
var justFlattenIt = flatten;
/*
flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]]);
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
*/
function flattenHelper(arr, depth) {
var stack = arr.slice();
var result = [];
while (stack.length) {
var item = stack.pop();
if (Array.isArray(item) && depth > 0) {
stack.push.apply(stack, item);
depth--;
} else {
result.push(item);
}
}
return result.reverse();
}
function flatten(arr, depth) {
if (!Array.isArray(arr)) {
throw new Error('expected an array');
}
if (depth !== undefined && typeof depth !== 'number') {
throw new Error('depth expects a number');
}
return flattenHelper(arr, typeof depth === 'number' ? depth : Infinity);
}
var justIndex = index;
/*
index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id');
// {first: {id: 'first', val: 1}, second: {id: 'second', val: 2}}
index([{id: 'first', val: 1}, null], 'id'); // {first: {id: 'first', val: 1}}
index([], 'id'); // {}
index([], null); // throws
index({}, 'id'); // throws
*/
function index(arr, key) {
if (!Array.isArray(arr)) {
throw new Error('expected an array for first argument');
}
if (typeof key != 'string') {
throw new Error('expected a string for second argument');
}
var result = {};
var len = arr.length;
for (var i = 0; i < len; i++) {
var index = arr[i] && arr[i][key];
if (index) {
result[index] = arr[i];
}
}
return result;
}
var justInsert = insert;
/*
insert([1, 2, 5, 6], ['a', 'c', 'e'], 2); // [1, 2, 'a', 'c', 'e', 5, 6]
insert([1, 2, 5, 6], 'a', 2); // [1, 2, 'a', 5, 6]
insert([1, 2, 5, 6], ['a', 'c', 'e'], 0); // ['a', 'c', 'e', 1, 2, 5, 6]
insert([1, 2, 5, 6], ['a', 'c', 'e']); // ['a', 'c', 'e', 1, 2, 5, 6]
*/
function insert(arr1, arr2, index) {
if (!Array.isArray(arr1)) {
throw new Error('expected an array for first argument');
}
if (arguments.length > 2 && typeof index != 'number') {
throw new Error('expected a number for third argument');
}
if (!Array.isArray(arr2)) {
arr2 = [arr2];
}
if (!index) {
return arr2.concat(arr1);
}
var front = arr1.slice(0, index);
var back = arr1.slice(index);
return front.concat(arr2, back);
}
var justIntersect = intersect;
/*
intersect([1, 2, 5, 6], [2, 3, 5, 6]); // [2, 5, 6]
intersect([1, 2, 2, 4, 5], [3, 2, 2, 5, 7]); // [2, 5]
*/
function intersect(arr1, arr2) {
if (!Array.isArray(arr1) || !Array.isArray(arr2)) {
throw new Error('expected both arguments to be arrays');
}
var result = [];
var len = arr1.length;
for (var i = 0; i < len; i++) {
var elem = arr1[i];
if (arr2.indexOf(elem) > -1 && result.indexOf(elem) == -1) {
result.push(elem);
}
}
return result;
}
var justCompact = compact;
/*
compact([1, null, 2, undefined, null, NaN, 3, 4, false, 5]); // [1, 2, 3, 4, 5]
compact([1, 2, [], 4, {}]); // [1, 2, [], 4, {}]
compact([]); // []
compact({}); // throws
*/
function compact(arr) {
if (!Array.isArray(arr)) {
throw new Error('expected an array');
}
var result = [];
var len = arr.length;
for (var i = 0; i < len; i++) {
var elem = arr[i];
if (elem) {
result.push(elem);
}
}
return result;
}
var justLast = last;
/*
last([1, 2, 3, 4, 5]); // 5
last([{a: 1}, {b: 1}, {c: 1}]); // {c: 1}
last([true, false, [true, false]]); // [true, false]
last({}); // throws
last(); // throws
*/
function last(arr) {
if (!Array.isArray(arr)) {
throw new Error('expected an array');
}
return arr[arr.length - 1];
}
var justTail = tail;
/*
tail([1, 2, 3, 4, 5]); // [2, 3, 4, 5]
tail([{a: 1}, {b: 1}, {c: 1}]); // [{b: 1}, {c: 1}]
tail([true, false, [true, false]]); // [false, [true, false]]
tail([]); // []
tail(); // throws
*/
function tail(arr) {
if (!Array.isArray(arr)) {
throw new Error('expected an array');
}
return arr.slice(1);
}
var justRandom = random;
/*
random([1, 2, 3]); // one of [1, 2, 3], at random
random([1]); // 1
random(); // throws
*/
function random(arr) {
if (!Array.isArray(arr)) {
throw new Error('expected an array');
}
return arr[Math.floor(Math.random() * arr.length)];
}
var justShuffle = shuffle;
/*
shuffle([1, 2, 3]);
// array with original elements randomly sorted
shuffle([1, 2, 3], {shuffleAll: true});
// array with original elements randomly sorted and all in a new position
shuffle([1]); // [1]
shuffle(); // throws
shuffle(undefined); // throws
shuffle(null); // throws
shuffle({}); // throws
*/
function shuffle(arr, options) {
if (!Array.isArray(arr)) {
throw new Error('expected an array');
}
if (arr.length < 2) {
return arr;
}
var shuffleAll = options && options.shuffleAll;
var result = arr.slice();
var i = arr.length, rand, temp;
while (--i > 0) {
do {
rand = Math.floor(Math.random() * (i + 1));
} while (shuffleAll && rand == i);
if (!shuffleAll || rand != i) {
temp = result[i];
result[i] = result[rand];
result[rand] = temp;
}
}
return result;
}
var justSplit = split;
/*
split([]); // []
split([1, 2, 3, 4, 5]); // [[1, 2, 3, 4, 5]]
split([1, 2, 3, 4, 5], null); // [[1, 2, 3, 4, 5]]
split([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
split(['a', 'b', 'c', 'd', 'e'], 2); // [['a', 'b'], ['c', 'd'], ['e']]
split([1, 2, 3, 4, 5, 6, 7, 8], 3); // [[1, 2, 3], [4, 5, 6], [7, 8]]
split(null, 3); // throws
split([1, 2, 3, 4, 5, 6], '3'); // throws
split([1, 2, 3, 4, 5, 6], {}); // throws
*/
function split(arr, n) {
if (!Array.isArray(arr)) {
throw new Error('expected an array for the first argument');
}
if (n != null && typeof n != 'number') {
throw new Error('expected a number or null/undefined for the second argument');
}
n = n != null ? n : arr.length;
var len = arr.length;
var groups = [];
for (var i = 0; i < len; i += n) {
groups.push(arr.slice(i, i + n));
}
return groups;
}
var justSplitAt = splitAt;
/*
splitAt([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4, 5]]
splitAt([{a: 1}, {b: 1}, {c: 1}], -1); // [[{a: 1}, {b: 1}], [{c: 1}]]
splitAt([], 2); // [[], []]
splitAt(null, 1); // throws
splitAt(undefined, 1); // throws
*/
function splitAt(arr, n) {
if (!Array.isArray(arr)) {
throw new Error('expected an array for the first argument');
}
if (n != null && typeof n != 'number') {
throw new Error('expected a number or null for the second argument');
}
if (n == null) {
n = 0;
}
return [arr.slice(0, n), arr.slice(n)];
}
var justSortBy = sortBy;
function handleSort(iteratee) {
return function(a, b) {
var keyA = typeof iteratee === 'string' ? a[iteratee] : iteratee(a);
var keyB = typeof iteratee === 'string' ? b[iteratee] : iteratee(b);
if (typeof keyA === 'string' && typeof keyB === 'string') {
var valueA = keyA.toUpperCase();
var valueB = keyB.toUpperCase();
if (valueA < valueB) {
return -1;
}
if (valueA > valueB) {
return 1;
}
return 0;
}
return keyA - keyB;
};
}
function sortBy(arr, iteratee) {
if (!Array.isArray(arr)) {
throw new Error('arr should be an array');
}
if (iteratee !== undefined && (typeof iteratee !== 'string' && typeof iteratee !== 'function')) {
throw new Error('iteratee should be a string or a function');
}
if (arr.length <= 1) {
return arr;
}
var copied = arr.slice();
if (!iteratee) {
return copied.sort(function(a, b) {
return a - b;
});
}
return copied.sort(handleSort(iteratee));
}
var justPartition = partition;
/*
partition([1, 5, 2, 4, 3], n => n > 3); // [[5, 4],[1, 2, 3]]
partition(['a', 2, 3, '3'], x => typeof x == 'string'); // [['a', '3'],[2, 3]]
partition([1, 2, 3, 4], x => typeof x == 'number'); // [[1, 2, 3, 4],[]]
partition([1, 2, 3, 4], x => typeof x == 'string'); // [[], [1, 2, 3, 4]]
partition([], n => n > 3); // [[], []]
partition({a: 1, b: 2}, n => n > 1); // throws
partition(null, n => n > 1); // throws
partition(undefined, n => n > 1); // throws
*/
function partition(arr, fn) {
if (!Array.isArray(arr)) {
throw new Error('expected first argument to be an array');
}
if (typeof fn != 'function') {
throw new Error('expected second argument to be a function');
}
var first = [];
var second = [];
var length = arr.length;
for (var i = 0; i < length; i++) {
var nextValue = arr[i];
if (fn(nextValue)) {
first.push(nextValue);
} else {
second.push(nextValue);
}
}
return [first, second];
}
var justPermutations = permutations;
/*
permutations([1, 2, 3]); // [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]
permutations([1]); // [[1]]
permutations(); // throws
*/
function permutations(arr) {
if (!Array.isArray(arr)) {
throw new Error('just-array-permutations expects an array');
}
if (!arr.length) {
return [];
}
if (arr.length === 1) {
return [arr];
}
var output = [];
var partialPermutations = permutations(arr.slice(1));
var first = arr[0];
for (var i = 0, len = partialPermutations.length; i < len; i++) {
var partial = partialPermutations[i];
for (var j = 0, len2 = partial.length; j <= len2; j++) {
var start = partial.slice(0, j);
var end = partial.slice(j);
var merged = start.concat(first, end);
output.push(merged);
}
}
return output;
}
var justRange = range;
/*
range(0, 5); // [0, 1, 2, 3, 4]
range(5); // [0, 1, 2, 3, 4]
range(-5); // [0, -1, -2, -3, -4]
range(0, 20, 5) // [0, 5, 10, 15]
range(0, -20, -5) // [0, -5, -10, -15]
*/
function range(start, stop, step) {
if (start != null && typeof start != 'number') {
throw new Error('start must be a number or null');
}
if (stop != null && typeof stop != 'number') {
throw new Error('stop must be a number or null');
}
if (step != null && typeof step != 'number') {
throw new Error('step must be a number or null');
}
if (stop == null) {
stop = start || 0;
start = 0;
}
if (step == null) {
step = stop > start ? 1 : -1;
}
var toReturn = [];
var increasing = start < stop; //← here’s the change
for (; increasing ? start < stop : start > stop; start += step) {
toReturn.push(start);
}
return toReturn;
}
var justRemove = remove;
/*
remove([1, 2, 3, 4, 5, 6], [1, 3, 6]); // [2, 4, 5]
*/
function remove(arr1, arr2) {
if (!Array.isArray(arr1) || !Array.isArray(arr2)) {
throw new Error('expected both arguments to be arrays');
}
var result = [];
var len = arr1.length;
for (var i = 0; i < len; i++) {
var elem = arr1[i];
if (arr2.indexOf(elem) == -1) {
result.push(elem);
}
}
return result;
}
var justUnion = union;
/*
union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 3, 4, 5, 6]
*/
function union(arr1, arr2) {
if (!Array.isArray(arr1) || !Array.isArray(arr2)) {
throw new Error('expected both arguments to be arrays');
}
var result = arr1.concat([]);
var len = arr2.length;
for (var i = 0; i < len; i++) {
var elem = arr2[i];
if (arr1.indexOf(elem) == -1) {
result.push(elem);
}
}
return result;
}
var justZipIt = zip;
/*
zip([1, 2, 3]); // [[1], [2], [3]]
zip([1, 2, 3], ['a', 'b', 'c']); // [[1, 'a'], [2, 'b'], [3, 'c']]
zip([1, 2], ['a', 'b'], [true, false]); //[[1, 'a', true], [2, 'b', false]]
zip([1, 2, 3], ['a', 'b'], [true]);
// [[1, 'a', true], [2, 'b', undefined], [3, undefined, undefined]]
zip(undefined, {}, false, 1, 'foo'); // throws
zip([1, 2], ['a', 'b'], undefined, {}, false, 1, 'foo'); // throws
*/
function zip() {
var result = [];
var args = Array.prototype.slice.call(arguments);
var argsLen = args.length;
var maxLen = 0;
var i, j;
if (!argsLen) {
throw new Error('zip requires at least one argument');
}
for (i = 0; i < argsLen; i++) {
if (!Array.isArray(args[i])) {
throw new Error('all arguments must be arrays');
}
var arrLen = args[i].length;
if (arrLen > maxLen) {
maxLen = arrLen;
}
}
for (i = 0; i < maxLen; i++) {
var group = [];
for (j = 0; j < argsLen; j++) {
if (!Array.isArray(args[j])) {
throw new Error('all arguments must be arrays');
}
group[j] = args[j][i];
}
result[i] = group;
}
return result;
}
var justGroupBy = groupBy;
function groupBy(arr, cb) {
if (!Array.isArray(arr)) {
throw new Error('expected an array for first argument');
}
if (typeof cb !== 'function') {
throw new Error('expected a function for second argument');
}
var result = {};
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
var bucketCategory = cb(item);
var bucket = result[bucketCategory];
if (!Array.isArray(bucket)) {
result[bucketCategory] = [item];
} else {
result[bucketCategory].push(item);
}
}
return result;
}
export { justCartesianProduct as cartesianProduct, justCompact as compact, justFlattenIt as flattenIt, justGroupBy as groupBy, justIndex as index, justInsert as insert, justIntersect as intersect, justLast as last, justPartition as partition, justPermutations as permutations, justRandom as random, justRange as range, justRemove as remove, justShuffle as shuffle, justSortBy as sortBy, justSplit as split, justSplitAt as splitAt, justTail as tail, justUnion as union, justUnique as unique, justZipIt as zip };
//# sourceMappingURL=arrays.js.map

@@ -1,9 +0,474 @@

import { j as justDiff, a as justDiffApply } from './index-788581f6.js';
export { c as clone, b as compare, e as flush, d as pluck } from './index-788581f6.js';
var justDiff = {
diff: diff,
jsonPatchPathConverter: jsonPatchPathConverter$1,
};
/*
const obj1 = {a: 4, b: 5};
const obj2 = {a: 3, b: 5};
const obj3 = {a: 4, c: 5};
diff(obj1, obj2);
[
{ "op": "replace", "path": ['a'], "value": 3 }
]
var diff = justDiff.diff;
var diffApply = justDiffApply.diffApply;
export { diff, diffApply };
diff(obj2, obj3);
[
{ "op": "remove", "path": ['b'] },
{ "op": "replace", "path": ['a'], "value": 4 }
{ "op": "add", "path": ['c'], "value": 5 }
]
// using converter to generate jsPatch standard paths
// see http://jsonpatch.com
import {diff, jsonPatchPathConverter} from 'just-diff'
diff(obj1, obj2, jsonPatchPathConverter);
[
{ "op": "replace", "path": '/a', "value": 3 }
]
diff(obj2, obj3, jsonPatchPathConverter);
[
{ "op": "remove", "path": '/b' },
{ "op": "replace", "path": '/a', "value": 4 }
{ "op": "add", "path": '/c', "value": 5 }
]
// arrays
const obj4 = {a: 4, b: [1, 2, 3]};
const obj5 = {a: 3, b: [1, 2, 4]};
const obj6 = {a: 3, b: [1, 2, 4, 5]};
diff(obj4, obj5);
[
{ "op": "replace", "path": ['a'], "value": 3 }
{ "op": "replace", "path": ['b', 2], "value": 4 }
]
diff(obj5, obj6);
[
{ "op": "add", "path": ['b', 3], "value": 5 }
]
// nested paths
const obj7 = {a: 4, b: {c: 3}};
const obj8 = {a: 4, b: {c: 4}};
const obj9 = {a: 5, b: {d: 4}};
diff(obj7, obj8);
[
{ "op": "replace", "path": ['b', 'c'], "value": 4 }
]
diff(obj8, obj9);
[
{ "op": "replace", "path": ['a'], "value": 5 }
{ "op": "remove", "path": ['b', 'c']}
{ "op": "add", "path": ['b', 'd'], "value": 4 }
]
*/
function diff(obj1, obj2, pathConverter) {
if (!obj1 || typeof obj1 != 'object' || !obj2 || typeof obj2 != 'object') {
throw new Error('both arguments must be objects or arrays');
}
pathConverter ||
(pathConverter = function(arr) {
return arr;
});
function getDiff(obj1, obj2, basePath, diffs) {
var obj1Keys = Object.keys(obj1);
var obj1KeysLength = obj1Keys.length;
var obj2Keys = Object.keys(obj2);
var obj2KeysLength = obj2Keys.length;
var path;
for (var i = 0; i < obj1KeysLength; i++) {
var key = Array.isArray(obj1) ? Number(obj1Keys[i]) : obj1Keys[i];
if (!(key in obj2)) {
path = basePath.concat(key);
diffs.remove.push({
op: 'remove',
path: pathConverter(path),
});
}
}
for (var i = 0; i < obj2KeysLength; i++) {
var key = Array.isArray(obj2) ? Number(obj2Keys[i]) : obj2Keys[i];
var obj1AtKey = obj1[key];
var obj2AtKey = obj2[key];
if (!(key in obj1)) {
path = basePath.concat(key);
var obj2Value = obj2[key];
diffs.add.push({
op: 'add',
path: pathConverter(path),
value: obj2Value,
});
} else if (obj1AtKey !== obj2AtKey) {
if (
Object(obj1AtKey) !== obj1AtKey ||
Object(obj2AtKey) !== obj2AtKey
) {
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2);
} else {
if (
!Object.keys(obj1AtKey).length &&
!Object.keys(obj2AtKey).length &&
String(obj1AtKey) != String(obj2AtKey)
) {
path = pushReplace(path, basePath, key, diffs, pathConverter, obj2);
} else {
getDiff(obj1[key], obj2[key], basePath.concat(key), diffs);
}
}
}
}
return diffs.remove
.reverse()
.concat(diffs.replace)
.concat(diffs.add);
}
return getDiff(obj1, obj2, [], {remove: [], replace: [], add: []});
}
function pushReplace(path, basePath, key, diffs, pathConverter, obj2) {
path = basePath.concat(key);
diffs.replace.push({
op: 'replace',
path: pathConverter(path),
value: obj2[key],
});
return path;
}
function jsonPatchPathConverter$1(arrayPath) {
return [''].concat(arrayPath).join('/');
}
var justDiffApply = {
diffApply: diffApply,
jsonPatchPathConverter: jsonPatchPathConverter,
};
/*
const obj1 = {a: 3, b: 5};
diffApply(obj1,
[
{ "op": "remove", "path": ['b'] },
{ "op": "replace", "path": ['a'], "value": 4 },
{ "op": "add", "path": ['c'], "value": 5 }
]
);
obj1; // {a: 4, c: 5}
// using converter to apply jsPatch standard paths
// see http://jsonpatch.com
import {diff, jsonPatchPathConverter} from 'just-diff'
const obj2 = {a: 3, b: 5};
diffApply(obj2, [
{ "op": "remove", "path": '/b' },
{ "op": "replace", "path": '/a', "value": 4 }
{ "op": "add", "path": '/c', "value": 5 }
], jsonPatchPathConverter);
obj2; // {a: 4, c: 5}
// arrays
const obj3 = {a: 4, b: [1, 2, 3]};
diffApply(obj3, [
{ "op": "replace", "path": ['a'], "value": 3 }
{ "op": "replace", "path": ['b', 2], "value": 4 }
{ "op": "add", "path": ['b', 3], "value": 9 }
]);
obj3; // {a: 3, b: [1, 2, 4, 9]}
// nested paths
const obj4 = {a: 4, b: {c: 3}};
diffApply(obj4, [
{ "op": "replace", "path": ['a'], "value": 5 }
{ "op": "remove", "path": ['b', 'c']}
{ "op": "add", "path": ['b', 'd'], "value": 4 }
]);
obj4; // {a: 5, b: {d: 4}}
*/
var REMOVE = 'remove';
var REPLACE = 'replace';
var ADD = 'add';
function diffApply(obj, diff, pathConverter) {
if (!obj || typeof obj != 'object') {
throw new Error('base object must be an object or an array');
}
if (!Array.isArray(diff)) {
throw new Error('diff must be an array');
}
var diffLength = diff.length;
for (var i = 0; i < diffLength; i++) {
var thisDiff = diff[i];
var subObject = obj;
var thisOp = thisDiff.op;
var thisPath = thisDiff.path;
if (pathConverter) {
thisPath = pathConverter(thisPath);
if (!Array.isArray(thisPath)) {
throw new Error('pathConverter must return an array');
}
} else {
if (!Array.isArray(thisPath)) {
throw new Error('diff path must be an array, consider supplying a path converter');
}
}
var pathCopy = thisPath.slice();
var lastProp = pathCopy.pop();
if (lastProp == null) {
return false;
}
var thisProp;
while (((thisProp = pathCopy.shift())) != null) {
if (!(thisProp in subObject)) {
subObject[thisProp] = {};
}
subObject = subObject[thisProp];
}
if (thisOp === REMOVE || thisOp === REPLACE) {
if (!subObject.hasOwnProperty(lastProp)) {
throw new Error(['expected to find property', thisDiff.path, 'in object', obj].join(' '));
}
}
if (thisOp === REMOVE) {
Array.isArray(subObject) ? subObject.splice(lastProp, 1) : delete subObject[lastProp];
}
if (thisOp === REPLACE || thisOp === ADD) {
subObject[lastProp] = thisDiff.value;
}
}
return subObject;
}
function jsonPatchPathConverter(stringPath) {
return stringPath.split('/').slice(1);
}
var justCompare = compare;
/*
primitives: value1 === value2
functions: value1.toString == value2.toString
arrays: if length, sequence and values of properties are identical
objects: if length, names and values of properties are identical
compare([[1, [2, 3]], [[1, [2, 3]]); // true
compare([[1, [2, 3], 4], [[1, [2, 3]]); // false
compare({a: 2, b: 3}, {a: 2, b: 3}); // true
compare({a: 2, b: 3}, {b: 3, a: 2}); // true
compare({a: 2, b: 3, c: 4}, {a: 2, b: 3}); // false
compare({a: 2, b: 3}, {a: 2, b: 3, c: 4}); // false
compare([[1, [2, {a: 4}], 4], [[1, [2, {a: 4}]]); // true
*/
function compare(value1, value2) {
if (value1 === value2) {
return true;
}
/* eslint-disable no-self-compare */
// if both values are NaNs return true
if (value1 !== value1 && value2 !== value2) {
return true;
}
if ({}.toString.call(value1) != {}.toString.call(value2)) {
return false;
}
if (value1 !== Object(value1)) {
// non equal primitives
return false;
}
if (!value1) {
return false;
}
if (Array.isArray(value1)) {
return compareArrays(value1, value2);
}
if ({}.toString.call(value1) == '[object Set]') {
return compareArrays(Array.from(value1), Array.from(value2));
}
if ({}.toString.call(value1) == '[object Object]') {
return compareObjects(value1, value2);
} else {
return compareNativeSubtypes(value1, value2);
}
}
function compareNativeSubtypes(value1, value2) {
// e.g. Function, RegExp, Date
return value1.toString() === value2.toString();
}
function compareArrays(value1, value2) {
var len = value1.length;
if (len != value2.length) {
return false;
}
var alike = true;
for (var i = 0; i < len; i++) {
if (!compare(value1[i], value2[i])) {
alike = false;
break;
}
}
return alike;
}
function compareObjects(value1, value2) {
var keys1 = Object.keys(value1).sort();
var keys2 = Object.keys(value2).sort();
var len = keys1.length;
if (len != keys2.length) {
return false;
}
for (var i = 0; i < len; i++) {
var key1 = keys1[i];
var key2 = keys2[i];
if (!(key1 == key2 && compare(value1[key1], value2[key2]))) {
return false;
}
}
return true;
}
var justClone = clone;
/*
Deep clones all properties except functions
var arr = [1, 2, 3];
var subObj = {aa: 1};
var obj = {a: 3, b: 5, c: arr, d: subObj};
var objClone = clone(obj);
arr.push(4);
subObj.bb = 2;
obj; // {a: 3, b: 5, c: [1, 2, 3, 4], d: {aa: 1}}
objClone; // {a: 3, b: 5, c: [1, 2, 3], d: {aa: 1, bb: 2}}
*/
function clone(obj) {
if (typeof obj == 'function') {
return obj;
}
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;
}
}
return result;
}
function getRegExpFlags(regExp) {
if (typeof regExp.source.flags == 'string') {
return regExp.source.flags;
} else {
var flags = [];
regExp.global && flags.push('g');
regExp.ignoreCase && flags.push('i');
regExp.multiline && flags.push('m');
regExp.sticky && flags.push('y');
regExp.unicode && flags.push('u');
return flags.join('');
}
}
var justPluckIt = pluck;
/*
var arr = [{a:1, b:2}, {a:4, b:3}, {a:2, b:5}];
pluck(arr, 'a'); // [1, 4, 2]
var obj = {x: {a:1, b:2}, y: {a:4, b:3}, z: {a:2, b:5}];
pluck(obj, 'a'); // {x: 1, y: 4, z: 2}
*/
function pluck(collection, propertyName) {
if (!collection || typeof collection != 'object') {
return new Error('expected first argument to be an object or array');
}
var result, len, i, keys, key;
if (Array.isArray(collection)) {
result = [];
len = collection.length;
for (i = 0; i < len; i++) {
result.push(collection[i][propertyName]);
}
} else {
result = {};
keys = Object.keys(collection);
len = keys.length;
for (i = 0; i < len; i++) {
key = keys[i];
result[key] = collection[key][propertyName];
}
}
return result;
}
var justFlush = flush;
/*
flush([1, undefined, 2, null, 3, NaN, 0]); // [1, 2, 3, NaN, 0]
flush([true, null, false, true, [null], undefined]); // [true, false, true, [null]]
flush({a: 2, b: null, c: 4, d: undefined}); // {a: 2, c: 4}
flush('something'); // undefined
flush(); // undefined
*/
function flush(collection) {
var result, len, i;
if (!collection) {
return undefined;
}
if (Array.isArray(collection)) {
result = [];
len = collection.length;
for (i = 0; i < len; i++) {
var elem = collection[i];
if (elem != null) {
result.push(elem);
}
}
return result;
}
if (typeof collection == 'object') {
result = {};
var keys = Object.keys(collection);
len = keys.length;
for (i = 0; i < len; i++) {
var key = keys[i];
var value = collection[key];
if (value != null) {
result[key] = value;
}
}
return result;
}
return undefined;
}
var diff$1 = justDiff.diff;
var diffApply$1 = justDiffApply.diffApply;
export { justClone as clone, justCompare as compare, diff$1 as diff, diffApply$1 as diffApply, justFlush as flush, justPluckIt as pluck };
//# sourceMappingURL=collection.js.map

@@ -1,9 +0,413 @@

import { i as justOnce } from './index-63915575.js';
export { j as compose, a as curry, e as debounce, b as demethodize, c as flip, f as memoize, g as memoizeLast, d as partial, h as throttle } from './index-63915575.js';
export { j as random } from './index-ee0914ac.js';
var justCompose = compose;
/*
const sqRootBiggest = compose(Math.max, Math.sqrt, Math.trunc);
sqRootBiggest(10, 5); // 3
sqRootBiggest(7, 0, 16); // 4
*/
function compose(fn1, fn2 /*, fn3, etc */) {
if (!arguments.length) {
throw new Error(
'expected at least one (and probably more) function arguments'
);
}
var fns = arguments;
var once = justOnce.once;
export { once };
return function() {
var result = fns[0].apply(this, arguments);
var len = fns.length;
for (var i = 1; i < len; i++) {
result = fns[i].call(this, result);
}
return result;
};
}
var justCurryIt = curry;
/*
function add(a, b, c) {
return a + b + c;
}
curry(add)(1)(2)(3); // 6
curry(add)(1)(2)(2); // 5
curry(add)(2)(4, 3); // 9
function add(...args) {
return args.reduce((sum, n) => sum + n, 0)
}
var curryAdd4 = curry(add, 4)
curryAdd4(1)(2, 3)(4); // 10
function converter(ratio, input) {
return (input*ratio).toFixed(1);
}
const curriedConverter = curry(converter)
const milesToKm = curriedConverter(1.62);
milesToKm(35); // 56.7
milesToKm(10); // 16.2
*/
function curry(fn, arity) {
return function curried() {
if (arity == null) {
arity = fn.length;
}
var args = [].slice.call(arguments);
if (args.length >= arity) {
return fn.apply(this, args);
} else {
return function() {
return curried.apply(this, args.concat([].slice.call(arguments)));
};
}
};
}
var justDemethodize = demethodize;
/*
var trimFn = demethodize(''.trim);
['hello ', ' goodbye', 'hello again'].map(trimFn); // ['hello', 'goodbye', 'hello again']
var circle = {
volumeOfCylinder: function (height) {
return this.radius * this.radius * Math.PI * height;
}
};
var volume = demethodize(circle.volumeOfCylinder)({radius: 3}, 4);
demethodize({}); // undefined
demethodize(undefined); // undefined
*/
function demethodize(fn) {
if (typeof fn != 'function') {
throw new Error('expected a function, got', fn);
}
return function(thisValue /*, arg1, arg2, ...*/) {
if (thisValue == null) {
throw new Error('expected a value for 1st arg, got ' + thisValue);
}
var args = [].slice.call(arguments);
return fn.apply(args.shift(), args);
};
}
var justFlip = flip;
/*
flip(Array)('a', 'b') // ['b', 'a'];
flip(console.log)(1, 2, 3) // 2, 1, 3
*/
function flip(fn) {
return function() {
var first = arguments[0];
var second = arguments[1];
var rest = [].slice.call(arguments, 2);
return fn.apply(this, [second, first].concat(rest));
};
}
var justPartialIt = partial;
/*
const cubedRoot = partial(Math.pow, _, 1/3);
cubedRoot(64); // 4
const getRoot = partial(Math.pow, 64);
getRoot(1/2); // 8
*/
function partial(fn /*, arg1, arg2 etc */) {
var partialArgs = [].slice.call(arguments, 1);
if (!partialArgs.length) {
return fn;
}
return function() {
var args = [].slice.call(arguments);
var argsIndex = 0;
var derivedArgs = [];
for (var i = 0; i < partialArgs.length; i++) {
var thisPartialArg = partialArgs[i];
derivedArgs[i] =
thisPartialArg === undefined ? args[argsIndex++] : thisPartialArg;
}
return fn.apply(this, derivedArgs.concat(args));
};
}
var justDebounceIt = debounce;
function debounce(fn, wait, callFirst) {
var timeout = null;
var debouncedFn = null;
var clear = function() {
if (timeout) {
clearTimeout(timeout);
debouncedFn = null;
timeout = null;
}
};
var flush = function() {
var call = debouncedFn;
clear();
if (call) {
call();
}
};
var debounceWrapper = function() {
if (!wait) {
return fn.apply(this, arguments);
}
var context = this;
var args = arguments;
var callNow = callFirst && !timeout;
clear();
debouncedFn = function() {
fn.apply(context, args);
};
timeout = setTimeout(function() {
timeout = null;
if (!callNow) {
var call = debouncedFn;
debouncedFn = null;
return call();
}
}, wait);
if (callNow) {
return debouncedFn();
}
};
debounceWrapper.cancel = clear;
debounceWrapper.flush = flush;
return debounceWrapper;
}
var justMemoize = memoize;
/*
const sumByOne = memoize(function(value) {
return value + 1;
});
sumByOne(10);
sumByOne(10); -- Cache hit!
sumByOne(20);
sumByOne(20); -- Cache hit!
// Custom cache
var sum = memoize(function(a, b) {
return a + b
}, function(a, b) {
return `${a}-${b}`
})
sum(10, 10)
sum(10, 20)
sum(10, 20) -- Cache hit!
*/
function memoize(callback, resolver) {
if (typeof callback !== 'function') {
throw new Error('`callback` should be a function');
}
if (resolver !== undefined && typeof resolver !== 'function') {
throw new Error('`resolver` should be a function');
}
var cache = {};
var memoized = function() {
var args = Array.prototype.slice.call(arguments); // to simplify JSON.stringify
var key = resolver ? resolver.apply(this, args) : JSON.stringify(args);
if (!(key in cache)) {
cache[key] = callback.apply(this, args);
}
return cache[key];
};
memoized.cache = cache;
return memoized;
}
var justMemoizeLast = memoizeLast;
function defaultEqual(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
}
for (var i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
}
return true;
}
function memoizeLast(fn, isEqual) {
if (typeof fn !== 'function') {
throw new Error('fn should be a function');
}
if (isEqual !== undefined && typeof isEqual !== 'function') {
throw new Error('isEqual should be a function');
}
var lastThis = null;
var lastArgs = null;
var lastResult = null;
var _isEqual = isEqual || defaultEqual;
return function() {
var args = [].slice.call(arguments);
if (!lastArgs || this !== lastThis || !_isEqual(lastArgs, args)) {
lastThis = this;
lastArgs = args;
lastResult = fn.apply(this, args);
}
return lastResult;
};
}
var justRandom = random;
/*
random([1, 2, 3]); // one of [1, 2, 3], at random
random([1]); // 1
random(); // throws
*/
function random(arr) {
if (!Array.isArray(arr)) {
throw new Error('expected an array');
}
return arr[Math.floor(Math.random() * arr.length)];
}
var justThrottle = throttle;
function throttle(fn, interval, options) {
var timeoutId = null;
var throttledFn = null;
var leading = (options && options.leading);
var trailing = (options && options.trailing);
if (leading == null) {
leading = true; // default
}
if (trailing == null) {
trailing = !leading; //default
}
if (leading == true) {
trailing = false; // forced because there should be invocation per call
}
var cancel = function() {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = null;
}
};
var flush = function() {
var call = throttledFn;
cancel();
if (call) {
call();
}
};
var throttleWrapper = function() {
var callNow = leading && !timeoutId;
var context = this;
var args = arguments;
throttledFn = function() {
return fn.apply(context, args);
};
if (!timeoutId) {
timeoutId = setTimeout(function() {
timeoutId = null;
if (trailing) {
return throttledFn();
}
}, interval);
}
if (callNow) {
callNow = false;
return throttledFn();
}
};
throttleWrapper.cancel = cancel;
throttleWrapper.flush = flush;
return throttleWrapper;
}
var justOnce = once;
/*
let i = 0;
const getFirst = once(() => ++i);
getFirst(); // 1
getFirst(); // 1
*/
function once(fn) {
var called, value;
if (typeof fn !== 'function') {
throw new Error('expected a function but got ' + fn);
}
return function wrap() {
if (called) {
return value;
}
called = true;
value = fn.apply(this, arguments);
fn = undefined;
return value;
};
}
var once$1 = justOnce.once;
export { justCompose as compose, justCurryIt as curry, justDebounceIt as debounce, justDemethodize as demethodize, justFlip as flip, justMemoize as memoize, justMemoizeLast as memoizeLast, once$1 as once, justPartialIt as partial, justRandom as random, justThrottle as throttle };
//# sourceMappingURL=functions.js.map

@@ -1,2 +0,106 @@

export { j as clamp, b as modulo, a as prime } from './index-03dab9e8.js';
var justClamp = clamp;
/*
var n = 5;
clamp(1, n, 12); // 5
clamp(12, n, 3); // 5
clamp(8.2, n, 9,4); // 8.2
clamp(0, n, 0); // 0
var n = -2;
clamp(1, n, 12); // 1
clamp(-4, n, -7); // -4
clamp(NaN, n, 8); // NaN
clamp(3, n, NaN); // NaN
clamp(3, NaN, 8); // NaN
clamp(undefined, n, 8); // throws
clamp(3, n, 'h'); // throws
clamp(12, false, 8); // throws
*/
function clamp(b1, n, b2) {
if (typeof b1 != 'number' || typeof n != 'number' || typeof b2 != 'number') {
throw new Error('arguments must be numbers');
}
if (isNaN(b1) || isNaN(n) || isNaN(b2)) {
return NaN;
}
if (b1 == b2) {
return b1;
}
var lower, higher;
b1 < b2 ? ((lower = b1), (higher = b2)) : ((higher = b1), (lower = b2));
if (n < lower) {
return lower;
}
if (n > higher) {
return higher;
}
return n;
}
var justIsPrime = isPrime;
/*
isPrime(1); // false
isPrime(2); // true
isPrime(17); // true
isPrime(10); // false
isPrime(); // throws
isPrime(null); // throws
isPrime("js"); // throws
isPrime({}); // throws
isPrime(function() {}); // throws
isPrime([]); // throws
*/
function isPrime(number) {
if (!Number.isInteger(number)) {
throw new Error('just-is-prime expects an integer argument');
}
if (number < 2) {
return false;
}
for (var i = 2; i <= Math.sqrt(number); i++) {
if (number % i === 0) {
return false;
}
}
return true;
}
var justModulo = modulo;
/*
modulo(7, 5); // 2
modulo(17, 23); // 17
modulo(16.2, 3.8); // 1
modulo(5.8, 3.4); //2.4
modulo(4, 0); // 4
modulo(-7, 5); // 3
modulo(-2, 15); // 13
modulo(-5.8, 3.4); // 1
modulo(12, -1); // NaN
modulo(-3, -8); // NaN
modulo(12, 'apple'); // NaN
modulo('bee', 9); // NaN
modulo(null, undefined); // NaN
*/
function modulo(n, d) {
if (d === 0) {
return n;
}
if (d < 0) {
return NaN;
}
return (n % d + d) % d;
}
export { justClamp as clamp, justModulo as modulo, justIsPrime as prime };
//# sourceMappingURL=numbers.js.map

@@ -1,9 +0,657 @@

import { b as justValues, e as justOmit } from './index-9a3d8328.js';
export { m as circular, l as empty, c as entries, j as extend, f as filterObject, r as flipObject, i as mapKeys, g as mapObject, h as mapValues, a as merge, q as objectsTypeof, d as pick, n as primitive, k as reduceObject, o as safeGet, p as safeSet } from './index-9a3d8328.js';
var justExtend = extend;
/*
var obj = {a: 3, b: 5};
extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
obj; // {a: 4, b: 5, c: 8}
var obj = {a: 3, b: 5};
extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
obj; // {a: 3, b: 5}
var omit = justOmit.omit;
var values = justValues.values;
export { omit, values };
var arr = [1, 2, 3];
var obj = {a: 3, b: 5};
extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
arr.push(4);
obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}
var arr = [1, 2, 3];
var obj = {a: 3, b: 5};
extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
arr.push(4);
obj; // {a: 3, b: 5, c: [1, 2, 3]}
extend({a: 4, b: 5}); // {a: 4, b: 5}
extend({a: 4, b: 5}, 3); {a: 4, b: 5}
extend({a: 4, b: 5}, true); {a: 4, b: 5}
extend('hello', {a: 4, b: 5}); // throws
extend(3, {a: 4, b: 5}); // throws
*/
function extend(/* [deep], obj1, obj2, [objn] */) {
var args = [].slice.call(arguments);
var deep = false;
if (typeof args[0] == 'boolean') {
deep = args.shift();
}
var result = args[0];
if (isUnextendable(result)) {
throw new Error('extendee must be an object');
}
var extenders = args.slice(1);
var len = extenders.length;
for (var i = 0; i < len; i++) {
var extender = extenders[i];
for (var key in extender) {
if (Object.prototype.hasOwnProperty.call(extender, key)) {
var value = extender[key];
if (deep && isCloneable(value)) {
var base = Array.isArray(value) ? [] : {};
result[key] = extend(
true,
Object.prototype.hasOwnProperty.call(result, key) && !isUnextendable(result[key])
? result[key]
: base,
value
);
} else {
result[key] = value;
}
}
}
}
return result;
}
function isCloneable(obj) {
return Array.isArray(obj) || {}.toString.call(obj) == '[object Object]';
}
function isUnextendable(val) {
return !val || (typeof val != 'object' && typeof val != 'function');
}
var justMerge = merge;
/*
var obj = {a: 3, b: 5};
merge(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
obj; // {a: 4, b: 5, c: 8}
var obj = {a: 3, b: 5};
merge({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
obj; // {a: 3, b: 5}
var arr = [1, 2, 3];
var obj = {a: 3, b: 5};
merge(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
arr.push(4);
obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}
merge({a: 4, b: 5}); // {a: 4, b: 5}
merge(3, {a: 4, b: 5}); // throws
merge({a: 4, b: 5}, 3); // throws
merge({a: 4, b: 5}, {b: 4, c: 5}, 'c'); // throws
*/
function merge(/* obj1, obj2, [objn] */) {
var args = [].slice.call(arguments);
var arg;
var i = args.length;
while (((arg = args[i - 1]), i--)) {
if (!arg || (typeof arg != 'object' && typeof arg != 'function')) {
throw new Error('expected object, got ' + arg);
}
}
var result = args[0];
var extenders = args.slice(1);
var len = extenders.length;
for (var i = 0; i < len; i++) {
var extender = extenders[i];
for (var key in extender) {
result[key] = extender[key];
}
}
return result;
}
var justValues = values;
/*
values({a: 4, c: 8}); // [4, 8]
values({a: {aa: 2}, b: {bb: 4}}); // [{aa: 2}, {bb: 4}]
values({}); // []
values([1, 2, 3]); // [1, 2, 3]
values(function(a, b) {return a + b;}); // []
values(new String('hello')); // ['h', 'e', 'l', 'l', 'o']
values(1); // throw exception
values(true); // throw exception
values(undefined); // throw exception
values(null); // throw exception
*/
function values(obj) {
var result = [];
if (Array.isArray(obj)) {
return obj.slice(0);
}
if (typeof obj == 'object' || typeof obj == 'function') {
var keys = Object.keys(obj);
var len = keys.length;
for (var i = 0; i < len; i++) {
result.push(obj[keys[i]]);
}
return result;
}
throw new Error('argument to `values` must be an object');
}
var justEntries = entries;
/*
// Object:
entries({c: 8, a: 4}); // [['c', 8], ['a', 4]]
entries({b: {bb: 4}, a: {aa: 2}}); // [['b', {bb: 4}], ['a', {aa: 2}]]
entries({}); // []
// Array:
entries([{c: 8}, {a: 4}]); // [[0, {c: 8}], [1, {a: 4}]]
entries(['Γ€', 'mauvais', 'ouvrier', 'point', 'de', 'bon', 'outil'])
// [[0, 'Γ€'], [1, 'mauvais'] ... [6, 'outil']]
entries([]); // []
*/
function entries(obj) {
if ((typeof obj != 'object' && typeof obj != 'function') || obj == null) {
throw new Error('argument to `entries` must be an object');
}
var result = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
result.push([key, obj[key]]);
}
}
return result;
}
var justPick = pick;
/*
var obj = {a: 3, b: 5, c: 9};
pick(obj, ['a', 'c']); // {a: 3, c: 9}
pick(obj, 'a', 'c'); // {a: 3, c: 9}
pick(obj, ['a', 'b', 'd']); // {a: 3, b: 5}
pick(obj, ['a', 'a']); // {a: 3}
*/
function pick(obj, select) {
var result = {};
if (typeof select === 'string') {
select = [].slice.call(arguments, 1);
}
var len = select.length;
for (var i = 0; i < len; i++) {
var key = select[i];
if (key in obj) {
result[key] = obj[key];
}
}
return result;
}
var justOmit = omit;
/*
var obj = {a: 3, b: 5, c: 9};
omit(obj, ['a', 'c']); // {b: 5}
omit(obj, a, c); // {b: 5}
omit(obj, ['a', 'b', 'd']); // {c: 9}
omit(obj, ['a', 'a']); // {b: 5, c: 9}
*/
function omit(obj, remove) {
var result = {};
if (typeof remove === 'string') {
remove = [].slice.call(arguments, 1);
}
for (var prop in obj) {
if (!obj.hasOwnProperty || obj.hasOwnProperty(prop)) {
if (remove.indexOf(prop) === -1) {
result[prop] = obj[prop];
}
}
}
return result;
}
var justFilterObject = filter;
/*
var obj = {a: 3, b: 5, c: 9};
filter(obj, function(key, value) {
return value < 6;
}); // {a: 3, b: 5}
var obj = {a1: 3, b1: 5, a2: 9};
filter(obj, function(key, value) {
return key[0] == 'a';
}); // {a1: 3, a2: 9}
var obj = {a: 3, b: 5, c: null};
filter(obj, function(key, value) {
return value;
}); // {a: 3, b: 5}
*/
function filter(obj, predicate) {
var result = {};
var keys = Object.keys(obj);
var len = keys.length;
for (var i = 0; i < len; i++) {
var key = keys[i];
if (predicate(key, obj[key])) {
result[key] = obj[key];
}
}
return result;
}
var justMapObject = map$2;
/*
// returns a new object with the predicate applied to each value
// like just-map-value, but (key, value) are passed to the predicate
map({a: 3, b: 5, c: 9}, (key, value) => value + 1); // {a: 4, b: 6, c: 10}
map({a: 3, b: 5, c: 9}, (key, value) => key); // {a: 'a', b: 'b', c: 'c'}
map({a: 3, b: 5, c: 9}, (key, value) => key + value); // {a: 'a3', b: 'b5', c: 'c9'}
*/
function map$2(obj, predicate) {
var result = {};
var keys = Object.keys(obj);
var len = keys.length;
for (var i = 0; i < len; i++) {
var key = keys[i];
result[key] = predicate(key, obj[key]);
}
return result;
}
var justMapValues = map$1;
/*
// returns a new object with the predicate applied to each value
// like just-map-object, but (value, key, object) are passed to the predicate
map({a: 3, b: 5, c: 9}, (value) => value + 1); // {a: 4, b: 6, c: 10}
map({a: 3, b: 5, c: 9}, (value, key) => value + key); // {a: 3a, b: 5b, c: 9c}
map({a: 3, b: 5, c: 9}, (value, key, object) => object.b); // {a: 5, b: 5, c: 5}
*/
function map$1(obj, predicate) {
var result = {};
var keys = Object.keys(obj);
var len = keys.length;
for (var i = 0; i < len; i++) {
var key = keys[i];
result[key] = predicate(obj[key], key, obj);
}
return result;
}
var justMapKeys = map;
/*
map({a: 'cow', b: 'sheep', c: pig'}, (value) => value);
// {cow: 'cow', sheep: 'sheep', pig: pig'}
map([4, 5, 6], (value, key) => key + 1); // {1: 4, 2: 5, 3: 6}
map({a: 3, b: 5, c: 9}, (value, key) => key + value); // {a3: 3, b5: 5, c9: 9}
map({a: 3, b: 5, c: 9}, (value, key, object) => key + object.b);
// {a5: 3, b5: 5, c5: 9}
*/
function map(obj, predicate) {
var result = {};
var keys = Object.keys(obj);
var len = keys.length;
for (var i = 0; i < len; i++) {
var key = keys[i];
var value = obj[key];
var newKey = predicate(value, key, obj);
result[newKey] = value;
}
return result;
}
var justReduceObject = reduce;
function reduce(obj, predicate /*, initialValue*/) {
var args = [callback];
// `initialValue` is optional
var hasInitialValue = 2 in arguments;
hasInitialValue && args.push(arguments[2]);
function callback(previousValue, currentKey, currentIndex, array) {
// when `initialValue` is not provided then
// `previousValue` is the value associated to the first key
if (!hasInitialValue) {
previousValue = obj[array[0]];
hasInitialValue = true;
}
return predicate(
previousValue,
currentKey,
obj[currentKey],
currentIndex,
array
);
}
return Array.prototype.reduce.apply(Object.keys(obj), args);
}
var justIsEmpty = isEmpty;
/*
isEmpty({a: 3, b: 5}) // false
isEmpty([1, 2]) // false
isEmpty(new Set([1, 2, 2])) // false
isEmpty((new Map()).set('a', 2)) // false
isEmpty({}) // true
isEmpty([]) // true
isEmpty(new Set()) // true
isEmpty(new Map()) // true
isEmpty('abc') // false
isEmpty('') // true
isEmpty(0) // true
isEmpty(1) // true
isEmpty(true) // true
isEmpty(Symbol('abc')); // true
isEmpty(//); // true
isEmpty(new String('abc')); // false
isEmpty(new String('')); // true
isEmpty(new Boolean(true)); // true
isEmpty(null) // true
isEmpty(undefined) // true
*/
function isEmpty(obj) {
if (obj == null) {
return true;
}
if (Array.isArray(obj)) {
return !obj.length;
}
if (typeof obj == 'string') {
return !obj.length;
}
var type = {}.toString.call(obj);
if (type == '[object Object]') {
return !Object.keys(obj).length;
}
if (type == '[object Map]' || type == '[object Set]') {
return !obj.size;
}
// other primitive || unidentifed object type
return Object(obj) !== obj || !Object.keys(obj).length;
}
var justIsCircular = isCircular;
/*
const a = {};
a.b = a;
isCircular(a) // true
const a = {};
a.b = {
c: a
}
isCircular(a) // true
const a = {};
a.b = {
c: 4
}
isCircular(a) // false
const a = [];
a.push(a);
isCircular(a) // true
isCircular({}) // false
isCircular('hi') // false
isCircular(undefined) // false
*/
// safari, ff, chrome/opera
var errorKeywords = ['circular', 'cyclic'];
function isCircular(obj) {
if (typeof obj === 'function') {
throw new Error('cannot determine if function is circular');
}
try {
JSON.stringify(obj);
} catch (err) {
var index = errorKeywords.length;
while (index--) {
if (err.message.indexOf(errorKeywords[index]) > -1) {
return true;
}
}
throw err;
}
return false;
}
var justIsPrimitive = isPrimitive;
/*
isPrimitive('hi') // true
isPrimitive(3) // true
isPrimitive(true) // true
isPrimitive(false) // true
isPrimitive(null) // true
isPrimitive(undefined) // true
isPrimitive(Symbol()) // true
isPrimitive({}) // false
isPrimitive([]) // false
isPrimitive(function() {}) // false
isPrimitive(new Date()) // false
isPrimitive(/a/) // false
*/
function isPrimitive(obj) {
return obj !== Object(obj);
}
var justSafeGet = get;
/*
const obj = {a: {aa: {aaa: 2}}, b: 4};
get(obj, 'a.aa.aaa'); // 2
get(obj, ['a', 'aa', 'aaa']); // 2
get(obj, 'b.bb.bbb'); // undefined
get(obj, ['b', 'bb', 'bbb']); // undefined
get(obj.a, 'aa.aaa'); // 2
get(obj.a, ['aa', 'aaa']); // 2
get(obj.b, 'bb.bbb'); // undefined
get(obj.b, ['bb', 'bbb']); // undefined
get(obj.b, 'bb.bbb', 42); // 42
get(obj.b, ['bb', 'bbb'], 42); // 42
get(null, 'a'); // undefined
get(undefined, ['a']); // undefined
get(null, 'a', 42); // 42
get(undefined, ['a'], 42); // 42
const obj = {a: {}};
const sym = Symbol();
obj.a[sym] = 4;
get(obj.a, sym); // 4
*/
function get(obj, propsArg, defaultValue) {
if (!obj) {
return defaultValue;
}
var props, prop;
if (Array.isArray(propsArg)) {
props = propsArg.slice(0);
}
if (typeof propsArg == 'string') {
props = propsArg.split('.');
}
if (typeof propsArg == 'symbol') {
props = [propsArg];
}
if (!Array.isArray(props)) {
throw new Error('props arg must be an array, a string or a symbol');
}
while (props.length) {
prop = props.shift();
if (!obj) {
return defaultValue;
}
obj = obj[prop];
if (obj === undefined) {
return defaultValue;
}
}
return obj;
}
var justSafeSet = set;
/*
var obj1 = {};
set(obj1, 'a.aa.aaa', 4); // true
obj1; // {a: {aa: {aaa: 4}}}
var obj2 = {};
set(obj2, ['a', 'aa', 'aaa'], 4); // true
obj2; // {a: {aa: {aaa: 4}}}
var obj3 = {a: {aa: {aaa: 2}}};
set(obj3, 'a.aa.aaa', 3); // true
obj3; // {a: {aa: {aaa: 3}}}
// don't clobber existing
var obj4 = {a: {aa: {aaa: 2}}};
set(obj4, 'a.aa', {bbb: 7}); // false
const obj5 = {a: {}};
const sym = Symbol();
set(obj5.a, sym, 7); // true
obj5; // {a: {Symbol(): 7}}
*/
function set(obj, propsArg, value) {
var props, lastProp;
if (Array.isArray(propsArg)) {
props = propsArg.slice(0);
}
if (typeof propsArg == 'string') {
props = propsArg.split('.');
}
if (typeof propsArg == 'symbol') {
props = [propsArg];
}
if (!Array.isArray(props)) {
throw new Error('props arg must be an array, a string or a symbol');
}
lastProp = props.pop();
if (!lastProp) {
return false;
}
prototypeCheck(lastProp);
var thisProp;
while ((thisProp = props.shift())) {
prototypeCheck(thisProp);
if (typeof obj[thisProp] == 'undefined') {
obj[thisProp] = {};
}
obj = obj[thisProp];
if (!obj || typeof obj != 'object') {
return false;
}
}
obj[lastProp] = value;
return true;
}
function prototypeCheck(prop) {
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
throw new Error('setting of prototype values not supported');
}
}
var justTypeof = typeOf;
/*
typeOf({}); // 'object'
typeOf([]); // 'array'
typeOf(function() {}); // 'function'
typeOf(async function() {}); // 'function'
typeOf(/a/); // 'regexp'
typeOf(new Date()); // 'date'
typeOf(null); // 'null'
typeOf(undefined); // 'undefined'
typeOf('a'); // 'string'
typeOf(1); // 'number'
typeOf(true); // 'boolean'
*/
function typeOf(obj) {
if (obj === null) {
return 'null';
}
if (obj !== Object(obj)) {
return typeof obj;
}
var result = {}.toString
.call(obj)
.slice(8, -1)
.toLowerCase();
// strip function adornments (e.g. "sAsyncFunction")
return result.toLowerCase().indexOf('function') > -1 ? 'function' : result;
}
var justFlipObject = flip;
/*
// flip the key and value
flip({a: 'x', b: 'y', c: 'z'}); // {x: 'a', y: 'b', z: 'c'}
flip({a: 1, b: 2, c: 3}); // {'1': 'a', '2': 'b', '3': 'c'}
flip({a: false, b: true}); // {false: 'a', true: 'b'}
*/
function flip(obj) {
var result = {};
var keys = Object.keys(obj);
var len = keys.length;
for (var i = 0; i < len; i++) {
var key = keys[i];
result[obj[key]] = key;
}
return result;
}
var omit$1 = justOmit.omit;
var values$1 = justValues.values;
export { justIsCircular as circular, justIsEmpty as empty, justEntries as entries, justExtend as extend, justFilterObject as filterObject, justFlipObject as flipObject, justMapKeys as mapKeys, justMapObject as mapObject, justMapValues as mapValues, justMerge as merge, justTypeof as objectsTypeof, omit$1 as omit, justPick as pick, justIsPrimitive as primitive, justReduceObject as reduceObject, justSafeGet as safeGet, justSafeSet as safeSet, values$1 as values };
//# sourceMappingURL=objects.js.map

2

package.json
{
"name": "all-of-just",
"private": false,
"version": "0.3.0",
"version": "0.4.0",
"description": "A single collection of all of Just utility functions in one single library",

@@ -6,0 +6,0 @@ "files": [

@@ -1,2 +0,242 @@

export { j as mean, a as median, b as mode, c as percentile, f as skewness, e as stdev, d as variance } from './index-6aef6b13.js';
var justMean = mean;
function mean(arr) {
if (!Array.isArray(arr)) {
arr = [].slice.call(arguments);
}
if (!arr.length) {
throw new Error('no values were passed to `mean`');
}
var sum = 0;
var len = arr.length;
for (var i = 0; i < len; i++) {
var n = arr[i];
if (!Number.isFinite(n)) {
throw new Error('all values passed to `mean` must be numeric');
}
sum += n;
}
return sum / len;
}
var justMedian = median;
var nonNumericMsg$1 = 'all values passed to `median` must be numeric';
function median(arr) {
if (!Array.isArray(arr)) {
arr = [].slice.call(arguments);
}
if (!arr.length) {
throw new Error('no values were passed to `median`');
}
if (arr.length == 1) {
if (Number.isFinite(arr[0])) {
return arr[0];
} else {
throw new Error(nonNumericMsg$1);
}
}
var sorted = arr.sort(function(a, b) {
if (!Number.isFinite(a)) {
throw new Error(nonNumericMsg$1);
}
return a >= b ? 1 : -1;
});
var lowerMiddleRank = Math.floor(arr.length / 2);
return arr.length / 2 != lowerMiddleRank
? sorted[lowerMiddleRank]
: (sorted[lowerMiddleRank] + sorted[lowerMiddleRank - 1]) / 2;
}
var justMode = mode;
function mode(arr) {
if (!Array.isArray(arr)) {
arr = [].slice.call(arguments);
}
var map = {};
var ArrLen = arr.length;
for (var i = 0; i < ArrLen; i++) {
var n = arr[i];
if (typeof n != 'number') {
throw new Error('all values passed to `mode` must be numeric');
}
n in map ? map[n]++ : (map[n] = 1);
}
var mapKeys = Object.keys(map);
var mapKeysLen = mapKeys.length;
if (!mapKeysLen) {
throw new Error('no values were passed to `mode`');
}
var maxOccurences = -1;
var result;
for (var i = 0; i < mapKeysLen; i++) {
var thisKey = mapKeys[i];
if (map[thisKey] > maxOccurences) {
result = [Number(thisKey)];
maxOccurences = map[thisKey];
} else if (map[thisKey] == maxOccurences) {
result.push(Number(thisKey));
}
}
return result.length > 1
? result.sort(function(a, b) {
return a >= b ? 1 : -1;
})
: result[0];
}
var justPercentile = percentile;
var nonNumericMsg = 'all values passed to `percentile` must be numeric';
// Using linear interpolation method
// https://en.wikipedia.org/wiki/Percentile
function percentile(arr, percentileValue) {
if (!Array.isArray(arr)) {
throw new Error('the argument to `percentile` must be an array');
}
if (!arr.length) {
throw new Error('no values were passed to `percentile`');
}
if (arr.length == 1) {
if (Number.isFinite(arr[0])) {
return arr[0];
} else {
throw new Error(nonNumericMsg);
}
}
var sorted = arr.sort(function(a, b) {
if (!Number.isFinite(a)) {
throw new Error(nonNumericMsg);
}
return a >= b ? 1 : -1;
});
var percentileRank = Math.min(
Math.max((arr.length * percentileValue) / 100 - 0.5, 0),
arr.length - 1
);
var lowerInt = Math.floor(percentileRank);
if (percentileRank == lowerInt) {
return sorted[lowerInt];
} else {
var upperInt = Math.ceil(percentileRank);
return (
sorted[lowerInt] +
(percentileRank - lowerInt) * (sorted[upperInt] - sorted[lowerInt])
);
}
}
var justVariance = variance;
function variance(arr) {
if (!Array.isArray(arr)) {
arr = [].slice.call(arguments);
}
if (!arr.length || arr.length < 2) {
throw new Error('less than one value was passed to `variance`');
}
var sum = 0;
var len = arr.length;
for (var i = 0; i < len; i++) {
var n = arr[i];
if (typeof n != 'number' || !n) {
throw new Error('all values passed to `variance` must be numeric');
}
sum += n;
}
var mean = sum / len;
var acc = 0;
for (var i = 0; i < len; i++) {
var n = arr[i];
acc += (n - mean) * (n - mean);
}
return acc / (len - 1);
}
var justStdev = stdev;
function stdev(arr) {
if (!Array.isArray(arr)) {
arr = [].slice.call(arguments);
}
if (!arr.length || arr.length < 2) {
throw new Error('less than one value was passed to `variance`');
}
var sum = 0;
var len = arr.length;
for (var i = 0; i < len; i++) {
var n = arr[i];
if (typeof n != 'number' || !n) {
throw new Error('all values passed to `variance` must be numeric');
}
sum += n;
}
var mean = sum / len;
var acc = 0;
for (var i = 0; i < len; i++) {
var n = arr[i];
acc += (n - mean) * (n - mean);
}
return Math.sqrt(acc / (len - 1));
}
var justSkewness = skewness;
function skewness(arr) {
if (!Array.isArray(arr)) {
arr = [].slice.call(arguments);
}
if (!arr.length || arr.length < 2) {
throw new Error('less than one value was passed to `skewness`');
}
var standardDeviation, mean, median;
// standard deviation
var sum = 0;
var len = arr.length;
for (var i = 0; i < len; i++) {
var n = arr[i];
if (!Number.isFinite(n)) {
throw new Error('all values passed to `skewness` must be numeric');
}
sum += n;
}
mean = sum / len;
var acc = 0;
for (var i = 0; i < len; i++) {
var n = arr[i];
acc += (n - mean) * (n - mean);
}
standardDeviation = Math.sqrt(acc / (len - 1));
// median
if (arr.length == 1) {
median = arr[0];
}
var sorted = arr.sort(function(a, b) {
return a >= b ? 1 : -1;
});
var lowerMiddleRank = Math.floor(arr.length / 2);
median =
arr.length / 2 != lowerMiddleRank
? sorted[lowerMiddleRank]
: (sorted[lowerMiddleRank] + sorted[lowerMiddleRank - 1]) / 2;
// Pearson's second skewness coefficient (median skewness)
return (3 * (mean - median)) / standardDeviation;
}
export { justMean as mean, justMedian as median, justMode as mode, justPercentile as percentile, justSkewness as skewness, justStdev as stdev, justVariance as variance };
//# sourceMappingURL=statistics.js.map

@@ -1,2 +0,328 @@

export { e as camelCase, k as capitalize, f as kebabCase, i as leftPad, h as pascalCase, b as prune, l as replaceAll, d as rightPad, g as snakeCase, c as squash, j as template, a as truncate } from './index-30bb0e4d.js';
var justTemplate = template;
/*
var data = {
a: {
aa: {
aaa: 'apple',
bbb: 'pear'
},
bb: 'orange'
},
b: 'plum'
};
template('2 {{a.aa.aaa}}s, a {{a.aa.bbb}}, 3 {{a.bb}}s and a {{b}}. Yes 1 {{a.aa.bbb}}.', data);
// '2 apples, a pear, 3 oranges and a plum. Yes 1 pear.'
*/
function template(string, data) {
var proxyRegEx = /\{\{([^\}]+)?\}\}/g;
return string.replace(proxyRegEx, function(_, key) {
var keyParts = key.split('.');
var value = data;
for (var i = 0; i < keyParts.length; i++) {
value = value[keyParts[i]];
}
return value || '';
});
}
var justTruncate = truncate;
/*
truncate('when shall we three meet again', 9); // 'when s...'
truncate('when shall we three meet again', 10, ' (etc)'); // 'when (etc)'
truncate('when shall we', 15,); // 'when shall we'
truncate('when shall we', 15, '(more)'); // 'when shall we'
truncate('when shall we', 7, ' (more)'); // ' (more)'
*/
function truncate(str, length, end) {
if (length == null || length >= str.length) {
return str;
}
if (end == null) {
end = '…';
}
return str.slice(0, Math.max(0, length - end.length)) + end;
}
var justPrune = prune;
/*
prune('when shall we three meet again', 7); // 'when...'
prune('when shall we three meet again', 7, ' (more)'; // 'when (more)'
prune('when shall we', 15,); // 'when shall we'
prune('when shall we', 15, ' (etc)'); // 'when shall we'
prune('when shall we', 7, ' (more)'); // ' (more)'
*/
function prune(str, length, end) {
if (length == null || length >= str.length) {
return str;
}
if (end == null) {
end = '...';
}
var remnantPlusOne = str.slice(0, Math.max(0, length - end.length) + 1);
var lastSpace = Math.max(0, remnantPlusOne.lastIndexOf(' '));
return remnantPlusOne.slice(0, lastSpace) + end;
}
var justSquash = squash;
/*
remove spaces, optionally remove escape sequences \t, \n, \f, \r and \v
squash('the cat sat on the mat'); // 'thecatsatonthemat'
squash(' the cat sat on the mat '); // 'thecatsatonthemat'
squash('\tthe cat\n sat \fon \vthe \rmat '); // '\tthecat\nsat\fon\vthe\rmat'
squash('\tthe cat\n sat \fon \vthe \rmat ', true); // 'thecatsatonthemat'
squash(`the cat
sat on the mat`, true); // thecatsatonthemat
*/
var escapeSequencesRegex = /\s/g;
var spacesRegex = / /g;
function squash(str, squashEscapeSequences) {
if (squashEscapeSequences) {
return str.replace(escapeSequencesRegex, '');
} else {
return str.replace(spacesRegex, '');
}
}
var index_min=leftPad;var surrogatePairRegEx$1=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;function leftPad(str,length,padStr){if(typeof str!="string"||arguments.length>2&&typeof padStr!="string"||!(isFinite(length)&&length>=0&&Math.floor(length)===length)){throw Error("1st and 3rd args must be strings, 2nd arg must be a positive integer")}if(padStr==null||padStr==""){padStr=" ";}var strLen=str.length-(str.match(surrogatePairRegEx$1)||[]).length;var padStrLen=padStr.length;var surrPairsInPad=(padStr.match(surrogatePairRegEx$1)||[]).length;if(surrPairsInPad&&padStrLen/surrPairsInPad!=2){throw Error("padding mixes regular characters and surrogate pairs")}if(!length||length<=strLen){return str}var padCount=Math.floor((length-strLen)/padStrLen);var padRemainder=(length-strLen)%padStrLen;if(surrPairsInPad){padCount=2*padCount;padRemainder=2*padRemainder;}return (padRemainder?[padStr.slice(-padRemainder)]:[]).concat(new Array(padCount+1).join(padStr)).concat(str).join("")}
var justRightPad = rightPad;
/*
rightPad('hello', 9); // 'hello '
rightPad('hello', 3); // 'hello'
rightPad('hello', 9, '.'); // 'hello....'
rightPad('hello', 9, '..'); // 'hello....'
rightPad('hello', 10, 'ab'); // 'helloababa'
rightPad('hello', 9, '\uD83D\uDC04'); // 'helloπŸ„πŸ„πŸ„πŸ„'
rightPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'helloπŸ‘πŸ„πŸ‘πŸ„πŸ‘'
rightPad('hello', 7, 'πŸ„'), // 'helloπŸ„πŸ„'
rightPad(null, 7); // throws
rightPad([], 4, '*'); // throws
rightPad('hello', 4, true); // throws
rightPad('hello', -4, true); // throws
rightPad('hello', 2.3, true); // throws
*/
var surrogatePairRegEx = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
function rightPad(str, length, padStr) {
if (
typeof str != 'string' ||
(arguments.length > 2 && typeof padStr != 'string') ||
!(isFinite(length) && length >= 0 && Math.floor(length) === length)
) {
throw Error('1st and 3rd args must be strings, 2nd arg must be a positive integer');
}
if (padStr == null || padStr == '') {
padStr = ' ';
}
var strLen = str.length - (str.match(surrogatePairRegEx) || []).length;
var padStrLen = padStr.length;
var surrPairsInPad = (padStr.match(surrogatePairRegEx) || []).length;
if (surrPairsInPad && padStrLen / surrPairsInPad != 2) {
throw Error('padding mixes regular characters and surrogate pairs');
}
if (!length || length <= strLen) {
return str;
}
var padCount = Math.floor((length - strLen) / padStrLen);
var padRemainder = (length - strLen) % padStrLen;
if (surrPairsInPad) {
padCount = 2 * padCount;
padRemainder = 2 * padRemainder;
}
return [str]
.concat(new Array(padCount + 1).join(padStr))
.concat(padRemainder ? padStr.slice(0, padRemainder) : '')
.join('');
}
var justCamelCase = camelCase;
// any combination of spaces and punctuation characters
// thanks to http://stackoverflow.com/a/25575009
var wordSeparatorsRegEx = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/;
var basicCamelRegEx = /^[a-z\u00E0-\u00FCA-Z\u00C0-\u00DC][\d|a-z\u00E0-\u00FCA-Z\u00C0-\u00DC]*$/;
var fourOrMoreConsecutiveCapsRegEx = /([A-Z\u00C0-\u00DC]{4,})/g;
var allCapsRegEx = /^[A-Z\u00C0-\u00DC]+$/;
function camelCase(str, options) {
var words = str.split(wordSeparatorsRegEx);
var len = words.length;
var mappedWords = new Array(len);
for (var i = 0; i < len; i++) {
var word = words[i];
if (word === '') {
continue;
}
var isCamelCase = basicCamelRegEx.test(word) && !allCapsRegEx.test(word);
if (isCamelCase) {
word = word.replace(fourOrMoreConsecutiveCapsRegEx, function(match, p1, offset) {
return deCap(match, word.length - offset - match.length == 0);
});
}
var firstLetter = word[0];
firstLetter = i > 0 ? firstLetter.toUpperCase() : firstLetter.toLowerCase();
mappedWords[i] = firstLetter + (!isCamelCase ? word.slice(1).toLowerCase() : word.slice(1));
}
return mappedWords.join('');
}
function deCap(match, endOfWord) {
var arr = match.split('');
var first = arr.shift().toUpperCase();
var last = endOfWord ? arr.pop().toLowerCase() : arr.pop();
return first + arr.join('').toLowerCase() + last;
}
var justKebabCase = kebabCase;
/*
kebabCase('the quick brown fox'); // 'the-quick-brown-fox'
kebabCase('the-quick-brown-fox'); // 'the-quick-brown-fox'
kebabCase('the_quick_brown_fox'); // 'the-quick-brown-fox'
kebabCase('theQuickBrownFox'); // 'the-quick-brown-fox'
kebabCase('theQuickBrown Fox'); // 'the-quick-brown-fox'
kebabCase('thequickbrownfox'); // 'thequickbrownfox'
kebabCase('the - quick * brown# fox'); // 'the-quick-brown-fox'
kebabCase('theQUICKBrownFox'); // 'the-q-u-i-c-k-brown-fox'
*/
// any combination of spaces and punctuation characters
// thanks to http://stackoverflow.com/a/25575009
var wordSeparators$2 = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/;
var capitals$1 = /[A-Z\u00C0-\u00D6\u00D9-\u00DD]/g;
function kebabCase(str) {
//replace capitals with space + lower case equivalent for later parsing
str = str.replace(capitals$1, function(match) {
return ' ' + (match.toLowerCase() || match);
});
return str
.trim()
.split(wordSeparators$2)
.join('-');
}
var justSnakeCase = snakeCase;
/*
snakeCase('the quick brown fox'); // 'the_quick_brown_fox'
snakeCase('the-quick-brown-fox'); // 'the_quick_brown_fox'
snakeCase('the_quick_brown_fox'); // 'the_quick_brown_fox'
snakeCase('theQuickBrownFox'); // 'the_quick_brown_fox'
snakeCase('theQuickBrown Fox'); // 'the_quick_brown_Fox'
snakeCase('thequickbrownfox'); // 'thequickbrownfox'
snakeCase('the - quick * brown# fox'); // 'the_quick_brown_fox'
snakeCase('theQUICKBrownFox'); // 'the_q_u_i_c_k_brown_fox'
*/
// any combination of spaces and punctuation characters
// thanks to http://stackoverflow.com/a/25575009
var wordSeparators$1 = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/;
var capitals = /[A-Z\u00C0-\u00D6\u00D9-\u00DD]/g;
function snakeCase(str) {
//replace capitals with space + lower case equivalent for later parsing
str = str.replace(capitals, function(match) {
return ' ' + (match.toLowerCase() || match);
});
return str
.trim()
.split(wordSeparators$1)
.join('_');
}
var justPascalCase = pascalCase;
/*
pascalCase('the quick brown fox'); // 'TheQuickBrownFox'
pascalCase('the_quick_brown_fox'); // 'TheQuickBrownFox'
pascalCase('the-quick-brown-fox'); // 'TheQuickBrownFox'
pascalCase('theQuickBrownFox'); // 'TheQuickBrownFox'
pascalCase('thequickbrownfox'); // 'Thequickbrownfox'
pascalCase('the - quick * brown# fox'); // 'TheQuickBrownFox'
pascalCase('theQUICKBrownFox'); // 'TheQUICKBrownFox'
*/
// any combination of spaces and punctuation characters
// thanks to http://stackoverflow.com/a/25575009
var wordSeparators = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/;
function pascalCase(str) {
var words = str.split(wordSeparators);
var len = words.length;
var mappedWords = new Array(len);
for (var i = 0; i < len; i++) {
var word = words[i];
if (word === '') {
continue;
}
mappedWords[i] = word[0].toUpperCase() + word.slice(1);
}
return mappedWords.join('');
}
var justCapitalize = capitalize;
/*
capitalize('capitals'); // 'Capitals'
capitalize('Capitals'); // 'Capitals'
capitalize('CapiTALS'); // 'Capitals'
capitalize('many Words'); // 'Many words'
capitalize('!exclaim'); // '!exclaim'
*/
function capitalize(str) {
if (typeof str != 'string') {
throw Error('just-capitalize expects a string argument');
}
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}
var justReplaceAll = replaceAll;
/*
replaceAll('hello, world', 'l', 'q'); // 'heqqo, worqd'
replaceAll('hello, world', 'l', 'qq'); // 'heqqqqo, worqqd'
replaceAll('hello, world', 'll', 'q'); // 'heqo, world'
replaceAll('hello, world', '', 'q'); // 'hello, world'
replaceAll('hello, world', 'l', ''); // 'heo, word'
replaceAll('hello, world', null, 'q'); // 'hello, world'
replaceAll('hello, world', 'l'); // throw
replaceAll('hello, world'); // throw
replaceAll(); // throw
replaceAll(null, 'l', 'q'); // throw
replaceAll('hello, world', null, 'q'); // throw
replaceAll('hello, world', 'l', null); // throw
*/
function replaceAll(str, subStr, newSubStr) {
if (
arguments.length !== 3 ||
typeof str != 'string' ||
typeof subStr != 'string' ||
typeof newSubStr != 'string'
) {
throw new Error('just-replace-all expects three string arguments');
}
if (!subStr) {
return str;
}
return str.split(subStr).join(newSubStr);
}
export { justCamelCase as camelCase, justCapitalize as capitalize, justKebabCase as kebabCase, index_min as leftPad, justPascalCase as pascalCase, justPrune as prune, justReplaceAll as replaceAll, justRightPad as rightPad, justSnakeCase as snakeCase, justSquash as squash, justTemplate as template, justTruncate as truncate };
//# sourceMappingURL=strings.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc