Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/topliceanu/jaccess
object accessor utility that works like the `?.` operator from coffeescript
https://github.com/topliceanu/jaccess
Last synced: 1 day ago
JSON representation
object accessor utility that works like the `?.` operator from coffeescript
- Host: GitHub
- URL: https://github.com/topliceanu/jaccess
- Owner: topliceanu
- Created: 2012-05-30T09:19:21.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-05-30T10:09:52.000Z (over 12 years ago)
- Last Synced: 2023-03-22T20:57:54.716Z (over 1 year ago)
- Language: JavaScript
- Size: 105 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
jAccess
=======[![Build Status](https://secure.travis-ci.org/topliceanu/jAccess.png)](http://travis-ci.org/topliceanu/jAccess)
small function that works like the `?.` operator in coffeescript
i.e it tries to return the requested key chain from an object. If it fails, it returns _undefined_ instead of throwing an error
various accessors are supported in the query string (see _Use case_)
API
---jAccess( data: Object [, query: String] ) : mixed
* data: Object - the query is run against this object
* query: String (Optional) - chain of accessor keys defined by `.` or `[ ]`
**Return value**if `query` is present, jAccess returns the requested value or undefined
if `query` is not present, jAccess returns an object whos only method is `get`
`get = function (query) ` - runs a given query on the initial data object. Usefull for multiple queries on the same object
Use case
--------var largeObject;
var db = jAccess(largeObject);
var value = db.get('prop1.prop2["prop3"][prop4][0].prop5');// alternatively
var value = jAccess(largeObject, 'prop1.prop2["prop3"][prop4][0].prop5');// value is either undefined or the value of largeObject.prop1.prop2.prop3.prop4[0].prop5.
// no expceptions are thrown