add test, update tags, update description
This commit is contained in:
92
dist/_30s.es5.js
vendored
92
dist/_30s.es5.js
vendored
@ -846,6 +846,15 @@
|
|||||||
return fn(obj[key], key, obj);
|
return fn(obj[key], key, obj);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var formToObject = function formToObject(form) {
|
||||||
|
return Array.from(new FormData(form)).reduce(function (acc, _ref10) {
|
||||||
|
var _ref11 = _slicedToArray(_ref10, 2),
|
||||||
|
key = _ref11[0],
|
||||||
|
value = _ref11[1];
|
||||||
|
|
||||||
|
return _objectSpread({}, acc, _defineProperty({}, key, value));
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
var formatDuration = function formatDuration(ms) {
|
var formatDuration = function formatDuration(ms) {
|
||||||
if (ms < 0) ms = -ms;
|
if (ms < 0) ms = -ms;
|
||||||
var time = {
|
var time = {
|
||||||
@ -857,10 +866,10 @@
|
|||||||
};
|
};
|
||||||
return Object.entries(time).filter(function (val) {
|
return Object.entries(time).filter(function (val) {
|
||||||
return val[1] !== 0;
|
return val[1] !== 0;
|
||||||
}).map(function (_ref10) {
|
}).map(function (_ref12) {
|
||||||
var _ref11 = _slicedToArray(_ref10, 2),
|
var _ref13 = _slicedToArray(_ref12, 2),
|
||||||
key = _ref11[0],
|
key = _ref13[0],
|
||||||
val = _ref11[1];
|
val = _ref13[1];
|
||||||
|
|
||||||
return "".concat(val, " ").concat(key).concat(val !== 1 ? 's' : '');
|
return "".concat(val, " ").concat(key).concat(val !== 1 ? 's' : '');
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
@ -1060,9 +1069,9 @@
|
|||||||
var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
||||||
|
|
||||||
if (end && start > end) {
|
if (end && start > end) {
|
||||||
var _ref12 = [start, end];
|
var _ref14 = [start, end];
|
||||||
end = _ref12[0];
|
end = _ref14[0];
|
||||||
start = _ref12[1];
|
start = _ref14[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
return end == null ? n >= 0 && n < start : n >= start && n < end;
|
||||||
@ -1450,14 +1459,14 @@
|
|||||||
}, {});
|
}, {});
|
||||||
}, {});
|
}, {});
|
||||||
};
|
};
|
||||||
var midpoint = function midpoint(_ref13, _ref14) {
|
var midpoint = function midpoint(_ref15, _ref16) {
|
||||||
var _ref15 = _slicedToArray(_ref13, 2),
|
var _ref17 = _slicedToArray(_ref15, 2),
|
||||||
x1 = _ref15[0],
|
x1 = _ref17[0],
|
||||||
y1 = _ref15[1];
|
y1 = _ref17[1];
|
||||||
|
|
||||||
var _ref16 = _slicedToArray(_ref14, 2),
|
var _ref18 = _slicedToArray(_ref16, 2),
|
||||||
x2 = _ref16[0],
|
x2 = _ref18[0],
|
||||||
y2 = _ref16[1];
|
y2 = _ref18[1];
|
||||||
|
|
||||||
return [(x1 + x2) / 2, (y1 + y2) / 2];
|
return [(x1 + x2) / 2, (y1 + y2) / 2];
|
||||||
};
|
};
|
||||||
@ -1531,10 +1540,10 @@
|
|||||||
return (n === -1 ? arr.slice(n) : arr.slice(n, n + 1))[0];
|
return (n === -1 ? arr.slice(n) : arr.slice(n, n + 1))[0];
|
||||||
};
|
};
|
||||||
var objectFromPairs = function objectFromPairs(arr) {
|
var objectFromPairs = function objectFromPairs(arr) {
|
||||||
return arr.reduce(function (a, _ref17) {
|
return arr.reduce(function (a, _ref19) {
|
||||||
var _ref18 = _slicedToArray(_ref17, 2),
|
var _ref20 = _slicedToArray(_ref19, 2),
|
||||||
key = _ref18[0],
|
key = _ref20[0],
|
||||||
val = _ref18[1];
|
val = _ref20[1];
|
||||||
|
|
||||||
return a[key] = val, a;
|
return a[key] = val, a;
|
||||||
}, {});
|
}, {});
|
||||||
@ -1623,10 +1632,10 @@
|
|||||||
return _toConsumableArray(arr).sort(function (a, b) {
|
return _toConsumableArray(arr).sort(function (a, b) {
|
||||||
return props.reduce(function (acc, prop, i) {
|
return props.reduce(function (acc, prop, i) {
|
||||||
if (acc === 0) {
|
if (acc === 0) {
|
||||||
var _ref19 = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]],
|
var _ref21 = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]],
|
||||||
_ref20 = _slicedToArray(_ref19, 2),
|
_ref22 = _slicedToArray(_ref21, 2),
|
||||||
p1 = _ref20[0],
|
p1 = _ref22[0],
|
||||||
p2 = _ref20[1];
|
p2 = _ref22[1];
|
||||||
|
|
||||||
acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0;
|
acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0;
|
||||||
}
|
}
|
||||||
@ -2004,8 +2013,8 @@
|
|||||||
type: 'application/javascript; charset=utf-8'
|
type: 'application/javascript; charset=utf-8'
|
||||||
}));
|
}));
|
||||||
return new Promise(function (res, rej) {
|
return new Promise(function (res, rej) {
|
||||||
worker.onmessage = function (_ref21) {
|
worker.onmessage = function (_ref23) {
|
||||||
var data = _ref21.data;
|
var data = _ref23.data;
|
||||||
res(data), worker.terminate();
|
res(data), worker.terminate();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2022,18 +2031,18 @@
|
|||||||
var sample = function sample(arr) {
|
var sample = function sample(arr) {
|
||||||
return arr[Math.floor(Math.random() * arr.length)];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
};
|
};
|
||||||
var sampleSize = function sampleSize(_ref22) {
|
var sampleSize = function sampleSize(_ref24) {
|
||||||
var _ref23 = _toArray(_ref22),
|
var _ref25 = _toArray(_ref24),
|
||||||
arr = _ref23.slice(0);
|
arr = _ref25.slice(0);
|
||||||
|
|
||||||
var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
||||||
var m = arr.length;
|
var m = arr.length;
|
||||||
|
|
||||||
while (m) {
|
while (m) {
|
||||||
var i = Math.floor(Math.random() * m--);
|
var i = Math.floor(Math.random() * m--);
|
||||||
var _ref24 = [arr[i], arr[m]];
|
var _ref26 = [arr[i], arr[m]];
|
||||||
arr[m] = _ref24[0];
|
arr[m] = _ref26[0];
|
||||||
arr[i] = _ref24[1];
|
arr[i] = _ref26[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return arr.slice(0, n);
|
return arr.slice(0, n);
|
||||||
@ -2055,6 +2064,11 @@
|
|||||||
var serializeCookie = function serializeCookie(name, val) {
|
var serializeCookie = function serializeCookie(name, val) {
|
||||||
return "".concat(encodeURIComponent(name), "=").concat(encodeURIComponent(val));
|
return "".concat(encodeURIComponent(name), "=").concat(encodeURIComponent(val));
|
||||||
};
|
};
|
||||||
|
var serializeForm = function serializeForm(form) {
|
||||||
|
return Array.from(new FormData(form), function (field) {
|
||||||
|
return field.map(encodeURIComponent).join('=');
|
||||||
|
}).join('&');
|
||||||
|
};
|
||||||
var setStyle = function setStyle(el, ruleName, val) {
|
var setStyle = function setStyle(el, ruleName, val) {
|
||||||
return el.style[ruleName] = val;
|
return el.style[ruleName] = val;
|
||||||
};
|
};
|
||||||
@ -2080,17 +2094,17 @@
|
|||||||
return e.style.display = '';
|
return e.style.display = '';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var shuffle = function shuffle(_ref25) {
|
var shuffle = function shuffle(_ref27) {
|
||||||
var _ref26 = _toArray(_ref25),
|
var _ref28 = _toArray(_ref27),
|
||||||
arr = _ref26.slice(0);
|
arr = _ref28.slice(0);
|
||||||
|
|
||||||
var m = arr.length;
|
var m = arr.length;
|
||||||
|
|
||||||
while (m) {
|
while (m) {
|
||||||
var i = Math.floor(Math.random() * m--);
|
var i = Math.floor(Math.random() * m--);
|
||||||
var _ref27 = [arr[i], arr[m]];
|
var _ref29 = [arr[i], arr[m]];
|
||||||
arr[m] = _ref27[0];
|
arr[m] = _ref29[0];
|
||||||
arr[i] = _ref27[1];
|
arr[i] = _ref29[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
@ -2164,8 +2178,8 @@
|
|||||||
};
|
};
|
||||||
}).sort(function (a, b) {
|
}).sort(function (a, b) {
|
||||||
return compare(a.item, b.item) || a.index - b.index;
|
return compare(a.item, b.item) || a.index - b.index;
|
||||||
}).map(function (_ref28) {
|
}).map(function (_ref30) {
|
||||||
var item = _ref28.item;
|
var item = _ref30.item;
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -2715,6 +2729,7 @@
|
|||||||
exports.forEachRight = forEachRight;
|
exports.forEachRight = forEachRight;
|
||||||
exports.forOwn = forOwn;
|
exports.forOwn = forOwn;
|
||||||
exports.forOwnRight = forOwnRight;
|
exports.forOwnRight = forOwnRight;
|
||||||
|
exports.formToObject = formToObject;
|
||||||
exports.formatDuration = formatDuration;
|
exports.formatDuration = formatDuration;
|
||||||
exports.fromCamelCase = fromCamelCase;
|
exports.fromCamelCase = fromCamelCase;
|
||||||
exports.functionName = functionName;
|
exports.functionName = functionName;
|
||||||
@ -2885,6 +2900,7 @@
|
|||||||
exports.scrollToTop = scrollToTop;
|
exports.scrollToTop = scrollToTop;
|
||||||
exports.sdbm = sdbm;
|
exports.sdbm = sdbm;
|
||||||
exports.serializeCookie = serializeCookie;
|
exports.serializeCookie = serializeCookie;
|
||||||
|
exports.serializeForm = serializeForm;
|
||||||
exports.setStyle = setStyle;
|
exports.setStyle = setStyle;
|
||||||
exports.shallowClone = shallowClone;
|
exports.shallowClone = shallowClone;
|
||||||
exports.shank = shank;
|
exports.shank = shank;
|
||||||
|
|||||||
2
dist/_30s.es5.min.js
vendored
2
dist/_30s.es5.min.js
vendored
File diff suppressed because one or more lines are too long
10
dist/_30s.esm.js
vendored
10
dist/_30s.esm.js
vendored
@ -383,6 +383,12 @@ const forOwnRight = (obj, fn) =>
|
|||||||
Object.keys(obj)
|
Object.keys(obj)
|
||||||
.reverse()
|
.reverse()
|
||||||
.forEach(key => fn(obj[key], key, obj));
|
.forEach(key => fn(obj[key], key, obj));
|
||||||
|
const formToObject = form =>
|
||||||
|
Array.from(new FormData(form))
|
||||||
|
.reduce((acc, [key, value]) => ({
|
||||||
|
...acc,
|
||||||
|
[key]: value,
|
||||||
|
}), {});
|
||||||
const formatDuration = ms => {
|
const formatDuration = ms => {
|
||||||
if (ms < 0) ms = -ms;
|
if (ms < 0) ms = -ms;
|
||||||
const time = {
|
const time = {
|
||||||
@ -1041,6 +1047,8 @@ const sdbm = str => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
|
const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
|
||||||
|
const serializeForm = form =>
|
||||||
|
Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&');
|
||||||
const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
|
const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
|
||||||
const shallowClone = obj => Object.assign({}, obj);
|
const shallowClone = obj => Object.assign({}, obj);
|
||||||
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
||||||
@ -1350,4 +1358,4 @@ const zipWith = (...array) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compactWhitespace, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createDirIfNotExists, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, deepMapKeys, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterFalsy, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNegativeZero, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapNumRange, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, midpoint, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, vectorDistance, when, without, words, xProd, yesNo, zip, zipObject, zipWith };
|
export { CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compactWhitespace, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createDirIfNotExists, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, deepMapKeys, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterFalsy, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formToObject, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNegativeZero, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapNumRange, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, midpoint, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, serializeForm, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, vectorDistance, when, without, words, xProd, yesNo, zip, zipObject, zipWith };
|
||||||
|
|||||||
10
dist/_30s.js
vendored
10
dist/_30s.js
vendored
@ -389,6 +389,12 @@
|
|||||||
Object.keys(obj)
|
Object.keys(obj)
|
||||||
.reverse()
|
.reverse()
|
||||||
.forEach(key => fn(obj[key], key, obj));
|
.forEach(key => fn(obj[key], key, obj));
|
||||||
|
const formToObject = form =>
|
||||||
|
Array.from(new FormData(form))
|
||||||
|
.reduce((acc, [key, value]) => ({
|
||||||
|
...acc,
|
||||||
|
[key]: value,
|
||||||
|
}), {});
|
||||||
const formatDuration = ms => {
|
const formatDuration = ms => {
|
||||||
if (ms < 0) ms = -ms;
|
if (ms < 0) ms = -ms;
|
||||||
const time = {
|
const time = {
|
||||||
@ -1047,6 +1053,8 @@
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
|
const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
|
||||||
|
const serializeForm = form =>
|
||||||
|
Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&');
|
||||||
const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
|
const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
|
||||||
const shallowClone = obj => Object.assign({}, obj);
|
const shallowClone = obj => Object.assign({}, obj);
|
||||||
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
||||||
@ -1455,6 +1463,7 @@
|
|||||||
exports.forEachRight = forEachRight;
|
exports.forEachRight = forEachRight;
|
||||||
exports.forOwn = forOwn;
|
exports.forOwn = forOwn;
|
||||||
exports.forOwnRight = forOwnRight;
|
exports.forOwnRight = forOwnRight;
|
||||||
|
exports.formToObject = formToObject;
|
||||||
exports.formatDuration = formatDuration;
|
exports.formatDuration = formatDuration;
|
||||||
exports.fromCamelCase = fromCamelCase;
|
exports.fromCamelCase = fromCamelCase;
|
||||||
exports.functionName = functionName;
|
exports.functionName = functionName;
|
||||||
@ -1625,6 +1634,7 @@
|
|||||||
exports.scrollToTop = scrollToTop;
|
exports.scrollToTop = scrollToTop;
|
||||||
exports.sdbm = sdbm;
|
exports.sdbm = sdbm;
|
||||||
exports.serializeCookie = serializeCookie;
|
exports.serializeCookie = serializeCookie;
|
||||||
|
exports.serializeForm = serializeForm;
|
||||||
exports.setStyle = setStyle;
|
exports.setStyle = setStyle;
|
||||||
exports.shallowClone = shallowClone;
|
exports.shallowClone = shallowClone;
|
||||||
exports.shank = shank;
|
exports.shank = shank;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
### formToObject
|
### formToObject
|
||||||
|
|
||||||
Serializes a form into an object.
|
Encode a set of form elements as a `object`.
|
||||||
|
|
||||||
First we transform the `form` into `FormData`, then we convert it into an `array` and from the `array` we collect an `object`
|
First we transform the `form` into `FormData`, then we convert it into an `array` and from the `array` we collect an `object`
|
||||||
|
|
||||||
@ -13,13 +13,6 @@ const formToObject = form =>
|
|||||||
}), {})
|
}), {})
|
||||||
```
|
```
|
||||||
|
|
||||||
```html
|
|
||||||
<form id="form">
|
|
||||||
<input name="email" type="email" />
|
|
||||||
<input name="name" />
|
|
||||||
</form>
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
formToObject(document.querySelector('#form')) // { email: 'test@email.com', name: 'Test Name' }
|
formToObject(document.querySelector('#form')) // { email: 'test@email.com', name: 'Test Name' }
|
||||||
```
|
```
|
||||||
@ -1,6 +1,6 @@
|
|||||||
### serializeForm
|
### serializeForm
|
||||||
|
|
||||||
Serializes a form into an object.
|
Encode a set of form elements as a query string.
|
||||||
|
|
||||||
First we transform the `form` into `FormData`, then we convert it into an `array` and from the `array` we collect an `query string`
|
First we transform the `form` into `FormData`, then we convert it into an `array` and from the `array` we collect an `query string`
|
||||||
|
|
||||||
@ -9,13 +9,6 @@ const serializeForm = form =>
|
|||||||
Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&')
|
Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&')
|
||||||
```
|
```
|
||||||
|
|
||||||
```html
|
|
||||||
<form id="form">
|
|
||||||
<input name="email" type="email" />
|
|
||||||
<input name="name" />
|
|
||||||
</form>
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
serializeForm(document.querySelector('#form')) // email=test%40email.com&name=Test%20Name
|
serializeForm(document.querySelector('#form')) // email=test%40email.com&name=Test%20Name
|
||||||
```
|
```
|
||||||
@ -90,7 +90,7 @@ flattenObject:object,recursion,intermediate
|
|||||||
flip:adapter,function,intermediate
|
flip:adapter,function,intermediate
|
||||||
forEachRight:array,function,intermediate
|
forEachRight:array,function,intermediate
|
||||||
formatDuration:date,math,string,utility,intermediate
|
formatDuration:date,math,string,utility,intermediate
|
||||||
formToObject:browser,utility,object
|
formToObject:browser,utility,object,beginner
|
||||||
forOwn:object,intermediate
|
forOwn:object,intermediate
|
||||||
forOwnRight:object,intermediate
|
forOwnRight:object,intermediate
|
||||||
fromCamelCase:string,intermediate
|
fromCamelCase:string,intermediate
|
||||||
@ -265,7 +265,7 @@ sampleSize:array,random,intermediate
|
|||||||
scrollToTop:browser,intermediate
|
scrollToTop:browser,intermediate
|
||||||
sdbm:math,utility,intermediate
|
sdbm:math,utility,intermediate
|
||||||
serializeCookie:utility,string,intermediate
|
serializeCookie:utility,string,intermediate
|
||||||
serializeForm:browser,beginner,utility,string
|
serializeForm:browser,utility,string,beginner
|
||||||
setStyle:browser,beginner
|
setStyle:browser,beginner
|
||||||
shallowClone:object,beginner
|
shallowClone:object,beginner
|
||||||
shank:array,intermediate
|
shank:array,intermediate
|
||||||
|
|||||||
10
test/_30s.js
10
test/_30s.js
@ -386,6 +386,12 @@ const forOwnRight = (obj, fn) =>
|
|||||||
Object.keys(obj)
|
Object.keys(obj)
|
||||||
.reverse()
|
.reverse()
|
||||||
.forEach(key => fn(obj[key], key, obj));
|
.forEach(key => fn(obj[key], key, obj));
|
||||||
|
const formToObject = form =>
|
||||||
|
Array.from(new FormData(form))
|
||||||
|
.reduce((acc, [key, value]) => ({
|
||||||
|
...acc,
|
||||||
|
[key]: value,
|
||||||
|
}), {})
|
||||||
const formatDuration = ms => {
|
const formatDuration = ms => {
|
||||||
if (ms < 0) ms = -ms;
|
if (ms < 0) ms = -ms;
|
||||||
const time = {
|
const time = {
|
||||||
@ -1046,6 +1052,8 @@ const sdbm = str => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
|
const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
|
||||||
|
const serializeForm = form =>
|
||||||
|
Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&')
|
||||||
const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
|
const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
|
||||||
const shallowClone = obj => Object.assign({}, obj);
|
const shallowClone = obj => Object.assign({}, obj);
|
||||||
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
||||||
@ -1520,4 +1528,4 @@ const speechSynthesis = message => {
|
|||||||
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
|
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
|
||||||
|
|
||||||
|
|
||||||
module.exports = {CSVToArray,CSVToJSON,JSONToFile,JSONtoCSV,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,all,allEqual,any,approximatelyEqual,arrayToCSV,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compactWhitespace,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,counter,createDirIfNotExists,createElement,createEventHub,currentURL,curry,dayOfYear,debounce,decapitalize,deepClone,deepFlatten,deepFreeze,deepMapKeys,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,dig,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementContains,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterFalsy,filterNonUnique,filterNonUniqueBy,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getImages,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,hz,inRange,indentString,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,initializeNDArray,insertAfter,insertBefore,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isAfterDate,isAnagram,isArrayLike,isBeforeDate,isBoolean,isBrowser,isBrowserTabFocused,isDivisible,isDuplexStream,isEmpty,isEven,isFunction,isLowerCase,isNegativeZero,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isReadableStream,isSameDate,isSorted,isStream,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,isWritableStream,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapNumRange,mapObject,mapString,mapValues,mask,matches,matchesWith,maxBy,maxDate,maxN,median,memoize,merge,midpoint,minBy,minDate,minN,mostPerformant,negate,nest,nodeListToArray,none,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,offset,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,pad,palindrome,parseCookie,partial,partialRight,partition,percentile,permutations,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prefix,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,recordAnimationFrames,redirect,reduceSuccessive,reduceWhich,reducedFilter,reject,remove,removeNonASCII,renameKeys,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,shank,show,shuffle,similarity,size,sleep,smoothScroll,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,stableSort,standardDeviation,stringPermutations,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toHash,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toTitleCase,toggleClass,tomorrow,transform,triggerEvent,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,uniqueElementsBy,uniqueElementsByRight,uniqueSymmetricDifference,untildify,unzip,unzipWith,validateNumber,vectorDistance,when,without,words,xProd,yesNo,zip,zipObject,zipWith,JSONToDate,binarySearch,celsiusToFahrenheit,cleanObj,collatz,countVowels,factors,fahrenheitToCelsius,fibonacciCountUntilNum,fibonacciUntilNum,heronArea,howManyTimes,httpDelete,httpPut,isArmstrongNumber,isSimilar,kmphToMph,levenshteinDistance,mphToKmph,pipeLog,quickSort,removeVowels,solveRPN,speechSynthesis,squareSum}
|
module.exports = {CSVToArray,CSVToJSON,JSONToFile,JSONtoCSV,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,all,allEqual,any,approximatelyEqual,arrayToCSV,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compactWhitespace,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,counter,createDirIfNotExists,createElement,createEventHub,currentURL,curry,dayOfYear,debounce,decapitalize,deepClone,deepFlatten,deepFreeze,deepMapKeys,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,dig,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementContains,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterFalsy,filterNonUnique,filterNonUniqueBy,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formToObject,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getImages,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,hz,inRange,indentString,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,initializeNDArray,insertAfter,insertBefore,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isAfterDate,isAnagram,isArrayLike,isBeforeDate,isBoolean,isBrowser,isBrowserTabFocused,isDivisible,isDuplexStream,isEmpty,isEven,isFunction,isLowerCase,isNegativeZero,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isReadableStream,isSameDate,isSorted,isStream,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,isWritableStream,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapNumRange,mapObject,mapString,mapValues,mask,matches,matchesWith,maxBy,maxDate,maxN,median,memoize,merge,midpoint,minBy,minDate,minN,mostPerformant,negate,nest,nodeListToArray,none,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,offset,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,pad,palindrome,parseCookie,partial,partialRight,partition,percentile,permutations,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prefix,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,recordAnimationFrames,redirect,reduceSuccessive,reduceWhich,reducedFilter,reject,remove,removeNonASCII,renameKeys,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,serializeForm,setStyle,shallowClone,shank,show,shuffle,similarity,size,sleep,smoothScroll,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,stableSort,standardDeviation,stringPermutations,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toHash,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toTitleCase,toggleClass,tomorrow,transform,triggerEvent,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,uniqueElementsBy,uniqueElementsByRight,uniqueSymmetricDifference,untildify,unzip,unzipWith,validateNumber,vectorDistance,when,without,words,xProd,yesNo,zip,zipObject,zipWith,JSONToDate,binarySearch,celsiusToFahrenheit,cleanObj,collatz,countVowels,factors,fahrenheitToCelsius,fibonacciCountUntilNum,fibonacciUntilNum,heronArea,howManyTimes,httpDelete,httpPut,isArmstrongNumber,isSimilar,kmphToMph,levenshteinDistance,mphToKmph,pipeLog,quickSort,removeVowels,solveRPN,speechSynthesis,squareSum}
|
||||||
18
test/formToObject.test.js
Normal file
18
test/formToObject.test.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const expect = require('expect');
|
||||||
|
const {formToObject} = require('./_30s.js');
|
||||||
|
|
||||||
|
test('formToObject is a Function', () => {
|
||||||
|
expect(formToObject).toBeInstanceOf(Function);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('formToObject correctly converts to object', () => {
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<form id="form">
|
||||||
|
<input name="name" value="Test Name" />
|
||||||
|
<input name="email" value="test@mail.com" />
|
||||||
|
</form>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const form = document.querySelector('#form');
|
||||||
|
expect(formToObject(form)).toEqual({ name: 'Test Name', email: 'test@mail.com' });
|
||||||
|
});
|
||||||
18
test/serializeForm.test.js
Normal file
18
test/serializeForm.test.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const expect = require('expect');
|
||||||
|
const {serializeForm} = require('./_30s.js');
|
||||||
|
|
||||||
|
test('serializeForm is a Function', () => {
|
||||||
|
expect(serializeForm).toBeInstanceOf(Function);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('serializeForm correctly converts to query string', () => {
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<form id="form">
|
||||||
|
<input name="name" value="Test Name" />
|
||||||
|
<input name="email" value="test@mail.com" />
|
||||||
|
</form>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const form = document.querySelector('#form');
|
||||||
|
expect(serializeForm(form)).toBe('name=Test%20Name&email=test%40mail.com');
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user