0.1.0 ā¢ Published 1 year ago
paneer v0.1.0
š§ Paneer
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
- Working parser and code generation with TS support
- Access to comments
- ESM
- Basic syntax support
- Access to the named exports
- Access to imports
- Typescript
- Basic syntax support
- Allow access to type nodes with shortcuts
- Objects
- Iterate over properties
- Assign new properties
- Arrays
- Push literal values
- Iterate and modify elements individually
- Functions
- 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.