https://github.com/amio/require-cjs-string
Load commonjs module from string in Node & Browser.
https://github.com/amio/require-cjs-string
cjs commonjs module parser require
Last synced: 12 months ago
JSON representation
Load commonjs module from string in Node & Browser.
- Host: GitHub
- URL: https://github.com/amio/require-cjs-string
- Owner: amio
- Created: 2018-04-27T03:21:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-04T05:55:45.000Z (almost 8 years ago)
- Last Synced: 2025-02-27T18:58:39.621Z (about 1 year ago)
- Topics: cjs, commonjs, module, parser, require
- Language: JavaScript
- Homepage:
- Size: 43.9 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# require-cjs-string [![npm-version][npm-badge]][npm-link]
Dynamic eval commonjs/umd module from string in Node & Browser.
## Install
```bash
npm install require-cjs-string
```
## Usage
```javascript
const rcs = require('require-cjs-string')
rcs('module.exports = 1') // => 1
```
More Examples:
```javascript
const rcs = require('require-cjs-string')
const { sqrt, square } = rcs(`
exports.sqrt = Math.sqrt;
exports.square = x => x * x;
`)
square(12) // => 144
sqrt(36) // => 6
const fn = rcs(`
module.exports = (x, y) => {
var z = x + y;
return z * z * z;
}
`)
fn(3, 4) // => 343
```
## License
MIT @ Amio
[amio-link]: https://github.com/amio
[npm-badge]: https://img.shields.io/npm/v/require-cjs-string.svg?style=flat-square
[npm-link]: http://www.npmjs.com/package/require-cjs-string