Travis build: 1100

This commit is contained in:
30secondsofcode
2019-04-08 05:41:51 +00:00
parent 1654380bb5
commit 27b26630ab
22 changed files with 122 additions and 36 deletions

View File

@ -207,6 +207,7 @@ _30s.average(1, 2, 3);
* [`detectDeviceType`](#detectdevicetype)
* [`elementContains`](#elementcontains)
* [`elementIsVisibleInViewport`](#elementisvisibleinviewport-)
* [`formToObject`](#formtoobject)
* [`getImages`](#getimages)
* [`getScrollPosition`](#getscrollposition)
* [`getStyle`](#getstyle)
@ -227,6 +228,7 @@ _30s.average(1, 2, 3);
* [`redirect`](#redirect)
* [`runAsync`](#runasync-)
* [`scrollToTop`](#scrolltotop)
* [`serializeForm`](#serializeform)
* [`setStyle`](#setstyle)
* [`show`](#show)
* [`smoothScroll`](#smoothscroll)
@ -677,7 +679,7 @@ const sum = pipeAsyncFunctions(
x => x + 3,
async x => (await x) + 4
);
(async () => {
(async() => {
console.log(await sum(5)); // 15 (after one second)
})();
```
@ -2325,9 +2327,9 @@ The `func` is invoked with three arguments (`value, index, array`).
const remove = (arr, func) =>
Array.isArray(arr)
? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
: [];
```
@ -3541,6 +3543,35 @@ elementIsVisibleInViewport(el, true); // true - (partially visible)
<br>[⬆ Back to top](#contents)
### formToObject
Encode a set of form elements as an `object`.
Use the `FormData` constructor to convert the HTML `form` to `FormData`, `Array.from()` to convert to an array.
Collect the object from the array, using `Array.prototype.reduce()`.
```js
const formToObject = form =>
Array.from(new FormData(form)).reduce(
(acc, [key, value]) => ({
...acc,
[key]: value
}),
{}
);
```
<details>
<summary>Examples</summary>
```js
formToObject(document.querySelector('#form')); // { email: 'test@email.com', name: 'Test Name' }
```
</details>
<br>[⬆ Back to top](#contents)
### getImages
Fetches all images from within an element and puts them into an array
@ -4101,6 +4132,30 @@ scrollToTop();
<br>[⬆ Back to top](#contents)
### serializeForm
Encode a set of form elements as a query string.
Use the `FormData` constructor to convert the HTML `form` to `FormData`, `Array.from()` to convert to an array, passing a map function as the second argument.
Use `Array.prototype.map()` and `window.encodeURIComponent()` to encode each field's value.
Use `Array.prototype.join()` with appropriate argumens to produce an appropriate query string.
```js
const serializeForm = form =>
Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&');
```
<details>
<summary>Examples</summary>
```js
serializeForm(document.querySelector('#form')); // email=test%40email.com&name=Test%20Name
```
</details>
<br>[⬆ Back to top](#contents)
### setStyle
Sets the value of a CSS rule for the specified element.
@ -4673,6 +4728,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]); // false
lengthIs4([1,2,3,4]); // true

View File

@ -250,6 +250,7 @@
<li><a tags="browser,intermediate" href="./browser#detectdevicetype">detectDeviceType</a></li>
<li><a tags="browser,intermediate" href="./browser#elementcontains">elementContains</a></li>
<li><a tags="browser,advanced" href="./browser#elementisvisibleinviewport">elementIsVisibleInViewport</a></li>
<li><a tags="browser,object,intermediate" href="./browser#formtoobject">formToObject</a></li>
<li><a tags="browser,beginner" href="./browser#getimages">getImages</a></li>
<li><a tags="browser,intermediate" href="./browser#getscrollposition">getScrollPosition</a></li>
<li><a tags="browser,css,beginner" href="./browser#getstyle">getStyle</a></li>
@ -270,6 +271,7 @@
<li><a tags="browser,url,beginner" href="./browser#redirect">redirect</a></li>
<li><a tags="browser,function,advanced,promise,url" href="./browser#runasync">runAsync</a></li>
<li><a tags="browser,intermediate" href="./browser#scrolltotop">scrollToTop</a></li>
<li><a tags="browser,string,intermediate" href="./browser#serializeform">serializeForm</a></li>
<li><a tags="browser,beginner" href="./browser#setstyle">setStyle</a></li>
<li><a tags="browser,css,beginner" href="./browser#show">show</a></li>
<li><a tags="browser,css,intermediate" href="./browser#smoothscroll">smoothScroll</a></li>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -250,6 +250,7 @@
<li><a tags="browser,intermediate" href="./browser#detectdevicetype">detectDeviceType</a></li>
<li><a tags="browser,intermediate" href="./browser#elementcontains">elementContains</a></li>
<li><a tags="browser,advanced" href="./browser#elementisvisibleinviewport">elementIsVisibleInViewport</a></li>
<li><a tags="browser,object,intermediate" href="./browser#formtoobject">formToObject</a></li>
<li><a tags="browser,beginner" href="./browser#getimages">getImages</a></li>
<li><a tags="browser,intermediate" href="./browser#getscrollposition">getScrollPosition</a></li>
<li><a tags="browser,css,beginner" href="./browser#getstyle">getStyle</a></li>
@ -270,6 +271,7 @@
<li><a tags="browser,url,beginner" href="./browser#redirect">redirect</a></li>
<li><a tags="browser,function,advanced,promise,url" href="./browser#runasync">runAsync</a></li>
<li><a tags="browser,intermediate" href="./browser#scrolltotop">scrollToTop</a></li>
<li><a tags="browser,string,intermediate" href="./browser#serializeform">serializeForm</a></li>
<li><a tags="browser,beginner" href="./browser#setstyle">setStyle</a></li>
<li><a tags="browser,css,beginner" href="./browser#show">show</a></li>
<li><a tags="browser,css,intermediate" href="./browser#smoothscroll">smoothScroll</a></li>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]); // false
lengthIs4([1,2,3,4]); // true

View File

@ -7,13 +7,15 @@ Collect the object from the array, using `Array.prototype.reduce()`.
```js
const formToObject = form =>
Array.from(new FormData(form))
.reduce((acc, [key, value]) => ({
Array.from(new FormData(form)).reduce(
(acc, [key, value]) => ({
...acc,
[key]: value,
}), {})
[key]: value
}),
{}
);
```
```js
formToObject(document.querySelector('#form')) // { email: 'test@email.com', name: 'Test Name' }
formToObject(document.querySelector('#form')); // { email: 'test@email.com', name: 'Test Name' }
```

View File

@ -17,7 +17,7 @@ const sum = pipeAsyncFunctions(
x => x + 3,
async x => (await x) + 4
);
(async () => {
(async() => {
console.log(await sum(5)); // 15 (after one second)
})();
```

View File

@ -9,9 +9,9 @@ The `func` is invoked with three arguments (`value, index, array`).
const remove = (arr, func) =>
Array.isArray(arr)
? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
: [];
```

View File

@ -8,9 +8,9 @@ Use `Array.prototype.join()` with appropriate argumens to produce an appropriate
```js
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('&');
```
```js
serializeForm(document.querySelector('#form')) // email=test%40email.com&name=Test%20Name
serializeForm(document.querySelector('#form')); // email=test%40email.com&name=Test%20Name
```

View File

@ -389,6 +389,14 @@ const forOwnRight = (obj, fn) =>
Object.keys(obj)
.reverse()
.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 => {
if (ms < 0) ms = -ms;
const time = {
@ -993,9 +1001,9 @@ const reject = (pred, array) => array.filter((...args) => !pred(...args));
const remove = (arr, func) =>
Array.isArray(arr)
? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
arr.splice(arr.indexOf(val), 1);
return acc.concat(val);
}, [])
: [];
const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, '');
const renameKeys = (keysMap, obj) =>
@ -1049,6 +1057,8 @@ const sdbm = str => {
);
};
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 shallowClone = obj => Object.assign({}, obj);
const shank = (arr, index = 0, delCount = 0, ...elements) =>
@ -1523,4 +1533,4 @@ const speechSynthesis = message => {
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,checkProp,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,checkProp,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}