1.1.0 • Published 4 years ago

easydot v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

easydot

MIT License

easydot provides "dot-string access" for target object.

e.g) console.log(easydot({a:{b:{c:42}}})["a.b.c"]); // => 42

Installing

For Browser (CDN)

<script src="https://cdn.jsdelivr.net/gh/matsuby/easydot/dist/easydot.min.js"></script>

For Node.js

// Install from npm
npm install --save easydot

// Install from yarn
yarn add easydot

and

// Use ES Modules
import easydot from "easydot";

// Use Common JS
const easydot = require("easydot");

Usage

const target = {
  what: {
    is: {
      easydot: 42
    }
  }
};

// create proxy that implements `dot-string acccess`
const proxy = easydot(target);

// get nested property
console.log(proxy["what.is.easydot"]);
// => 42

// set nested property
proxy["what.is.easydot"] = "set value";
console.log(proxy.what.is.easydot);
// => "set value"

// this is a just proxy, so target status was affected
proxy["what.is.name"] = "john";
console.log(JSON.stringify(target, null, 2));
// =>
// {
//  "what": {
//    "is": {
//      "easydot": "set value",
//      "name": "john"
//    }
//  }
// }

Over jump access

const target = {
  what: {
    is: {
      easydot: 42
    }
  }
};

// unsafe over jump access(default)
const unsafeProxy = easydot(target);
try {
  unsafeProxy["not.exist.property"];
} catch (e) {
  console.error("error");
}


// safe over jump access(optional)
const safeProxy = easydot(target, true);
safeProxy["not.exist.property"] = "safe";
1.1.0

4 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago