resolved a conflict.
This commit is contained in:
@ -6,6 +6,8 @@ Pass `location.search` as the argument to apply to the current `url`.
|
||||
|
||||
```js
|
||||
const getUrlParameters = url =>
|
||||
Object.assign(...url.match(/([^?=&]+)(=([^&]*))?/g).map(m => {[f,v] = m.split('='); return {[f]:v}}));
|
||||
url.match(/([^?=&]+)(=([^&]*))?/g).reduce(
|
||||
(a,v) => (a[v.slice(0,v.indexOf('='))] = v.slice(v.indexOf('=')), a), {}
|
||||
);
|
||||
// getUrlParameters('http://url.com/page?name=Adam&surname=Smith') -> {name: 'Adam', surname: 'Smith'}
|
||||
```
|
||||
|
||||
9
snippets/bottom-visible.md
Normal file
9
snippets/bottom-visible.md
Normal file
@ -0,0 +1,9 @@
|
||||
### Bottom visible
|
||||
|
||||
Use `scrollY`, `scrollHeight` and `clientHeight` to determine if the bottom of the page is visible.
|
||||
|
||||
```js
|
||||
const bottomVisible = _ =>
|
||||
document.documentElement.clientHeight + window.scrollY >= document.documentElement.scrollHeight || document.documentElement.clientHeight;
|
||||
// bottomVisible() -> true
|
||||
```
|
||||
17
snippets/promisify.md
Normal file
17
snippets/promisify.md
Normal file
@ -0,0 +1,17 @@
|
||||
### Promisify
|
||||
|
||||
Use currying to return a function returning a `Promise` that calls the original function.
|
||||
Use the `...rest` operator to pass in all the parameters.
|
||||
|
||||
*In Node 8+, you can use [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original)*
|
||||
|
||||
```js
|
||||
const promisify = func =>
|
||||
(...args) =>
|
||||
new Promise((resolve, reject) =>
|
||||
func(...args, (err, result) =>
|
||||
err ? reject(err) : resolve(result))
|
||||
);
|
||||
// const delay = promisify((d, cb) => setTimeout(cb, d))
|
||||
// delay(2000).then(() => console.log('Hi!')) -> Promise resolves after 2s
|
||||
```
|
||||
Reference in New Issue
Block a user