Code Monkey home page Code Monkey logo

zron's Introduction

ZRON

ZornCo Recursive Object Notation - JSON with circular references, functions, RegExp objects, and Date objects

Example:

JavaScript (Node.JS)

var ZRON = require('zron').ZRON;

var obj = {
	something: 1,
	somethingElse: 2,
};
obj.recurse = obj;
var test: Test = {
	obj: obj,
	func: function() { console.log('test'); },
	date: new Date(),
	regex: /.*test.*/ig,
};

var serialized = ZRON.stringify(test);
var parsed = ZRON.parse(serialized);

// `parsed` should now be equivalent to `test`

TypeScript (Node.JS)

import { ZRON } from 'zron';

interface Obj {
	something: 1;
	somethingElse: 2;
	recurse: Obj;
}
interface Test {
	obj: Obj;
	func: Function;
	date: Date;
	regex: RegExp;
}

let obj: Obj = {
	something: 1,
	somethingElse: 2,
	recurse: undefined,
};
obj.recurse = obj;
let test: Test = {
	obj,
	func: function() { console.log('test'); },
	date: new Date(),
	regex: /.*test.*/ig,
};

let serialized = ZRON.stringify(test);
var parsed: Test = ZRON.parse(serialized);

// `parsed` should now implement the `Test` interface and be equivalent to `test`

Example ZRON string

{
	"type": "zron",
	"uidMap": {
		"1": {
			"type": "object",
			"object": {
				"something": 1,
				"somethingElse": 2,
				"recurse.ZRONUid": "1"
			}
		},
		"2": {
			"type": "object",
			"object": [
				1,
				2,
				3
			]
		},
		"3": {
			"type": "function",
			"function": {
				"body": "function () {\n    console.log('test');\n}"
			}
		},
		"4": {
			"type": "date",
			"date": {
				"timestamp": 1489774609756
			}
		},
		"5": {
			"type": "regexp",
			"regexp": {
				"pattern": ".*test.*",
				"flags": "gi"
			}
		}
	},
	"data": {
		"someText": "this is text",
		"someNumber": 1337,
		"obj.ZRONUid": "1",
		"arr.ZRONUid": "2",
		"func.ZRONUid": "3",
		"date.ZRONUid": "4",
		"regex.ZRONUid": "5",
		"recurse.ZRONUid": "0"
	}
}

zron's People

Contributors

systemdisc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.