From 540e9b1f3e6431d5d7af409a1dd7dc652bb35bd5 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Mon, 1 Jan 2018 12:23:02 +0000 Subject: [PATCH] Travis build: 763 [ci skip] --- README.md | 54 ++++++++++++++++++++++++------------------------- docs/index.html | 12 +++++------ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 233609b8e..ea9e3def8 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,6 @@ * [`elementIsVisibleInViewport`](#elementisvisibleinviewport) * [`getScrollPosition`](#getscrollposition) * [`getStyle`](#getstyle) -* [`getURLParameters`](#geturlparameters) * [`hasClass`](#hasclass) * [`hide`](#hide) * [`httpsRedirect`](#httpsredirect) @@ -244,6 +243,7 @@ * [`coalesceFactory`](#coalescefactory) * [`extendHex`](#extendhex) * [`getType`](#gettype) +* [`getURLParameters`](#geturlparameters) * [`hexToRGB`](#hextorgb) * [`isArray`](#isarray) * [`isArrayLike`](#isarraylike) @@ -1707,32 +1707,6 @@ getStyle(document.querySelector('p'), 'font-size'); // '16px'
[⬆ Back to top](#table-of-contents) -### getURLParameters - -Returns an object containing the parameters of the current URL. - -Use `match()` with an appropriate regular expression to get all key-value pairs, `Array.reduce()` to map and combine them into a single object. -Pass `location.search` as the argument to apply to the current `url`. - -```js -const getURLParameters = url => - url - .match(/([^?=&]+)(=([^&]*))/g) - .reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {}); -``` - -
-Examples - -```js -getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'} -``` - -
- -
[⬆ Back to top](#table-of-contents) - - ### hasClass Returns `true` if the element has the specified class, `false` otherwise. @@ -4052,6 +4026,32 @@ getType(new Set([1, 2, 3])); // "set"
[⬆ Back to top](#table-of-contents) +### getURLParameters + +Returns an object containing the parameters of the current URL. + +Use `match()` with an appropriate regular expression to get all key-value pairs, `Array.reduce()` to map and combine them into a single object. +Pass `location.search` as the argument to apply to the current `url`. + +```js +const getURLParameters = url => + url + .match(/([^?=&]+)(=([^&]*))/g) + .reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {}); +``` + +
+Examples + +```js +getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'} +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### hexToRGB Converts a color code to a `rgb()` or `rgba()` string if alpha value is provided. diff --git a/docs/index.html b/docs/index.html index a82583589..8e1ea7362 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,7 +59,7 @@ wrapper.appendChild(box); box.appendChild(el); }); - }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+    }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -341,11 +341,6 @@ elementIsVisibleInViewport(el, true); // true // (partially visible)
 
getScrollPosition(); // {x: 0, y: 200}
 

getStyle

Returns the value of a CSS rule for the specified element.

Use Window.getComputedStyle() to get the value of the CSS rule for the specified element.

const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];
 
getStyle(document.querySelector('p'), 'font-size'); // '16px'
-

getURLParameters

Returns an object containing the parameters of the current URL.

Use match() with an appropriate regular expression to get all key-value pairs, Array.reduce() to map and combine them into a single object. Pass location.search as the argument to apply to the current url.

const getURLParameters = url =>
-  url
-    .match(/([^?=&]+)(=([^&]*))/g)
-    .reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
-
getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}
 

hasClass

Returns true if the element has the specified class, false otherwise.

Use element.classList.contains() to check if the element has the specified class.

const hasClass = (el, className) => el.classList.contains(className);
 
hasClass(document.querySelector('p.special'), 'special'); // true
 

hide

Hides all the elements specified.

Use the spread operator (...) and Array.forEach() to apply display: none to each element specified.

const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
@@ -835,6 +830,11 @@ extendHex('05a'); // '#0055aa'
 

getType

Returns the native type of a value.

Returns lowercased constructor name of value, "undefined" or "null" if value is undefined or null

const getType = v =>
   v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
 
getType(new Set([1, 2, 3])); // "set"
+

getURLParameters

Returns an object containing the parameters of the current URL.

Use match() with an appropriate regular expression to get all key-value pairs, Array.reduce() to map and combine them into a single object. Pass location.search as the argument to apply to the current url.

const getURLParameters = url =>
+  url
+    .match(/([^?=&]+)(=([^&]*))/g)
+    .reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a), {});
+
getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}
 

hexToRGB

Converts a color code to a rgb() or rgba() string if alpha value is provided.

Use bitwise right-shift operator and mask bits with & (and) operator to convert a hexadecimal color code (with or without prefixed with #) to a string with the RGB values. If it's 3-digit color code, first convert to 6-digit version. If an alpha value is provided alongside 6-digit hex, give rgba() string in return.

const hexToRGB = hex => {
   let alpha = false,
     h = hex.slice(hex.startsWith('#') ? 1 : 0);