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

uni-preprocessor

v0.3.0

Published

A (Cpp-like?) preprocessor for any programming language or any config texts or just plain text. Written in TypeScript/NodeJS

Downloads

12

Readme

Universal Preprocessor

NPM Version NPM Downloads

An util library / cli tool for preprocessing any type of files.

Currently used implementation is ifdef.js, written in Dave Balmer. You can find more about how it works there.

Library

The original project is just a cli program and does not provides any export functions.

This project exports a function ifdef_js.process_string(...), it receives string as the file content, and output the preprocessed string file content. For more information, you can see the function comments.

import upp from "uni-preprocessor"

const file_content = ...

const targets = ["windows", "app", "melty_kiss"]
const [processed_result, warnings] = upp.ifdef_js.process_string(file_content, targets)

CLI

This package exported two CLI command, uni-preprocessor and upp. These two command are equivalent to each other.

You can use npm install --global uni-preprocessor to install the CLI to your computer, or use npm install --save-dev uni-preprocessor to install this CLI to your project develop environment.

Then, just use $ upp --help to see the help page. There are helps and examples for the CLI.

Added features

For now, CLI does not supports the following features yet.

change #ifdef tag name

You can change #ifdef to another name such as #iftarget etc. using the IfdefJsConfig like below:

const result = ifdefJs.process_string(
	source, ["target-a"],
	{
		alternative_target_tagname: "def"
	}
)

Set the alternative_target_tagname to a string like "x" will let ifdefJs uses #ifx as #ifdef, #ifnx as #ifndef, while #endif will still be #endif.

const result = ifdefJs.process_string(
	source, ["target-a"],
	{
		alternative_target_tagname: {
			start: "ifdef",
			start_rev: "ifndef"
			end: "endif"
		}
	}
)

You can also set the alternative_target_name to an object that contains start, start_rev, end. In this case, start's value indicates ifdef, start_rev indicates ifndef, end indicates endif. Notice that you should not add # here and the ifdefJs will still need a prefixed #.

Replace texts

You can use IfdefJsConfig.defines to make the ifdefJs find and replace the texts. For example, if you want to change {{version}} to 0.0.1, just set configs like this:

const result = ifdefJs.process_string(
	source, ["target-a"],
	{
		defines: {
			"{{version}}": "0.0.1"
		}
	}
)

You can also set multiple find-and-replace pairs, ifdefJs will find-and-replace them in order. Notice that the find-and-replace cannot find across lines, while match multiple times in one line is supported.

const result = ifdefJs.process_string(
	source, ["target-a"],
	{
		defines: {
			"{{id}}": "my-hp"
			"{{name}}": "My Hypothetical Project",
			"{{version}}": "0.0.1",
			// due to this match string have \n,
			// means it must match across line,
			// but ifdefJs does not supports matches
			// across line, so this find-and-replace
			// pair will never be matched.
			"# my-hp\n": "# My Hypothetical Project\n"
		}
	}
)