Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allnulled/simple-getter
A tool to access (nested) array items and object properties through array/string-based selectors.
https://github.com/allnulled/simple-getter
Last synced: 1 day ago
JSON representation
A tool to access (nested) array items and object properties through array/string-based selectors.
- Host: GitHub
- URL: https://github.com/allnulled/simple-getter
- Owner: allnulled
- Created: 2017-12-24T16:02:38.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-24T17:11:21.000Z (over 6 years ago)
- Last Synced: 2024-10-31T19:57:31.255Z (17 days ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-getter
## 1. About
The simple-getter utility (for JavaScript) is just a tool to access objects and arrays nested contents through arrays of values used as *selectors*.
## 1. Installation
Import the file at:
src/simple-getter.js
It should work for both, NodeJS and browser environments.
## 2. Usage
You can use this utility like:
SimpleGetter(data, selector)
So for example, once it's loaded, this code should return ```true```:
SimpleGetter(
[0, {a: {b: [0, "foo"]}}, 2],
[1, "a", "b", 1]
) === "foo";You can test it even in the console of your favourite browser, if you want.
## 3. Why?
This utility exists in other libraries, like ```lodash``` or ```underscore```, but with this snippet, you can be sure that you don't depend on anything else for this functionality, which I find very important, as it can help you to solve problems that, otherwise, should require more effort.
Its purpose was to be a completely **minimalistic** approach too.
It doesn't handle errors, but it's up to you to add 3 more lines and handle them in your preferred way.
## 3. License
It is ok.