New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

uni-preprocessor

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uni-preprocessor

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

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
0
Created
Source

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"
		}
	}
)

FAQs

Package last updated on 07 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts