Skip to content

Commit

Permalink
Merge df48f2c into 1959b75
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfcosta committed Jul 9, 2016
2 parents 1959b75 + df48f2c commit b065015
Show file tree
Hide file tree
Showing 11 changed files with 790 additions and 334 deletions.
23 changes: 20 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
coverage/
node_modules/
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results
build
components

node_modules
npm-debug.log
*.tmp.js

coverage/

pathval.js
5 changes: 5 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
keithamus
davelosert
lucasfcosta
meeber
vesln
189 changes: 116 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,145 @@
[![NPM version](https://badge.fury.io/js/pathval.png)](http://badge.fury.io/js/pathval)
[![Build Status](https://secure.travis-ci.org/chaijs/pathval.png)](http://travis-ci.org/chaijs/pathval)
[![Code Climate](https://codeclimate.com/github/chaijs/pathval.png)](https://codeclimate.com/github/chaijs/pathval)
<h1 align=center>
<a href="http://chaijs.com" title="Chai Documentation">
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"/> pathval
</a>
</h1>

<p align=center>
Tool for Object value retrieval given a string path for <a href="http://nodejs.org">node</a> and the browser.
</p>

<p align=center>
<a href="./LICENSE">
<img
alt="license:mit"
src="https://img.shields.io/badge/license-mit-green.svg?style=flat-square"
/>
</a>
<a href="https://github.com/chaijs/pathval/releases">
<img
alt="tag:?"
src="https://img.shields.io/github/tag/chaijs/pathval.svg?style=flat-square"
/>
</a>
<a href="https://travis-ci.org/chaijs/pathval">
<img
alt="build:?"
src="https://img.shields.io/travis/chaijs/pathval/master.svg?style=flat-square"
/>
</a>
<a href="https://coveralls.io/r/chaijs/pathval">
<img
alt="coverage:?"
src="https://img.shields.io/coveralls/chaijs/pathval/master.svg?style=flat-square"
/>
</a>
<a href="https://www.npmjs.com/packages/pathval">
<img
alt="npm:?"
src="https://img.shields.io/npm/v/pathval.svg?style=flat-square"
/>
</a>
<a href="https://www.npmjs.com/packages/pathval">
<img
alt="dependencies:?"
src="https://img.shields.io/npm/dm/pathval.svg?style=flat-square"
/>
</a>
<a href="">
<img
alt="devDependencies:?"
src="https://img.shields.io/david/chaijs/pathval.svg?style=flat-square"
/>
</a>
<br/>
<a href="https://saucelabs.com/u/chaijs-pathval">
<img
alt="Selenium Test Status"
src="https://saucelabs.com/browser-matrix/chaijs-pathval.svg"
/>
</a>
<br>
<a href="https://chai-slack.herokuapp.com/">
<img
alt="Join the Slack chat"
src="https://img.shields.io/badge/slack-join%20chat-E2206F.svg?style=flat-square"
/>
</a>
<a href="https://gitter.im/chaijs/chai">
<img
alt="Join the Gitter chat"
src="https://img.shields.io/badge/gitter-join%20chat-D0104D.svg?style=flat-square"
/>
</a>
</p>

## What is pathval?

Pathval is a module which you can use to retrieve or set an Object's property for a given `String` path.

# pathval
## Installation

## Usage
### Node.js

```
var props = require('pathval');
```
`pathval` is available on [npm](http://npmjs.org). To install it, type:

Given:
$ npm install pathval

```js
var obj = {
prop1: {
arr: ['a', 'b', 'c']
, str: 'Hello'
}
, prop2: {
arr: [ { nested: 'Universe' } ]
, str: 'Hello again!'
}
}

var arr = [ { foo: 'bar' } ];
```
### Browsers

Expect:
You can also use it within the browser; install via npm and use the `pathval.js` file found within the download. For example:

<!-- js
var props = require('./');
-->
```html
<script src="./node_modules/pathval/pathval.js"></script>
```

#### get
## Usage

```js
props.get(obj, 'prop1.str'); // => "Hello"
props.get(obj, 'prop1.arr[2]'); // => "c"
props.get(obj, 'prop2.arr[0].nested'); // => "Universe"
The primary export of `pathval` is an object which has the following methods:

props.get(arr, '[0].foo'); // => "bar"
* `hasProperty(object, name)` - Checks whether an `object` has `name`d property or numeric array index.
* `getPathInfo(path, object)` - Returns an object with info indicating the value of the `parent` of that path, the `name ` of the property we're retrieving and its `value`.
* `getPathValue(path, object)` - Retrieves the value of a property at a given `path` inside an `object`'.
* `setPathValue(path, object, value)` - Sets the `value` of a property at a given `path` inside an `object`'.

props.get(undefined, 'doesnt.matter'); // => undefined
props.get({}, 'doesnt.exist'); // => undefined
```js
var pathval = require('pathval');
```

#### set
#### .hasProperty(object, name)

```js
props.set(obj, 'hello.universe', 'properties');
props.set(obj, 'hello.universe[1].properties', 'galaxy');
props.set(obj, 'hello', 'universe');
props.set(obj, 'hello[0]', 1);
props.set(obj, 'hello[2]', 3);
```
var pathval = require('pathval');

## Installation

```bash
npm install pathval
var obj = { prop: 'a value' };
pathval.hasProperty(obj, 'prop'); // true
```

## Tests
#### .getPathInfo(path, object)

### Running the tests
```js
var pathval = require('pathval');

```bash
$ npm test
var obj = { earth: { country: 'Brazil' } };
pathval.getPathInfo('earth.country', obj); // { parent: { country: 'Brazil' }, name: 'country', value: 'Brazil', exists: true }
```

### Test coverage

```bash
$ npm run-script coverage
```
#### .getPathValue(path, object)

### Readme tests
```js
var pathval = require('pathval');

```bash
$ npm run-script test-readme
var obj = { earth: { country: 'Brazil' } };
pathval.getPathValue('earth.country', obj); // 'Brazil'
```

## License

MIT License

Copyright (c) 2011-2013 Jake Luer jake@alogicalparadox.com
#### .setPathValue(path, object, value)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
```js
var pathval = require('pathval');

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
var obj = { earth: { country: 'Brazil' } };
pathval.setPathValue('earth.country', obj, 'USA');

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
obj.earth.country; // 'USA'
```
33 changes: 0 additions & 33 deletions hydro.conf.js

This file was deleted.

0 comments on commit b065015

Please sign in to comment.