An open API service indexing awesome lists of open source software.

https://github.com/imjuni/stringaccess


https://github.com/imjuni/stringaccess

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

StringAccess
============

String Access is a import, export library using by dot-notation string. See below.

# Exporter

```js
var sa = require('stringaccess')();
var superheros = {
ironman: {
name: 'Tony Stark',
indivisual: {
species: 'Human',
placeOfOrigin: 'Earth',
partnerships: 'War Machine'
}
},
thor: {
name: 'Thor Odinson',
indivisual: {
species: 'Asgardian',
placeOfOrigin: 'Asgard'
}
}
};

console.log(sa.exporter(superheros, 'ironman.name'));

# shell output
Tony Stark
```

# Importer

```js
var sa = require('stringaccess')();
var superheros = {
ironman: {
name: 'Tony Stark',
indivisual: {
species: 'Human',
placeOfOrigin: 'Earth',
partnerships: 'War Machine'
}
},
thor: {
name: 'Thor Odinson',
indivisual: {
species: 'Asgardian',
placeOfOrigin: 'Asgard'
}
}
};

sa.importer(superheros, 'hulk', {
name: 'Robert Bruce Banne',
});

sa = require('../lib/StringAccess')({ isCreate: true }); // isCreate options is create object on blank path
sa.importer(superheros, 'hulk.indivisual.species', 'Unknown');

console.log(superheros.hulk.name);
console.log(superheros.hulk.indivisual.species);

# shell output
Robert Bruce Banne
Unknown
```

# Options
* isCreate: Create object on blank path
* isAssign: Path is point to object this time replace it. But isAssign is true, assign it. See test/sa.js in StringAccess_importer_object test.

If you need more example, see test/sa.js.