All Projects → vinayk406 → angular-expression-parser

vinayk406 / angular-expression-parser

Licence: MIT License
This library helps in achieving AngularJs equivalents of $parse, $eval and $watch in Angular.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to angular-expression-parser

Arrive
Watch for DOM elements creation and removal
Stars: ✭ 703 (+4035.29%)
Mutual labels:  dynamic, watch
Splain
small parser to create more interesting language/sentences
Stars: ✭ 15 (-11.76%)
Mutual labels:  parse, dynamic
eval-estree-expression
Safely evaluate JavaScript (estree) expressions, sync and async.
Stars: ✭ 22 (+29.41%)
Mutual labels:  parse, eval
toxic-decorators
Library of Javascript decorators
Stars: ✭ 26 (+52.94%)
Mutual labels:  watch
json-source-map
Parse/stringify JSON and provide source-map for JSON-pointers to all nodes - supports BigInt, Maps, Sets and Typed arrays
Stars: ✭ 55 (+223.53%)
Mutual labels:  parse
pinus-parse-interface
parse interface to pinus-protobuf JSON
Stars: ✭ 25 (+47.06%)
Mutual labels:  parse
FacePorts
Clockology ports of all the watch faces that Apple withholds from certain watch models
Stars: ✭ 27 (+58.82%)
Mutual labels:  watch
instrumentation
Assorted pintools
Stars: ✭ 24 (+41.18%)
Mutual labels:  dynamic
jseval
Evaluate JavaScript on a URL through headless Chrome browser.
Stars: ✭ 19 (+11.76%)
Mutual labels:  eval
gpp-decrypt
Tool to parse the Group Policy Preferences XML file which extracts the username and decrypts the cpassword attribute.
Stars: ✭ 13 (-23.53%)
Mutual labels:  parse
Script.apex
Evaluate Javascript expressions in Apex
Stars: ✭ 18 (+5.88%)
Mutual labels:  parse
guilyx
Dynamic Profile with github statistics, coding info (time and languages) with WakaTime and music status with the spotify API, leave a ⭐ if you like it
Stars: ✭ 175 (+929.41%)
Mutual labels:  dynamic
LeagueReplayParser
C# library which can read some data from a .rofl file, and start a replay in the client. (no longer actively maintained)
Stars: ✭ 20 (+17.65%)
Mutual labels:  parse
staticfusion
StaticFusion
Stars: ✭ 107 (+529.41%)
Mutual labels:  dynamic
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (-17.65%)
Mutual labels:  dynamic
sjson-cpp
An Simplified JSON (SJSON) C++ reader and writer
Stars: ✭ 16 (-5.88%)
Mutual labels:  parse
Diffy
🎞️💓🍿 Love streaming - It's always best to watch a movie together ! 🤗
Stars: ✭ 37 (+117.65%)
Mutual labels:  watch
parse-function
(!! moved to tunnckoCore/opensource multi-package repository !!) 🔱 Parse a function into an object using espree, acorn or babylon parsers. Extensible through Smart Plugins.
Stars: ✭ 37 (+117.65%)
Mutual labels:  parse
ytnef
Yeraze's TNEF Stream Reader - for winmail.dat files
Stars: ✭ 28 (+64.71%)
Mutual labels:  parse
gonids
gonids is a library to parse IDS rules, with a focus primarily on Suricata rule compatibility. There is a discussion forum available that you can join on Google Groups: https://groups.google.com/forum/#!topic/gonids/
Stars: ✭ 140 (+723.53%)
Mutual labels:  parse

angular-expression-parser

This library helps in achieving AngularJs equivalents of $parse, $eval and $watch in Angular.

How to use

Download expression-parser.ts and services.ts in your Angular application.

Register the PipeProvider declared in services.ts with the Application module.

$parse

In your component file implement the below changes

  1. add the below import statements
import { $parse } from "path_to_expression-parser";
import { PipeProvider } from "path_to_services";
  1. Add the PipeProvider dependency
constructor(private pipeProvider: PipeProvider) {}

Arguments to $parse function:

  1. Expression to be parsed
  2. PipeProvider

let fn = $parse('(((firstName | uppercase) + lastName) | lowercase) | slice:start:end | uppercase', this.pipeProvider);

This returns a function which can later be excuted with a context.

$eval

The function returned with $parse accepts two arguments

  1. context
  2. overrides

example:

class AppComponent implements OnInit{

  constructor(public pipeProvider: PipeProvider) {}
  
  ngOnInit() {
    this.first = 'Hi';
    this.last = "World";
    let fn = $parse('first + " " + last | uppercase', this.pipeProvider);
    console.log(fn(this)); // logs HI WORLD
    console.log(fn(this, {first: 'hello'})); // logs HELLO WORLD
  }
}

$watch

To achieve $watch like functionality, we need to excute the function returned by $parse in ngDoCheck life cycle method.

example:

class AppComponent implements OnInit, DoCheck{
  
  constructor(public pipeProvider: PipeProvider) {}
  
  ngOnInit() {
    this.first = 'Hi';
    this.last = "World";
    this.watchers = [];
    let fn = $parse('first + " " + last | uppercase', this.pipeProvider);
    this.watchers.push([fn]);
    this.watchers.push([fn, {first: 'hello'}]);
  }
  
  ngDoCheck() { // evaluates the parsed functions on each change detection cycle
    for (const [fn, locals] of this.watchers) {
      console.log(fn(this, locals)); 
    }
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].