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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nv-macro-lexvar

v1.0.1

Published

nv-macro-lexvar ===================== - nv-macro-lexvar is a simple macro-tool, only one syntax - cli tool, use a simple syntax `##lexvar(...)` in your script - to let you get/set lexical-variables(let,var,params) from outside - to avoid using for/wh

Readme

nv-macro-lexvar

  • nv-macro-lexvar is a simple macro-tool, only one syntax
  • cli tool, use a simple syntax ##lexvar(...) in your script
  • to let you get/set lexical-variables(let,var,params) from outside
  • to avoid using for/while/if-[elif]-else/switch

install

  • npm install nv-macro-lexvar -g

usage

Usage: nv_lexvar [options]
Options:
    -i, --input             input string ,default stdin
    -o, --output            output string,default stdout
    -c, --compile           compile the macro
    -m, --macro_name        `##${macro_name}` used in script,default is lexvar
    -I, --IR                list four basic funcions : sync_while,async_while,sync_if,async_if
    -h, --help              usage




       nv-macro-lexvar# nv_lexvar -M
           the default macro_name:  lexvar
           use it begin with two #:  ##lexvar(...)


       nv-macro-lexvar# nv_lexvar -S
          .....
          let i=1;let a =100; let b=999;.....
          ////-for example, you need to change
          ////     the lexical <a> AND <i> from outside handler <handler>
          let ctx = ##lexvar(i,a);
          ////
          handler(ctx)
          .....

example

    % nv_lexvar -c 

    ////the source code

    function swhile(
        ctx,
        condf    =(ctx)=>ctx.i<5,
        handler  =(ctx)=>{ctx.rslt=ctx.rslt+ctx.i},
        post     =(ctx)=>{ctx.i=ctx.i+1}
    ) {
        while(condf(ctx)) {
            handler(ctx);
            post(ctx);
        }
        return(ctx)
    }


    function tst(param) {
        let i =0;
        let rslt=i;
        let ctx = ##lexvar(i,rslt);     // capture lexical-variables for using from outside
        swhile(ctx);
        return(rslt)
    }

    //--------> press ctrl+D


    function swhile(
        ctx,
        condf    =(ctx)=>ctx.i<5,
        handler  =(ctx)=>{ctx.rslt=ctx.rslt+ctx.i},
        post     =(ctx)=>{ctx.i=ctx.i+1}
    ) {
        while(condf(ctx)) {
            handler(ctx);
            post(ctx);
        }
        return(ctx)
    }

    function tst(param) {
      let i = 0;
      let rslt = i;

      let ctx = (() => {
        let ctx = {};
        Object.defineProperty(ctx, 'i', {
          get: () => i,
          set: v => {
            i = v;
          }
        });
        Object.defineProperty(ctx, 'rslt', {
          get: () => rslt,
          set: v => {
            rslt = v;
          }
        });
        return ctx;
      })();

      swhile(ctx);
      return rslt;
    }

    /*
    > tst()
    10
    >
    */

    function swhile(
        ctx,
        condf    =(ctx)=>ctx.i<5,
        handler  =(ctx)=>{ctx.rslt=ctx.rslt+ctx.i},
        post     =(ctx)=>{ctx.i=ctx.i+1}
    ) {
        while(condf(ctx)) {
            handler(ctx);
            post(ctx);
        }
        return(ctx)
    }


    function sif(
        ctx,
        entries=[
            (ctx)=>ctx.param,(ctx)=>{console.log([ctx.rslt,':',ctx.param])}
        ],
        else_handler=(ctx)=>console.log([ctx.param,':',ctx.rslt]),
    ) {
        for(let i=0;i<entries.length;i=i+2) {
            let condf = entries[i]
            let handler = entries[i+1]
            let cond = condf(ctx);
            if(cond) {
                handler(ctx)
                return(ctx)
            } else {}
        }
        ctx = else_handler(ctx);
        return(ctx)
    }

    function tst(param) {
        let i =0;
        let rslt=i;
        ////
        let ctx = ##lexvar(i,rslt);           //capture lexical-variables <i AND rslt> for using from outside
        swhile(ctx);
        ////
        console.log("lex rslt changed:",rslt)
        ////
        ctx = ##lexvar(param,rslt);      //capture lexical-variables <param AND rslt> for using from outside
        sif(ctx);
        ////
        return(rslt)
    }

    ////-------press ctrl+D

    ...... //generated code below

    function tst(param) {
      let i = 0;
      let rslt = i; ////
      
      /*##lexvar(i,rslt) generated code*/

      let ctx = (() => {
        let ctx = {};
        Object.defineProperty(ctx, 'i', {
          get: () => i,
          set: v => {
            i = v;
          }
        });
        Object.defineProperty(ctx, 'rslt', {
          get: () => rslt,
          set: v => {
            rslt = v;
          }
        });
        return ctx;
      })(); //capture lexical-variables <i AND rslt> for using from outside


      swhile(ctx); ////

      console.log("lex rslt changed:", rslt); ////

      /*##lexvar(param,rslt) generated code*/

      ctx = (() => {
        let ctx = {};
        Object.defineProperty(ctx, 'param', {
          get: () => param,
          set: v => {
            param = v;
          }
        });
        Object.defineProperty(ctx, 'rslt', {
          get: () => rslt,
          set: v => {
            rslt = v;
          }
        });
        return ctx;
      })(); //capture lexical-variables <param AND rslt> for using from outside


      sif(ctx); ////

      return rslt;
    }



    /*
    > tst(true)
    lex rslt changed: 10
    [ 10, ':', true ]
    10
    >
    > tst(false)
    lex rslt changed: 10
    [ false, ':', 10 ]
    10
    >

    */

four basic functions

  • sync while
  • async while
  • sync if
  • async if
  • MOST function could BE done with these four operations
  • the ONLY exception is IF you want to implement goto-like,these four is NOT enough

    swhile
    -------

        function swhile(
            ctx,
            condf,
            handler,
            post
        ) {
            while(condf(ctx)) {
                handler(ctx);
                post(ctx);
            }
            return(ctx)
        }


    awhile
    -------

        async function awhile(
            ctx,
            condf,
            handler,
            post
        ) {
            let cond = await condf(ctx)
            while(cond) {
                await handler(ctx);
                await post(ctx);
                cond = await condf(ctx);
            }
            return(ctx)
        }


    sif
    -------

        function sif(
            ctx,
            entries,
            else_handler,
        ) {
            for(let i=0;i<entries.length;i=i+2) {
                let condf = entries[i];
                let handler = entries[i+1];
                let cond = condf(ctx);
                if(cond) {
                    handler(ctx);
                    return(ctx)
                } else {}
            }
            ctx = else_handler(ctx);
            return(ctx)
        }


    aif
    -------

        async function aif(
            ctx,
            entries,
            else_handler,
        ) {
            for(let i=0;i<entries.length;i=i+2) {
                let condf = entries[i];
                let handler = entries[i+1];
                let cond = await condf(ctx);
                if(cond) {
                    await handler(ctx);
                    return(ctx)
                } else {}
            }
            ctx = await else_handler(ctx);
            return(ctx)
        }

LICENSE

  • ISC