Travis build: 802 [ci skip]
This commit is contained in:
103
README.md
103
README.md
@ -187,8 +187,11 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
|
|
||||||
|
* [`hasFlags`](#hasflags)
|
||||||
|
* [`isTravisCI`](#istravisci)
|
||||||
* [`JSONToFile`](#jsontofile)
|
* [`JSONToFile`](#jsontofile)
|
||||||
* [`readFileLines`](#readfilelines)
|
* [`readFileLines`](#readfilelines)
|
||||||
|
* [`untildify`](#untildify)
|
||||||
* [`UUIDGeneratorNode`](#uuidgeneratornode)
|
* [`UUIDGeneratorNode`](#uuidgeneratornode)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
@ -199,6 +202,7 @@
|
|||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
|
|
||||||
* [`cleanObj`](#cleanobj)
|
* [`cleanObj`](#cleanobj)
|
||||||
|
* [`invertKeyValues`](#invertkeyvalues)
|
||||||
* [`lowercaseKeys`](#lowercasekeys)
|
* [`lowercaseKeys`](#lowercasekeys)
|
||||||
* [`objectFromPairs`](#objectfrompairs)
|
* [`objectFromPairs`](#objectfrompairs)
|
||||||
* [`objectToPairs`](#objecttopairs)
|
* [`objectToPairs`](#objecttopairs)
|
||||||
@ -3171,6 +3175,57 @@ sumPower(10, 3, 5); //2925
|
|||||||
---
|
---
|
||||||
## 📦 Node
|
## 📦 Node
|
||||||
|
|
||||||
|
### hasFlags
|
||||||
|
|
||||||
|
Check if the current process's arguments contain the specified flags.
|
||||||
|
|
||||||
|
Use `Array.every()` and `Array.includes()` to check if `process.argv` contains all the specified flags.
|
||||||
|
Use a regular expression to test if the specified flags are prefixed with `-` or `--` and prefix them accordingly.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const hasFlags = (...flags) =>
|
||||||
|
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
// node myScript.js -s --test --cool=true
|
||||||
|
hasFlags('-s'); // true
|
||||||
|
hasFlags('test', 'cool=true'); // true
|
||||||
|
hasFlags('--test', 'cool=true', '-s'); // true
|
||||||
|
hasFlags('special'); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### isTravisCI
|
||||||
|
|
||||||
|
Checks if the current environment is [Travis CI](https://travis-ci.org/).
|
||||||
|
|
||||||
|
Checks if the current environment has the `TRAVIS` and `CI` environment variables ([reference](https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)).
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
const isTravisCI = ()) => 'TRAVIS' in process.env && 'CI' in process.env;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
isTravisCI(); // true (if code is running on Travis CI)
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### JSONToFile
|
### JSONToFile
|
||||||
|
|
||||||
Writes a JSON object to a file.
|
Writes a JSON object to a file.
|
||||||
@ -3233,6 +3288,28 @@ console.log(arr); // ['line1', 'line2', 'line3']
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### untildify
|
||||||
|
|
||||||
|
Converts a tilde path to an absolute path.
|
||||||
|
|
||||||
|
Use `String.replace()` with a regular expression and `OS.homedir()` to replace the `~` in the start of the path with the home directory.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$1`);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
untildify('~/node'); // '/Users/aUser/node'
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### UUIDGeneratorNode
|
### UUIDGeneratorNode
|
||||||
|
|
||||||
Generates a UUID in Node.JS.
|
Generates a UUID in Node.JS.
|
||||||
@ -3294,6 +3371,32 @@ cleanObj(testObj, ['a'], 'children'); // { a: 1, children : { a: 1}}
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### invertKeyValues
|
||||||
|
|
||||||
|
Inverts the key-value pairs of an object, without mutating it.
|
||||||
|
|
||||||
|
Use `Object.keys()` and `Array.reduce()` to invert the key-value pairs of an object.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const invertKeyValues = obj =>
|
||||||
|
Object.keys(obj).reduce((acc, key) => {
|
||||||
|
acc[obj[key]] = key;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
invertKeyValues({ name: 'John', age: 20 }); // { 20: 'age', John: 'name' }
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### lowercaseKeys
|
### lowercaseKeys
|
||||||
|
|
||||||
Creates a new object from the specified object, where all the keys are in lowercase.
|
Creates a new object from the specified object, where all the keys are in lowercase.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -7,9 +7,7 @@ Use a regular expression to test if the specified flags are prefixed with `-` or
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const hasFlags = (...flags) =>
|
const hasFlags = (...flags) =>
|
||||||
flags.every(flag => process.argv.includes(
|
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
|
||||||
/^-{1,2}/.test(flag) ? flag : '--' + flag
|
|
||||||
));
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -5,9 +5,13 @@ Inverts the key-value pairs of an object, without mutating it.
|
|||||||
Use `Object.keys()` and `Array.reduce()` to invert the key-value pairs of an object.
|
Use `Object.keys()` and `Array.reduce()` to invert the key-value pairs of an object.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const invertKeyValues = obj => Object.keys(obj).reduce((acc,key) => { acc[obj[key]] = key; return acc;},{});
|
const invertKeyValues = obj =>
|
||||||
|
Object.keys(obj).reduce((acc, key) => {
|
||||||
|
acc[obj[key]] = key;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
invertKeyValues({name:'John', age: 20}) // { 20: 'age', John: 'name' }
|
invertKeyValues({ name: 'John', age: 20 }); // { 20: 'age', John: 'name' }
|
||||||
```
|
```
|
||||||
|
|||||||
@ -5,6 +5,7 @@ Checks if the current environment is [Travis CI](https://travis-ci.org/).
|
|||||||
Checks if the current environment has the `TRAVIS` and `CI` environment variables ([reference](https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)).
|
Checks if the current environment has the `TRAVIS` and `CI` environment variables ([reference](https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
const isTravisCI = ()) => 'TRAVIS' in process.env && 'CI' in process.env;
|
const isTravisCI = ()) => 'TRAVIS' in process.env && 'CI' in process.env;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -9,5 +9,5 @@ const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
untildify('~/node') // '/Users/aUser/node'
|
untildify('~/node'); // '/Users/aUser/node'
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user