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

0.0.5 • Public • Published

@ria-develop/js-expressions-core

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 @ria-develop/js-expressions-core

or

npm i -S @ria-develop/js-expressions-core

Typescript

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

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-core');

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-core';

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-core

Weekly Downloads

1

Version

0.0.5

License

ISC

Unpacked Size

21.1 kB

Total Files

7

Last publish

Collaborators

  • spamshaker