https://github.com/imjuni/stringaccess
https://github.com/imjuni/stringaccess
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/imjuni/stringaccess
- Owner: imjuni
- License: mit
- Created: 2016-05-13T13:40:34.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-18T04:40:49.000Z (about 10 years ago)
- Last Synced: 2024-10-19T10:27:11.020Z (over 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: history.md
- License: LICENSE
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.