Ultra tiny serializer / encoder with plugin-support

栏目: IT技术 · 发布时间: 4年前

内容简介:Disclaimer: This library is part of a bigger project and it's goal is to be as small as possible (I don't want to use the >200kb bundle ofThe name is based on nashorn which is the German word for rhino.

Ultra tiny serializer / encoder with plugin-support

Ultra tiny object serializer

Disclaimer: This library is part of a bigger project and it's goal is to be as small as possible (I don't want to use the >200kb bundle of bson ). This lib is only around 4kb, uncompressed. It's only supposed to work within JS itself and not all data-types are implemented so far (see types-table at the bottom).

The name is based on nashorn which is the German word for rhino.

Installation

Install via npm or yarn :

$ npm install nason
# or
$ yarn add nason

Include directly via jsdelivr :

<script src="https://cdn.jsdelivr.net/npm/nason/lib/nason.min.js"></script>

Using JavaScript Modules :

import {...} from 'https://cdn.jsdelivr.net/npm/nason/lib/nason.min.mjs'

Usage

import {deserialize, serialize} from 'nason';

// Serialize something, you'll get a Uint8Array in return.
// You can pass any kind of supported data-type you want to serialize.
const enc = serialize({
    'hello': 'world',
    'number': 13235,
    'array': [1, 2, 3, 'abc']
});

// ... save enc to file or do whatever you want with it

// Deserialize a previously serialized value
const dec = deserialize(enc);
console.log(dec); // Will be the same as initially passed into serialize

nason exports the following properties and functions:

import {
    deserialize, // Takes a single Uint8Array and decodes it
    serialize, // Takes any supported value and converts it to a Uint8Array
    version // Current version of this package
} from 'nason';

There's even more if you want to develop plugins !

Data-types

Data-type Status
object :white_check_mark: Fully supported
array :white_check_mark: Fully supported
string :white_check_mark: Fully supported
number No floating-point number support
boolean :white_check_mark: Fully supported
null :white_check_mark: Fully supported

undefined is not part of the json specification and will throw an error if you try to serialize it.

I'm facing several problems supporting floating-point numbers. PR's and / or issues with ideas / suggestions are highly appreciated!

Plugins

It's possible to write custom encoders for data-types not supported out-of-the-box. Head to plugins to get started!

Logo / Icon provided by Icons8 .


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

失控的未来

失控的未来

[美]约翰·C·黑文斯 / 仝琳 / 中信出版集团 / 2017-4-1 / 59.00元

【编辑推荐】 20年前,尼古拉•尼葛洛庞帝的《数字化生存》描绘了数字科技给人们的工作、生活、教育和娱乐带来的冲击和各种值得思考的问题。数字化生存是一种社会生存状态,即以数字化形式显现的存在状态。20年后,本书以一种畅想的形式,展望了未来智能机器人与人类工作、生活紧密相联的场景。作者尤其对智能机器人与人类的关系,通过假设的场景进行了大胆有趣的描述,提出了人工智能的未来可能会面临的一些问题。黑文......一起来看看 《失控的未来》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具