# obj-parser

> A tool to parse object properties with dynamic replacer

Latest version **0.2.0** (published 2014-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install obj-parser
pnpm add obj-parser
yarn add obj-parser
bun add obj-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2014-10-29 |
| First published | 2014-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Herman |
| Maintainers | threeday0905 |
| Keywords | object, parser, replacer |

## Links

- npm: https://www.npmjs.com/package/obj-parser
- Repository: git@github.com:threeday0905/obj-parser
- Homepage: https://github.com/threeday0905/obj-parser
- Issues: https://github.com/threeday0905/obj-parser/issues
- npm.io page: https://npm.io/package/obj-parser

## Dependencies (1)

- [args-expect](https://npm.io/package/args-expect.md) 0.2.1

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2014-10-29
- 0.1.0 — 2014-10-21

## README

obj-parser
==========
A tool to parse object properties with dynamic replacer.

---
### How to Use

    var replacer = {
        name: 'James',
        age: 12
    };

    var source = {
        foo: '{{name}} / age {{age}}',
        bar: 'staic text',
        baz: [
            '{{name}}', {{age}}
        ]
    };

    var result = require('obj-parser').parse(source, replacer);
    expect(result).to.deep.equal({
        foo: 'James / age 12',
        bar: 'staic text',
        baz: [
            'James', '12'
        ]
    });


### APIs

There are some other useful APIs as below:

##### isPlainObject( value )
desc: same as **jQuery.isPlainObject**

##### extendAllProps( receiver, [ supplier, supplier2, ...] )
desc: same as **jQuery.extend**

##### parseString( str, replacer, callback )
desc: parse string, replace {{xxx}} with map object or callback function

    parseString('name: {{foo}}', {
        foo: 'James'
    });

    parseString('name: {{foo}}', function(match, key) {
        return key.toUpperCase(); // key will be 'foo'
    });    
    
##### getPropByPath( object, path )
desc: get prop value from object with prop path

    var source = {
        foo: {
            bar: 'hello'
        }
    };
    
    getPropByPath(source, 'foo.bar'); //return 'hello'
    
##### setPropByPath ( object, path, newValue )
desc: set prop value from object with prop path

    var source = {
        foo: {
            bar: 'hello'
        }
    };
    
    setPropByPath(source, 'foo.bar', 'world'); // update 'hello' to 'world'
    
##### replaceAllStrProps( obj, replaceFn, hoster )
desc: go throgh all props, and replace the value if it is string.

*refer "test/replaceAllStrProp.test.js" for" detail usage.*

##### replaceAllMatchProps( obj, matchFn, replaceFn, hoster )
desc: go throgh all props, and replace the value if it is pase the matchFn.

*refer "test/replaceAllMatchProps.test.js" for detail usage.*

---
### Questions?

If you have any questions, feel free to create a new issue.

---
_Source: https://npm.io/package/obj-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
