This package has been deprecated

Author message:

Please migrate to https://github.com/unjs/magicast

paneer
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

🧀 Paneer

npm version npm downloads Github Actions Codecov

Paneer allows you to programmatically modify JavaScript and Typescript source codes with a simplified, elegant and familiar syntax built on top of the AST parsed by recast and babel.

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:

# using yarn
yarn add --dev paneer

# using npm
npm install -D paneer

# using pnpm
pnpm add -D paneer

Import utilities:

// 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:

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

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

import { loadFile, writeFile } from "paneer";

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

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

await writeFile(_module);

Updated config.js:

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

Example: Directly use AST utils:

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
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with 💛

Published under MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i paneer

Weekly Downloads

969

Version

0.1.0

License

MIT

Unpacked Size

17.1 kB

Total Files

6

Last publish

Collaborators

  • pi0