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

your-script

v0.0.5

Published

Module, allows you to create your own subset of JavaScript

Downloads

20

Readme

your-script

Module allows you to create your own subset of keywords for JavaScript

Do you ever dreamed of MeowScript or BroScript? Now it's easier then ever.

Distribution

This module is distributed via npm, run npm i your-script just where you need it.

Usage

Easy way:

var yourScript = require('your-script');
var yoscript = new yourScript();

yoscript.parse('var barrio = foorio;');

And if you'll log the result of this operation, you'll see... No difference :) This happens due the default .lex configurations, there is no difference between javascript.lex and yourscript.lex by default. So, the easiest way to change keywords is just edit yourscript.lex in the way you like it and than translate everything from end to end.

This module is bundled with some dialects inside:

  • geoscript — keywords are random places on earth
  • meowscript — 50 shades of meow

True way:

This module assumed to be used for creating custom .lex definitions, so create a folder somewhere, and put there javascript.lex (it's required for this module to work, default could be found in lexems folder), and literally-any-script.lex, when instantiating the yourScript instance, just pass the path (yeah), in config object:

var translator = new yourScript({
  lexemsFolder: './per/some/folder/ad/lexems'
  from: 'javascript',
  to: 'somescript'
});

Now you have a translator, which will replace all keywords in given source from javascript to somescript definitions. If initial folder contains more then two file, it's totally ok, you can set the source and destination subsets right before parsing:

var translator = new yourScript({
  lexemsFoalder: './lexems'
});

and then...

translator.parse(sourceString, {
  from: 'subset you source written in'
  to 'subset to translate your source to'
});

now we're ready to...

How to create MeowScript


  • npm i your-script somewhere you like it
  • open node_modules/your-script/lexems folder
  • create meowscript.lex file
  • open javascript.lex somewhere nearby
  • replace all the keywords! The order doesn't matters, just be imaginative :) Example:
VAR meow
LET meoww
CONST meOw
FOR meowwr
...
  • var translator = require('your-script');
meowScript = new translator({
  to: 'meowscript'
});
  • Pass some source through it:
var kitty = new Kitty(); if (kitty.isHungry()) {kitty.feed()}
                            ||
                           \||/
                            \/
meow kitty = MEW Kitty(); meeow (kitty.isHungry()) {kitty.feed()}
  • Have fun :)

YourScript object interface:

    /**
     * Applies given config.
     *
     * @param {Object} config
     *   @config {String} lexemsFolder Path to lookup for keywords
     *   @config {String} sourceSubset Subset to parse from
     *   @config {String} destinationSubset Subset to parse to
     */
    applyConfig: function(config)
    
    /**
     * Parses the given string, translating it between subsets.
     *
     * @param {String} string Source to parse
     * @param {Object} options
     *   @config {String} sourceSubset Subset to parse from
     *   @config {String} destinationSubset Subset to parse to
     * @returns {String} translated source
     */
    parse: function (string, options)
    
    /**
     * Replaces tokens with their translations from preset subsets.
     *
     * @param {String} string source, contains tokens from source subset
     * @param {Object[]} tokens Array of esprima tokens to be used in replacing.
     * @returns {String} source, contains target subset tokens
     */
    replaceTokens: function(string, tokens)
    
    /**
     * Translates the keyword from the preset source subset to target subset.
     *
     * @param {String} keyword actual keyword value
     * @returns {String} translated keyword
     */
    translate: function(keyword)
    
    /**
     * Checks whether this token should be replaced or not.
     *
     * @param {Object} token esprima token
     * @returns {Boolean} true if should be replaced
     */
    isTargetToken: function(token)
    
    /**
     * Applies translation offset to the given position.
     *
     * @param {Number} position
     * @returns {Number} position with offset
     */
    applyOffset: function(position)
    
    /**
     * Increments translation offset (different subsets - different keyword length)
     *
     * @param {String} tokenValue
     */
    incrementOffset: function(tokenValue)

Under the hood.

This module uses esprima fork, which supports custom keywords, can be found at:

https://github.com/iamfrontender/esprima-custom-keywords

And small yet useful keywords-provider:

https://github.com/iamfrontender/keywords-provider

Cheers, mate!