Coder Social home page Coder Social logo

parselicious's Introduction

parselicious

a module for parsing strings used inhouse for BardsBallad modifier strings.

Installation

You can install it via your preferred package manager. npm i -S parselicious

Usage

Import the module.

import parse from 'parselicious';

// or require it.
const parse = require('pareselicious').default

Then provide the string and variables that are accessible for the string.

const vars = {
  name: 'Bob',
  number: '111-111-1111',
  birthYear: 2001,
  currentYear: new Date.now().getCurrentYear()
}

const result = parse('Hey! My name is ${name} my number is ${number} and I\'m currently *{currentYear - birthYear} years old.', vars)
// Hey! My name is Bob my number is 111-111-1111 and I'm currently 22 years old.

Features

  • Doesn't use Eval so is safe to run on user generated content.
  • Limits what variables the parser has acess to keep secrets safe.
  • Math expressions via *{} *{10 + 2 ^ 10}
  • Conditionals via ?{} ?{3 < 10 ? less : more}
  • variable replacements via ${} ${age}

TODO:

  1. Make a way to keep math variables for further down the line something like *{math + expression}[variableName] ?{variableName > 10 ? true : false}
  2. Add support for math expressions inside of conditional expressions.

parselicious's People

Contributors

kingcosmic avatar

Stargazers

Paul Nunes Sabatino avatar

Watchers

 avatar

Forkers

halfdollanugget

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.