objstr-resolver
v1.0.0
Published
A simple package to interact with object using string easily.
Downloads
7
Maintainers
Readme
Installation
Install the package using npm
:
npm install --save-dev objstr-resolver
Usage
import {
resolve,
resolveObjValue,
resolveCondition,
resolveMath
} from 'objstr-resolver';
console.log(resolve(`$1`, false)('hello world')); // hello world
console.log(resolve('$1>8')(9)); // true
console.log(
resolveObjValue('name.last')({ name: { first: '...', last:'name' } }) // name
);
console.log(resolveObjValue('name.1')({ name: ['...', 'name'] })); // name
console.log(resolve('$1>$1+1')(resolveObjValue('age')({ age: 23 }))); // true
console.log(resolveCondition('(1==2)&&(1!=3||1==0)')); // true
console.log(resolveCondition('true')); // true
console.log(resolveMath('1+2')); // 3
console.log(resolveMath('((1+2)*2)+((4/2)-1)')); // 7
Functions
resolve(value: string, resolveConditions: boolean, resolveMaths: boolean): Function
value
the target value for resolve it.resolveConditions
enable/disable resolve any condition in value. defaulttrue
resolveMaths
enable/disable resolve any math in value. defaulttrue
- that function compine
,
together.
resolveObjValue(value: string): Function
value
the target value for resolve it.
resolveCondition(value: string): Boolean
value
the target value for resolve it.
resolveMath(value: string): Number
value
the target value for resolve it.
Friendly Note
This package is for personal use but i hope this package help someone if needed something like this.
Bugs & Feedbacks
any report for bugs or feedbacks you can create issue here.
Contributing
All Contributing are welcome :)
License
This package is under MIT
license.