@ria-develop/js-expressions-client
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

@ria-develop/js-expressions-client

A Simple module that generates scope for resolving values by tokens, and returns simple callback which can be used while processing data structure.

Usage

Installation

yarn add lodash.get @ria-develop/js-expressions-client

or

npm i -S lodash.get @ria-develop/js-expressions-client

Typescript

import evaluator, {TokenProvider, TokenResolver} from '@ria-develop/js-expressions-client';

const TestToken = 'MyTestToken';
const TestValue = 'MyTestValue';

type MyData = {
  [TestToken]: string
}

const input: MyData = {[TestToken]: TestValue};

const TargetKey = 'targetKey';

const tokenProvider: TokenProvider = () => TestToken;
const tokenResolver: TokenResolver = <MyData>(data: MyData, token: string) => data[token];
console.log(evaluator<MyData>(input, tokenProvider, tokenResolver)(TargetKey, TestToken));
// output: MyTestValue

Vanilla javascript

const evaluator = require('@ria-develop/js-expressions-client');

const TestToken = 'MyTestToken';
const TestValue = 'MyTestValue';

const input = {[TestToken]: TestValue};

const TargetKey = 'targetKey';

console.log(evaluator(input, 
  () => TestToken, 
  (data: MyData, token: string) => data[token])
  (TargetKey, TestToken)
);
// output: MyTestValue

ES6

import evaluator from '@ria-develop/js-expressions-client';

const TestToken = 'MyTestToken';
const TestValue = 'MyTestValue';

const input = {[TestToken]: TestValue};

const TargetKey = 'targetKey';

console.log(evaluator(input, 
  () => TestToken, 
  (data: MyData, token: string) => data[token])
  (TargetKey, TestToken)
);
// output: MyTestValue

Package Sidebar

Install

npm i @ria-develop/js-expressions-client

Weekly Downloads

0

Version

0.0.6

License

ISC

Unpacked Size

16.2 kB

Total Files

7

Last publish

Collaborators

  • spamshaker