# paneer

> [![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]

Latest version **0.1.0** (published 2023-02-13) · MIT license · 0 weekly downloads

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2023-02-13 |
| First published | 2021-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2481 |
| Maintainers | pi0 |

## Links

- npm: https://www.npmjs.com/package/paneer
- Repository: https://github.com/unjs/paneer
- Homepage: https://github.com/unjs/paneer#readme
- Issues: https://github.com/unjs/paneer/issues
- npm.io page: https://npm.io/package/paneer

## Dependencies (3)

- [recast](https://npm.io/package/recast.md) ^0.22.0
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.20.15
- [@types/estree](https://npm.io/package/@types/estree.md) ^1.0.0

## Recent versions

- 0.1.0 (latest) — 2023-02-13
- 0.0.1 — 2021-05-25
- 0.0.0 — 2021-05-25

## README

# 🧀 Paneer

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]

Paneer allows you to programmatically modify JavaScript and Typescript source codes with a simplified, elegant and familiar syntax built on top of the [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) parsed by [recast](https://github.com/benjamn/recast) and [babel](https://babeljs.io/).

**Roadmap:**

🚧 Paneer is currently in the proof of concept state. While underlying parsers are stable, you might need to directly modify underlying AST for unsupported operations in the meantime.

- Generic API
  - [x] Working parser and code generation with TS support
  - [ ] Access to comments
- ESM
  - [x] Basic syntax support
  - [x] Access to the named exports
  - [ ] Access to imports
- Typescript
  - [x] Basic syntax support
  - [ ] Allow access to type nodes with shortcuts
- Objects
  - [x] Iterate over properties
  - [ ] Assign new properties
- Arrays
  - [x] Push literal values
  - [ ] Iterate and modify elements individually
- Functions
  - [x] Access to call expression arguments
  - [ ] Access to function body
  - [ ] Access to function return

## Usage

Install npm package:

```sh
# using yarn
yarn add --dev paneer

# using npm
npm install -D paneer

# using pnpm
pnpm add -D paneer
```

Import utilities:

```js
// ESM / Bundler
import { parseCode, generateCode } from "paneer";
import * as p from "paneer";

// CommonJS
const { parseCode, generateCode } = require("panner");
const p = require("panner");
```

**Example:** Modify a file:

`config.js`:

```js
export default {
  foo: ["a"],
};
```

Code to modify and append `b` to `foo` prop of defaultExport:

```js
import { loadFile, writeFile } from "paneer";

const _module = await loadFile("config.js");

_module.exports.default.props.foo.push("b");

await writeFile(_module);
```

Updated `config.js`:

```js
export default {
  foo: ["a", "b"],
};
```

**Example:** Directly use AST utils:

```js
import { parseCode, generateCode } from "paneer";

// Parse to AST
const _module = parseCode(`export default { foo: ['a'] }`);

// Add a new array member
_module.exports.default.props.foo.push("b");

// Generate code
const { code, map } = generateCode(_module);
```

## Development

- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`

## License

Made with 💛

Published under [MIT License](./LICENSE).

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/paneer?style=flat-square
[npm-version-href]: https://npmjs.com/package/paneer
[npm-downloads-src]: https://img.shields.io/npm/dm/paneer?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/paneer
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/paneer/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/paneer/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/paneer/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/paneer

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