Socket
Socket
Sign inDemoInstall

json-dry

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## 1.0.1 (2018-01-23)
* Fix reference paths being replaced with paths of equal or even longer size
## 1.0.0 (2018-01-15)

@@ -2,0 +6,0 @@

6

lib/json-dry.js

@@ -17,3 +17,3 @@ "use strict";

* @since 0.1.0
* @version 1.0.0
* @version 1.0.1
*

@@ -133,5 +133,5 @@ * @param {Object} root

// See if the new path is shorter
len = 0;
len = 1;
for (i = 0; i < path.length; i++) {
len += 1 + path.length;
len += 1 + path[i].length;
}

@@ -138,0 +138,0 @@ len += key.length;

{
"name": "json-dry",
"description": "Don't repeat yourself, JSON: Add support for (circular) references, class instances, ...",
"version": "1.0.0",
"version": "1.0.1",
"author": "Jelle De Loecker <jelle@develry.be>",

@@ -21,2 +21,3 @@ "keywords": [

"devDependencies": {
"coveralls" : "^2.11.6",
"istanbul" : "^0.4.5",

@@ -29,2 +30,2 @@ "mocha" : "1.20.x",

}
}
}

@@ -12,2 +12,21 @@ # JSON-dry

## Table of contents
* [Installation](#installation)
* [Usage](#usage)
* [Basic example](#basic-example)
* [Implementing methods for serializing & reviving instances](#implementing-methods-for-serializing--reviving-instances)
* [toObject](#toobject)
* [Cloning objects & instances](#cloning-objects--instances)
* [Clone methods](#clone-methods)
* [dryClone](#dryclone)
* [Custom clone methods](#custom-clone-methods)
* [Project history](#project-history)
* [Project future](#project-future)
* [Versioning](#versioning)
* [License](#license)
* [Acknowledgments](#acknowledgments)
## Installation

@@ -17,2 +36,3 @@

## Usage

@@ -75,4 +95,5 @@

### Reviving instances
### Implementing methods for serializing & reviving instances
Let's create an example class you might want to serialize and revive:

@@ -141,2 +162,3 @@

### toObject

@@ -150,2 +172,3 @@

## Cloning objects & instances

@@ -165,2 +188,3 @@

### Clone methods

@@ -172,2 +196,3 @@

#### dryClone

@@ -184,2 +209,3 @@

#### Custom clone methods

@@ -203,1 +229,37 @@

```
## Project history
Earlier versions of the project were heavily based on [circular-json](https://github.com/WebReflection/circular-json), a small library that adds (circular) reference support to JSON.
A lot of the JavaScript code on my websites was already shared between the server & client side, but I also wanted an easy way of sending data to the client while retaining references & class instances, so I started adding features to circular-json and called it `json-dry` (*dry* as in *don't repeat yourself*).
After version 0.1.6 I integrated `json-dry` into my [protoblast](https://github.com/skerit/protoblast) library, and development continued in there. But now it has deserved its own repository once again.
This version is a rewrite of earlier versions. `circular-json` used (and still uses) multiple arrays to keep track of already used objects, but `json-dry` now uses `WeakMap`s, something that makes the code easier to maintain and is also faster.
`circular-json` was also implemented as a `replacer` and `reviver` function to `JSON.stringify` and `JSON.parse` respectively. `json-dry` actually creates a new object before `stringifying` it.
Because multiple references are represented as `~paths~to~the~first~reference`, the size of the JSON string can be a lot smaller. Can be, though, because sometimes reference paths are longer than the object they are refering to.
Because of this, as soon as `json-dry` encounters a new path that is smaller than the previous one, it'll use that in the future. This helps a bit, though more improvements could be made in the future.
## Project future
* Possibly use objects or arrays instead of string primitives for references. This would speed up serializing and parsing, but be a bit more verbose. Tell me what you think in [issue #2](https://github.com/skerit/json-dry/issues/2)
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/skerit/json-dry/releases).
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
## Acknowledgments
Many thanks to [WebReflection](https://github.com/WebReflection/), whose [circular-json](https://github.com/WebReflection/circular-json) was the basis for earlier versions of this project.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc