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

inprint

v1.3.2

Published

A very simple precompiler written in typescript. With it you can make a dynamically generated blocks in your code.

Downloads

8

Readme

inprint

A very simple precompiler (written in typescript). With it you can make a dynamically generated blocks in your code.

Installation

npm i inprint --save-dev
yarn i inprint --save-dev
pnpm i inprint --save-dev

npm i -g inprint
yarn i -g inprint
pnpm i -g inprint

Usage

  1. Anywhere in your code add a block you want to generate like this
console.log("any code can be here");
// @INPRINT_START {my:"own params", json5:'is supported here!'}
// Anything here will be overwritten by generated code!
// @INPRINT_END
console.log("any code can be here");
  1. Now add inprint.cjs (or .js) to your project with the following contents:
module.exports = {
    files:['src/**/*.{ts,tsx,js,jsx}'],
    embeddedFeatures: false,    // Highly recommended if don't use them!
    inprint: function inprint(paramsObject) {
        return "    // " + JSON.stringify(paramsObject);
    }
}
  1. Run inprint

  2. The returned content will be inprinted between @INPRINT tags:

console.log("any code can be here");
// @INPRINT_START {my:"own params", json5:'is supported here!'}
    // {my:"own params", json5:'is supported here!'}
// @INPRINT_END
console.log("any code can be here");

Details

inprint function will receive the following additional paramaters:

  • absolutePath - absolute file path with inprint block

  • content - current content of the block

Options:

  • inprint - required, the function used to generate inprinted content

  • files - optional, globby input patterns, default is ['src/**/*.{ts,tsx,js,jsx}']

  • skipNodeModules- optional, if true will skip all path containing /node_modules/, default is true

  • embeddedFeatures - 'first' | 'last' | false - used to automatically run embedded generation functions (see the list below), 'first' - to run them before your inprint code, 'last' - to run only if your code returned undefined, false - don't run them ever, default is false.

  • prettierOpts - optional, options forwarded to prettier.

  • forceProcessTermination - if defined will call process.exit(0) after finished. Useful in case you include some files with timers to do your generation and don't want or can't get rid of them

Limitations

  • @INPRINT tags can't be nested

Debugging inprint function

Create inprintDebug.cjs with contents

require("inprint").run();

run it in your favorite IDE to debug the scripts.

Run programmatically

require("inprint").run(options);

Embedded Features

This package also contains some functions which I use for my own project automation.

If you want to disable them use:

embeddedFeatures: false,

If you want to use them add to options file:

embeddedFeatures: 'first'

You can also call them with:

require("inprint").callEmbeddedFeatures(params, options);

Using just one function is also possible, for example:

require("inprint").inprintIndexTs(params, options);

List of embedded features:

IndexTs

Generates reexports for each file in folder:

// @INPRINT_START {exclude:[""], merge:[{name:"embeddedFeatures:EmbeddedFeature[]", suffix:"EmbeddedFeature"}]}
export * from "./indexTs";

import {indexTsEmbeddedFeature} from "./indexTs";
export const embeddedFeatures:EmbeddedFeature[] = [indexTsEmbeddedFeature];
// @INPRINT_END
Params:
  • exclude - array of excluded filenames

  • merge - array of merged variables, defined as objects

    • suffix - name of a const exported from each file

    • name - name of result variable