js-sion
v1.2.0
Published
SION deserializer/serializer for ECMAScript
Downloads
8
Readme
js-sion
SION deserializer/serializer for ECMAScript
Synopsis
import {SION} from './sion.js';
//...
let obj = SION.parse('["formats":["JSON","SION"]]');
let str = SION.stringify({formats: ["JSON", "SION"]});
//...
Usage
sion.js has no dependency so you can simply put it anywhere handy. It is a ES6 module so you need a faily modern environments.
on browsers
In your JS script:
import {SION} from './sion.js'; // or wherever you put it
Or in your HTML:
<script type="module">
import {SION} from './sion.js';
</script>
You can even directly import
from CDN:
<script type="module">
import {SION} from 'https://cdn.jsdelivr.net/npm/[email protected]/sion.min.js';
</script>
Tree-shaken import is also supported.
import {stringify, parse} from './sion.js';
Besides SION
, the trunk, the follow symbols are exported:
RE_HEXFLOAT
: aRegExp
that matches hexadecimal floating-point number.RE_HEXFLOAT_G
: same asRE_HEXFLOAT
with a 'g' flag.parseHexFloat
: parses hexadecimal floating point.toHexString
: prints number in hexadecimal floating point format.stringify
: cf.JSON.stringify
. stringifies a JS object to a SION string.parse
: cf.JSON.parse
. parses SION string to a JS object.version
: The version of module.
on node.js
Use node 16 or later that support native esm. You can also use use standard-things/esm.
$ npm install esm js-sion
$ node
> const SION = await import('js-sion');
undefined
> SION
[Module: null prototype] {
RE_HEXFLOAT: /([+-]?)0x([0-9A-F]+).?([0-9A-F]*)p([+-]?[0-9]+)/i,
RE_HEXFLOAT_G: /([+-]?)0x([0-9A-F]+).?([0-9A-F]*)p([+-]?[0-9]+)/gi,
SION: {
version: '1.2.0',
RE_HEXFLOAT: /([+-]?)0x([0-9A-F]+).?([0-9A-F]*)p([+-]?[0-9]+)/i,
RE_HEXFLOAT_G: /([+-]?)0x([0-9A-F]+).?([0-9A-F]*)p([+-]?[0-9]+)/gi,
parseHexFloat: [Function: parseHexFloat],
toHexString: [Function: toHexString],
stringify: [Function: stringify],
parse: [Function: parse]
},
parse: [Function: parse],
parseHexFloat: [Function: parseHexFloat],
stringify: [Function: stringify],
toHexString: [Function: toHexString],
version: '1.2.0'
}
> SION.parse('["formats":["JSON","SION"]]');
{ formats: [ 'JSON', 'SION' ] }
> SION.stringify({formats: ["JSON", "SION"]});
'["formats":["JSON","SION"]]'