npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jifeon/sval

v0.5.2

Published

A javascript interpreter written in javascript

Downloads

7

Readme

Sval

npm travis-ci coveralls

A JavaScript interpreter writen in JavaScript, based on parser Acorn.

  • Running on ES5, supporting ES5~10 full features
  • Both invasived and sandbox modes available

It's useful to evaluate the code of higher ECMAScript editions, or for the environment with disabled eval, setTimeout and new Function.

Try Sval on the playground.

Installation

Node

Install Sval with npm.

npm install sval

Browser

Simply source from unpkg. Or, download from releases, get minimized file dist/min/sval.min.js, and source at your html page. You can access a global variable Sval directly.

<script type="text/javascript" src="https://unpkg.com/sval"></script>

Usage

import Sval from 'sval'

// Sval options
const options = {
  // ECMA Version of the code (5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019)
  ecmaVer: 9,
  // Whether the code runs in a sandbox
  sandBox: true,
}

// Create a interpreter
const interpreter = new Sval(options)

// Add global modules in interpreter
interpreter.import('importWhatYouNeed', 'AllKindsOfStuffs')
// Or interpreter.import({ importWhatYouNeed: 'AllKindsOfStuffs' })

// Parse and run the code
interpreter.run(`
  const msg = 'Hello World'
  exports.msg = msg // Export any you want
`)

interpreter.run(`
  exports.mod = importWhatYouNeed // Export again and merge
`)

// Get exports from runs
console.log(interpreter.exports.msg) // Get 'Hello World'
console.log(interpreter.exports.mod) // Get 'AllKindsOfStuffs'

Sval constructor has options with two fields, ecmaVer and sandBox.

  • ecmaVer is the ECMAScript edition of the code. Currently, 5, 6(2015), 7(2016), 8(2017), 9(2018) and 10(2019) are supported, and the default edition is 9.

  • sandBox is true for sandbox mode or false for invasived mode. Sandbox mode will run code in an isolated sandbox and won't pollute your global scope. Invasived mode allows you run code in the same global scope of your current environment. The default setting is true.

Sval instance has two methods, import and run.

  • import is to import modules into your Sval instance scope, expecting a name and a module as arguments like import(name: string, mod: any), or an object which contains the modules as argument like import({ [name: string]: any }). The modules will be automatically declared as global variables. This method is more likely to be used in sandbox mode.

  • run is to evaluate the code inputed, expecting a string as argument like run(code: string). If you want to export something, there is a internal global exports object for mounting what you want to export.

Sval instance also has a field, exports, to get what you exported from runs, merged if several runs have exports.

Note

WithStatement and LabeledStatement aren't implemented and recommended. Please avoid to use them.

Reference

License

Sval is licensed under the MIT.