# hasslium

> **This project is still in development, but it's ready to be used in real projects.** Feel free to check it out, feedback is appreciated !

Latest version **1.0.3** (published 2022-12-23) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install hasslium
pnpm add hasslium
yarn add hasslium
bun add hasslium
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-12-23 |
| First published | 2022-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 33.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | fuka-g |
| Maintainers | zekefeu |
| Keywords | preprocessor, compiler, node |

## Links

- npm: https://www.npmjs.com/package/hasslium
- Repository: https://github.com/fuka-g/hasslium
- Issues: https://github.com/fuka-g/hasslium/issues
- npm.io page: https://npm.io/package/hasslium

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2022-12-23

## README

# hasslium: A TS/JS preprocessor based on C's

**This project is still in development, but it's ready to be used in real projects.** Feel free to check it out, feedback is appreciated !

The documentation is under construction, but should be informative enough for now.

**A boilerplate is available to see how to use it ->** [fuka-g/hasslium-boilerplate](https://www.github.com/fuka-g/hasslium-boilerplate)

## Why ?

This preprocessor is mostly useful for:

- Front-end apps
- Commercial apps
- Products you want to make a demo version of

It allows you to include or exclude certain regions of your code (development & debug statements, etc), and to define macros to replace constants you would use all over your project.

It is built around of the C preprocessor's features and syntax to be easy to understand and to provide a steep learning curve.

## Installation

`$ npm install -D hasslium`

## Usage

For now, no CLI support has been added yet. The only way to run it is through a js script file.

The main function takes an array of strings as the input, an `options` object, and a callback

The options object takes a `macros` array (see examples below) to define macros before processing your file.

You can turn the verbose mode on for debugging purposes, even though the messages are pretty cryptic for now.

```ts
export interface processOptions {
	macros?: macroType[];
	verbose?: boolean;
}
```

Here's an example:

```ts
import * as hasslium from "hasslium";
import * as fs from "fs";

const inputArray: string[] = fs
	.readFileSync("yourFilePath.js")
	.toString()
	.split("\n");

// hasslium.process(input: string[], options: processOptions, callback: (error: string, output: string[]))
hasslium.process(
	inputArray,
	{
		macros: [
			["ENV", "dev"],
			["TEST_MACRO", "value"],
		],
		verbose: false,
	},
	(error, output) => {
		if (error) {
			console.error(error);
		} else {
			console.log("Output:", output);
		}
	}
);
```

## Features

- Almost all of the C preprocessor's directives
- Fast
- Tested & strongly typed

## GCC's features

[See the original preprocessor's features.](https://gcc.gnu.org/onlinedocs/cpp/index.html)

## Syntax

All directives must start with `//#` .

- Example: `//# define MACRO token`

You can either use `//# directive` or `//#directive`.

## Directives

### Defining macros

```ts
//# define macro token

//# undef macro
```

### Conditions

Conditional

```ts
//# if macro condition

//# elif macro condition

//# else

//# endif
```

If a macro is defined / undefined

```ts
//# ifdef macro

//# ifndef macro
```

### Diagnostics

```ts
//# warning message

//# error message
```

## Known bugs

- Issue relating to TypeScript: the last line of a file is not included if it is a comment. It includes hasslium directives

## Contributing

Contributions are welcome !

---
_Source: https://npm.io/package/hasslium · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
