Merge branch 'master' into tdd-update

This commit is contained in:
King David Martins
2018-01-17 14:28:32 -05:00
committed by GitHub
5 changed files with 139 additions and 1 deletions

View File

@ -162,6 +162,7 @@ average(1, 2, 3);
* [`getScrollPosition`](#getscrollposition)
* [`getStyle`](#getstyle)
* [`hasClass`](#hasclass)
* [`hashBrowser`](#hashbrowser-)
* [`hide`](#hide)
* [`httpsRedirect`](#httpsredirect)
* [`observeMutations`](#observemutations-)
@ -255,6 +256,7 @@ average(1, 2, 3);
* [`colorize`](#colorize)
* [`hasFlags`](#hasflags)
* [`hashNode`](#hashnode)
* [`isTravisCI`](#istravisci)
* [`JSONToFile`](#jsontofile)
* [`readFileLines`](#readfilelines)
@ -2223,6 +2225,35 @@ hasClass(document.querySelector('p.special'), 'special'); // true
<br>[⬆ Back to top](#table-of-contents)
### hashBrowser ![advanced](/advanced.svg)
Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.
Use the [SubtleCrypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) API to create a hash for the given value.
```js
const hashBrowser = val =>
crypto.subtle.digest('SHA-256', new TextEncoder('utf-8').encode(val)).then(h => {
let hexes = [],
view = new DataView(h);
for (let i = 0; i < view.byteLength; i += 4)
hexes.push(('00000000' + view.getUint32(i).toString(16)).slice(-8));
return hexes.join('');
});
```
<details>
<summary>Examples</summary>
```js
hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### hide
Hides all the elements specified.
@ -3915,6 +3946,41 @@ hasFlags('special'); // false
<br>[⬆ Back to top](#table-of-contents)
### hashNode
Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.
Use `crypto` API to create a hash for the given value.
```js
const crypto = require('crypto');
const hashNode = val =>
new Promise(resolve =>
setTimeout(
() =>
resolve(
crypto
.createHash('sha256')
.update(val)
.digest('hex')
),
0
)
);
```
<details>
<summary>Examples</summary>
```js
hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### isTravisCI
Checks if the current environment is [Travis CI](https://travis-ci.org/).

File diff suppressed because one or more lines are too long

20
snippets/hashBrowser.md Normal file
View File

@ -0,0 +1,20 @@
### hashBrowser
Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.
Use the [SubtleCrypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) API to create a hash for the given value.
```js
const hashBrowser = val =>
crypto.subtle.digest('SHA-256', new TextEncoder('utf-8').encode(val)).then(h => {
let hexes = [],
view = new DataView(h);
for (let i = 0; i < view.byteLength; i += 4)
hexes.push(('00000000' + view.getUint32(i).toString(16)).slice(-8));
return hexes.join('');
});
```
```js
hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
```

26
snippets/hashNode.md Normal file
View File

@ -0,0 +1,26 @@
### hashNode
Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.
Use `crypto` API to create a hash for the given value.
```js
const crypto = require('crypto');
const hashNode = val =>
new Promise(resolve =>
setTimeout(
() =>
resolve(
crypto
.createHash('sha256')
.update(val)
.digest('hex')
),
0
)
);
```
```js
hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
```

View File

@ -64,6 +64,8 @@ groupBy:array,object
hammingDistance:math
hasClass:browser,css
hasFlags:node
hashBrowser:browser,utility,advanced
hashNode:node,utility
head:array
hexToRGB:utility,string,math,advanced
hide:browser,css