Update shallow clone, tag, build

This commit is contained in:
Angelos Chalaris
2017-12-15 13:33:46 +02:00
parent 042260823b
commit 25984a700e
3 changed files with 21 additions and 4 deletions

View File

@ -83,6 +83,9 @@
### Media ### Media
* [Speech synthesis (experimental)](#speech-synthesis-experimental) * [Speech synthesis (experimental)](#speech-synthesis-experimental)
### Node
* [Write json to file](#write-json-to-file)
### Object ### Object
* [Object from key value pairs](#object-from-key-value-pairs) * [Object from key value pairs](#object-from-key-value-pairs)
* [Object to key value pairs](#object-to-key-value-pairs) * [Object to key value pairs](#object-to-key-value-pairs)
@ -943,6 +946,19 @@ const speak = message => {
// speak('Hello, World') -> plays the message // speak('Hello, World') -> plays the message
``` ```
[⬆ back to top](#table-of-contents)
## Node
### Write a JSON to a file
Use `fs.writeFile()`, template literals and `JSON.stringify()` to write a `json` object to a `.json` file.
```js
const fs = require('fs');
const jsonToFile = (obj, filename) => fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2))
// jsonToFile({test: "is passed"}, 'testJsonFile') -> writes the object to 'testJsonFile.json'
```
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
## Object ## Object
@ -970,10 +986,10 @@ const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
### Shallow clone object ### Shallow clone object
Use the object `...spread` operator to spread the properties of the target object into the clone. Use `Object.assign()` and an empty object (`{}`) to create a shallo clone of the original.
```js ```js
const shallowClone = obj => ({ ...obj }); const shallowClone = obj => Object.assign({}, obj);
/* /*
const a = { x: true, y: 1 }; const a = { x: true, y: 1 };
const b = shallowClone(a); const b = shallowClone(a);

View File

@ -1,9 +1,9 @@
### Shallow clone object ### Shallow clone object
Use the object `...spread` operator to spread the properties of the target object into the clone. Use `Object.assign()` and an empty object (`{}`) to create a shallo clone of the original.
```js ```js
const shallowClone = obj => ({ ...obj }); const shallowClone = obj => Object.assign({}, obj);
/* /*
const a = { x: true, y: 1 }; const a = { x: true, y: 1 };
const b = shallowClone(a); const b = shallowClone(a);

View File

@ -90,3 +90,4 @@ UUID-generator:utility
validate-email:utility validate-email:utility
validate-number:utility validate-number:utility
value-or-default:utility value-or-default:utility
write-json-to-file:node