Skip to content

Commit 80f355b

Browse files
committed
README.md: assign
1 parent 6b806cc commit 80f355b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ package.json:
5454
```js
5555
const {
5656
parse,
57-
stringify
57+
stringify,
58+
assign
5859
} = require('comment-json')
5960
const fs = require('fs')
6061

@@ -311,6 +312,32 @@ console.log(stringify(result)) // {"a":1}
311312
console.log(stringify(result, null, 2)) // is the same as `code`
312313
```
313314
315+
## assign(target: object, source?: object, keys?: Array<string>)
316+
317+
- **target** `object` the target object
318+
- **source?** `object` the source object. This parameter is optional but it is silly to not pass this argument.
319+
- **keys?** `Array<string>` If not specified, all enumerable own properties of `source` will be used.
320+
321+
This method is used to copy the enumerable own properties and their corresponding comment symbol properties to the target object.
322+
323+
```js
324+
const parsed = parse(`{
325+
// This is a comment
326+
"foo": "bar"
327+
}`)
328+
329+
const obj = assign({
330+
bar: 'baz'
331+
}, parsed)
332+
333+
stringify(obj, null, 2)
334+
// {
335+
// "bar": "baz",
336+
// // This is a comment
337+
// "foo": "bar"
338+
// }
339+
```
340+
314341
## License
315342
316343
[MIT](LICENSE)

0 commit comments

Comments
 (0)