Travis build: 802 [ci skip]

This commit is contained in:
Travis CI
2018-01-01 16:45:34 +00:00
parent 6293796ef2
commit e3f75a55e9
6 changed files with 132 additions and 8 deletions

103
README.md
View File

@ -187,8 +187,11 @@
<details>
<summary>View contents</summary>
* [`hasFlags`](#hasflags)
* [`isTravisCI`](#istravisci)
* [`JSONToFile`](#jsontofile)
* [`readFileLines`](#readfilelines)
* [`untildify`](#untildify)
* [`UUIDGeneratorNode`](#uuidgeneratornode)
</details>
@ -199,6 +202,7 @@
<summary>View contents</summary>
* [`cleanObj`](#cleanobj)
* [`invertKeyValues`](#invertkeyvalues)
* [`lowercaseKeys`](#lowercasekeys)
* [`objectFromPairs`](#objectfrompairs)
* [`objectToPairs`](#objecttopairs)
@ -3171,6 +3175,57 @@ sumPower(10, 3, 5); //2925
---
## 📦 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
Writes a JSON object to a file.
@ -3233,6 +3288,28 @@ console.log(arr); // ['line1', 'line2', 'line3']
<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
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)
### 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
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

View File

@ -7,9 +7,7 @@ Use a regular expression to test if the specified flags are prefixed with `-` or
```js
const hasFlags = (...flags) =>
flags.every(flag => process.argv.includes(
/^-{1,2}/.test(flag) ? flag : '--' + flag
));
flags.every(flag => process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag));
```
```js

View File

@ -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.
```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
invertKeyValues({name:'John', age: 20}) // { 20: 'age', John: 'name' }
invertKeyValues({ name: 'John', age: 20 }); // { 20: 'age', John: 'name' }
```

View File

@ -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)).
```js
const isTravisCI = ()) => 'TRAVIS' in process.env && 'CI' in process.env;
```

View File

@ -9,5 +9,5 @@ const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$
```
```js
untildify('~/node') // '/Users/aUser/node'
untildify('~/node'); // '/Users/aUser/node'
```