universal-serialize

WebJar for universal-serialize

Лицензия

Лицензия

Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

universal-serialize
Последняя версия

Последняя версия

1.0.7
Дата

Дата

Тип

Тип

jar
Описание

Описание

universal-serialize
WebJar for universal-serialize
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/krakenjs/universal-serialize

Скачать universal-serialize

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/universal-serialize/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>universal-serialize</artifactId>
    <version>1.0.7</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/universal-serialize/
implementation 'org.webjars.npm:universal-serialize:1.0.7'
// https://jarcasting.com/artifacts/org.webjars.npm/universal-serialize/
implementation ("org.webjars.npm:universal-serialize:1.0.7")
'org.webjars.npm:universal-serialize:jar:1.0.7'
<dependency org="org.webjars.npm" name="universal-serialize" rev="1.0.7">
  <artifact name="universal-serialize" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='universal-serialize', version='1.0.7')
)
libraryDependencies += "org.webjars.npm" % "universal-serialize" % "1.0.7"
[org.webjars.npm/universal-serialize "1.0.7"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Universal Serialize

Universal serializer and deserializer, which supports many build-in javascript types, and any number of custom types you want to support

Simple serialization

import { serialize, deserialize } from 'universal-serialize';


// Define a complex object
const originalObject = {
  foo: 'bar',
  date: new Date(),
  error: new Error('world')
};

// Serialize the complex object
const jsonString = serialize();

// Deserialize the object
const deserializedObject = deserialize(jsonString);

// Make use of the deserialized data and objects
console.log(
  deserializedObject.foo,
  deserializedObject.date.toUTCString(),
  deserializedObject.error.stack
);

By default universal serialize will serialize:

  • Errors
  • Regexes
  • Dates
  • Arrays
  • Objects
  • Strings
  • Numbers
  • Booleans
  • Nulls

Custom serialization

import { serialize, deserialize, serializeType, TYPE } from 'universal-serialize';

// Define a new serialization type
const SERIALIZED_FUNCTION = 'SERIALIZED_FUNCTION';

// Define a complex object containing a function
const originalObject = {
    sayHello: () => {
        console.log('Hello world!');
    };
};

// Serialize the object with a special handler to serialize function types
const jsonString = serialize(originalObject, {
    [ TYPE.FUNCTION ]: (val) => {
        // Serialize the function as a 'serialized function'
        return serializeType(SERIALIZED_FUNCTION, val.toString());
    }
});

// Deserialize any `SERIALIZED_FUNCTION` types from the serialized object
const deserializedObject = deserialize(jsonString, {
    [ SERIALIZED_FUNCTION ]: (fnString) => {
      return eval(fnString);
    }
});

// Call the deserialized functionn
deserializedObject.sayHello();

Quick Start

Getting Started

  • Fork the module
  • Run setup: npm install
  • Start editing code in ./src and writing tests in ./tests
  • npm run build

Building

npm run build

Tests

  • Edit tests in ./test/tests

  • Run the tests:

    npm run test

Testing with different/multiple browsers

npm run karma -- --browser=PhantomJS
npm run karma -- --browser=Chrome
npm run karma -- --browser=Safari
npm run karma -- --browser=Firefox
npm run karma -- --browser=PhantomJS,Chrome,Safari,Firefox

Keeping the browser open after tests

npm run karma -- --browser=Chrome --keep-open

Publishing

Before you publish for the first time:
  • Delete the example code in ./src, ./test/tests and ./demo
  • Edit the module name in package.json
  • Edit README.md and CONTRIBUTING.md
Then:
  • Publish your code: npm run release to add a patch
    • Or npm run release:path, npm run release:minor, npm run release:major
org.webjars.npm

The kraken.js team

The kraken.js team at PayPal

Версии библиотеки

Версия
1.0.7