diff --git a/README.md b/README.md index b2a9fece..f8005800 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ domJSON ======= -[![License](https://img.shields.io/cocoapods/l/AFNetworking.svg)](https://github.com/azaslavsky/domJSON#license) [![Bower version](https://badge.fury.io/bo/domjson.svg)](http://badge.fury.io/bo/domjson) [![npm version](https://badge.fury.io/js/domjson.svg)](http://badge.fury.io/js/domjson) [![Coverage Status](https://img.shields.io/coveralls/azaslavsky/domJSON.svg)](https://coveralls.io/r/azaslavsky/domJSON?branch=master) [![Dependencies](https://david-dm.org/azaslavsky/domJSON/dev-status.svg)](https://david-dm.org/azaslavsky/domJSON#info=devDependencies&view=table) [![Travis Build](https://api.travis-ci.org/azaslavsky/domJSON.svg)](https://travis-ci.org/azaslavsky/domJSON) +[![License](https://img.shields.io/cocoapods/l/AFNetworking.svg)](https://github.com/azaslavsky/domJSON#license) [![Bower version](https://badge.fury.io/bo/domjson.svg)](http://badge.fury.io/bo/domjson) [![npm version](https://badge.fury.io/js/domjson.svg)](http://badge.fury.io/js/domjson) [![Coverage Status](https://img.shields.io/coveralls/azaslavsky/domJSON.svg)](https://coveralls.io/r/azaslavsky/domJSON?branch=master) [![Dependencies](https://david-dm.org/azaslavsky/domJSON/dev-status.svg)](https://david-dm.org/azaslavsky/domJSON#info=devDependencies&view=table) [![Travis Build](https://api.travis-ci.org/azaslavsky/domJSON.svg)](https://travis-ci.org/azaslavsky/domJSON) Convert DOM trees into compact JSON objects, and vice versa, as fast as possible. @@ -64,8 +64,8 @@ Coming soon... Using domJSON is super simple: use the [`.toJSON()`](#domJSON.toJSON) method to create a JSON representation of the DOM tree: ```javascript -var someDOMElement = document.getElementById('sampleId'); -var jsonOutput = domJSON.toJSON(myDiv); +let someDOMElement = document.getElementById('sampleId'); +let jsonOutput = domJSON.toJSON(someDOMElement); ``` And then rebuild the DOM Node from that JSON using [`.toDOM()`](#domJSON.toDOM): @@ -221,6 +221,21 @@ domJSON is a global variable to store two methods: `.toJSON()` to convert a DOM #### domJSON.toJSON(node, [opts]) ⇒ Object | string Take a DOM node and convert it to simple object literal (or JSON string) with no circular references and no functions or events +| Param | Type | Description | +| -------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| node | Node | The actual DOM Node which will be the starting point for parsing the DOM Tree | +| \[opts\] | Object | A list of all method options | +| \[opts.absolutePaths=`'action', 'data', 'href', 'src'`\] | boolean \| [FilterList](#FilterList) | Only relevant if `opts.attributes` is not `false`; use `true` to convert all relative paths found in attribute values to absolute paths, or specify a `FilterList` of keys to boolean search | +| \[opts.attributes=`true`\] | boolean \| [FilterList](#FilterList) | Use `true` to copy all attribute key-value pairs, or specify a `FilterList` of keys to boolean search | +| \[opts.computedStyle=`false`\] | boolean \| [FilterList](#FilterList) | Use `true` to parse the results of "window.getComputedStyle()" on every node (specify a `FilterList` of CSS properties to be included via boolean search); this operation is VERY costly performance-wise! | +| \[opts.cull=`false`\] | boolean | Use `true` to ignore empty element properties | +| \[opts.deep=`true`\] | boolean \| number | Use `true` to iterate and copy all childNodes, or an INTEGER indicating how many levels down the DOM tree to iterate | +| \[opts.domProperties=true\] | boolean \| [FilterList](#FilterList) | 'false' means only 'tagName', 'nodeType', and 'nodeValue' properties will be copied, while a `FilterList` can specify DOM properties to include or exclude in the output (except for ones which serialize the DOM Node, which are handled separately by `opts.serialProperties`) | +| \[opts.htmlOnly=`false`\] | boolean | Use `true` to only iterate through childNodes where nodeType = 1 (aka, instances of HTMLElement); irrelevant if `opts.deep` is `true` | +| \[opts.metadata=`false`\] | boolean | Output a special object of the domJSON class, which includes metadata about this operation | +| \[opts.serialProperties=`true`\] | boolean \| [FilterList](#FilterList) | Use `true` to ignore the properties that store a serialized version of this DOM Node (ex: outerHTML, innerText, etc), or specify a `FilterList` of serial properties (no boolean search!) | +| \[opts.stringify=`false`\] | boolean | Output a JSON string, or just a JSON-ready javascript object? | + **Kind**: static method of [domJSON](#domJSON) **Returns**: Object | string - A JSON-friendly object, or JSON string, of the DOM node -> JSON conversion output **Todo** @@ -251,6 +266,12 @@ Take a DOM node and convert it to simple object literal (or JSON string) with no #### domJSON.toDOM(obj, [opts]) ⇒ DocumentFragment Take the JSON-friendly object created by the `.toJSON()` method and rebuild it back into a DOM Node +| Param | Type | Description | +| ----------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------- | +| obj | Object | A JSON friendly object, or even JSON string, of some DOM Node | +| \[opts\] | Object | A list of all method options | +| \[opts.noMeta=`false`\] | boolean | `true` means that this object is not wrapped in metadata, which it makes it somewhat more difficult to rebuild properly... | + **Kind**: static method of [domJSON](#domJSON) **Returns**: DocumentFragment - A `DocumentFragment` (nodeType 11) containing the result of unpacking the input `obj`