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

inlay

v0.0.7

Published

JavaScript source code templating system

Downloads

1

Readme

inlay

A node.js module for creating and inlining JavaScript source code templates.

Installation

Install using npm:

npm install inlay

Running the examples

The module includes a very basic sample which can be preprocessed using:

cd inlay/examples/basic
../../bin/inlay

The resulting JS source is now under ./lib and you can run it using:

node ./lib/basic.js

Status

Experimental - functional, but a work in progress. Hence no jsdocs or detailed user documentation. APIs are subject to change.

Defining templates

Templates are JavaScript with some template specific constructs and are used to define JS which can be inlined into your source code.

Inlay template files end with the .jst extension and are typically (but not required) isolated in their own root directory structure.

Templates are defined using the exports.NAME = function(/* args.. */) {/* body */} syntax. The arguments to templates must be explicitly defined -- that is, don't use argless functions and try to reference the args using the arguments[#] syntax -- the preprocessor isn't that smart.

Keep in mind that the body you define is JS source which will be inlined. As such the arguments to your template may be snippets of JS code.

The inlay template system uses 2 special symbols:

@NAME(args) -- The @ to invoke the template named NAME with the given arguments. ${arg} -- The ${} to expand a template argument.

Templates can reference other templates -- the preprocessor will resolve the dependencies for you. This allows you to reuse templates in other templates.

Example templates:

exports.DEBUG = function(msg) {
    if (process.env.NODE_ENV === 'debug') {
        console.log(${msg});
    }
};

exports.EXISTS = function(x) {
    ${x} !== null && ${x} !== undefined
};

exports.LOG_EXISTS = function(y) {
    if (@EXISTS(${y})) {
        console.log("Yes, " + ${y} + " does exist");
    } else {
        console.log("No, " + ${y} + " does not exist");
    }
};

Using templates in your source

To use a template in your JS source, use the @TEMPLATE_NAME syntax.

For example if you have a template named THE_TEMPLATE you can use it in your JS as follows:

//...
@THE_TEMPLATE(arg1, arg2 /* etc */)
//...

The inlay command

The module includes a binary which is packaged under the /bin directory of the module which can be used for invoking inlay from the command line.

It supports the following options:

  Usage: inlay [options]

  Options:

    -h, --help                output usage information
    -V, --version             output the version number
    -s, --source <path>       source path to process [./src]
    -o, --output <path>       output path [./lib]
    -t, --templates <path>    template path [./templates]
    -v, --validate <on>       validate templates and source [true]
    -b, --beautify <options>  js-beautify code with options [{}]
    -d, --debug [on]          debug verbose output [false]

Example usage...

Preprocess all sources under ./src using the templates under ./templates and output the resulting JS under ./lib:

inlay

The same as the above, but print debug info to the console:

inlay -d

Same as the above, but don't validate the resulting js:

inlay -d -v false

Preprocess all sources under ./js using the templates under ./inline and output the resulting JS under ./js-bin:

inlay -s ./js -t ./inline -o ./js-bin

License

(The MIT License)

Copyright (c) 2012 Boden Russell <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.