@htmlacademy/serializer
v1.0.11
Published
## Как сериализовать объект
Downloads
4
Readme
serializer
Как сериализовать объект
В виде строки (без отступов)
var getSerializer = require('@htmlacademy/serializer/lib/serializer');
var getBaseEmitter = require('@htmlacademy/serializer/lib/base-emitter');
var serialize = getSerializer(getBaseEmitter());
var string = serialize({obj: {}, fn: () => {}, num: 42, bool: true});
// => "{obj: {}, fn: () => {...}, num: 42, bool: true}"
В виде строки (с отступами)
var getSerializer = require('@htmlacademy/serializer/lib/serializer');
var getIndentingEmitter = require('@htmlacademy/serializer/lib/indenting-emitter');
var serialize = getSerializer(getIndentingEmitter());
var string = serialize({obj: {}, fn: () => {}, num: 42, bool: true});
/* =>
`
{
obj: {
},
fn: () => {...},
num: 42,
bool: true
}
`
*/
В виде html-разметки
var getSerializer = require('@htmlacademy/serializer/lib/serializer');
var getHtmlEmitter = require('@htmlacademy/serializer/lib/html-emitter');
var serialize = getSerializer(getHtmlEmitter());
var string = serialize({obj: {}, fn: () => {}, num: 42, bool: true});
/* =>
`
<span class="symbol">{</span>
obj<span class="symbol">:</span> <span class="symbol">{</span>
<span class="symbol">}</span><span class="symbol">,</span>
fn<span class="symbol">:</span> <span class="function">() => {...}</span><span class="symbol">,</span>
num<span class="symbol">:</span> <span class="number">42</span><span class="symbol">,</span>
bool<span class="symbol">:</span> <span class="boolean">true</span>
<span class="symbol">}</span>
`
*/