hasten

0.0.2 • Public • Published

hasten

Evaluate JS statically and dynamically. Hasten resolves all it can statically and asks for your input when it can't.

api

Give it input and it will give you output:

const output = hasten(src)

Give it variables and it will use those while resolving stuff:

const output = hasten(src, {
  foo: 'baz'
})

Give it a callback and it will call it when it cant resolve something. Now you can return something to help hasten resolve:

const output = hasten(src, {
  foo: 'baz'
}, (astNode, missingAstNode) => {
  if (astNode.type === 'ifStatement' && missingAstNode.name === 'device') {
    return 'phone'
  }
})

example

Input:

const obj = {}
obj.foo = 'bar'
if (obj.foo === 'bar') {
  console.log('success!')
}
if (/Macintosh/.test(window.navigator.userAgent)) {
  console.log('hipster!')
}
if (unknownThing === 'superman') {
  console.log('superman!')
}

Do something like:

const output = hasten(src, {
  window: {
    navigator: {
      userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36"
    }
  }
}, (astNode, missingAstNode) => {
  if (missingAstNode.name === 'unknownThing') {
    return 'bird'
  }
}

Output:

const obj = {}
obj.foo = 'bar'
if (true) {
  console.log('success!')
}
if (true) {
  console.log('hipster!')
}
if (false) {
  console.log('superman!')
}

Package Sidebar

Install

npm i hasten

Weekly Downloads

0

Version

0.0.2

License

ISC

Last publish

Collaborators

  • vigour-io