Travis build: 1289
This commit is contained in:
66
README.md
66
README.md
@ -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 
|
||||
|
||||
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
@ -6,17 +6,15 @@ Use the [SubtleCrypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCr
|
||||
|
||||
```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('');
|
||||
});
|
||||
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'
|
||||
hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
|
||||
```
|
||||
|
||||
@ -7,9 +7,20 @@ 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));
|
||||
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'
|
||||
hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user