Socket
Book a DemoInstallSign in
Socket

cerebral-scheme-parser

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cerebral-scheme-parser

Scheme parser for Cerebral

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

cerebral-scheme-parser

The scheme parser for operators

import schemeParser from 'cerebral-scheme-parser'

const string = 'state:foo.{{input:id}}.{{state:foo.bar}}'
const parsed = schemeParser(string)

parsed.target // "state"
parsed.value = // foo.{{input:id}}.{{state:foo.bar}}

// getValue iterates the inline schemes so this callback
// will be called twice
const newString = parsed.getValue(function (scheme) {
  scheme.target // "input", then "state"
  scheme.value // "id", then "foo.bar"

  if (target === 'input') {
    return 'woop'
  }

  return 'wuuut?'
})

newString // foo.woop.wuuut?

You can also do it async:

import schemeParser from 'cerebral-scheme-parser'

const string = 'state:foo.{{input:id}}'
const parsed = schemeParser(string)

parsed.getValuePromise(function (scheme) {
  scheme.target // "input"
  scheme.value // "id"
  return new Promise(function (resolve) {
    setTimeout(function () {
      resolve('bar')
    }, 100)
  })
})
  .then(function (value) {
    value // "foo.bar"
  })

Keywords

cerebral

FAQs

Package last updated on 14 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts