1 | # reqjs
|
2 |
|
3 | [![NPM version](https://img.shields.io/npm/v/reqjs.svg?style=flat)](https://npmjs.com/package/reqjs) [![NPM downloads](https://img.shields.io/npm/dm/reqjs.svg?style=flat)](https://npmjs.com/package/reqjs) [![CircleCI](https://circleci.com/gh/egoist/reqjs/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/reqjs/tree/master) [![codecov](https://codecov.io/gh/egoist/reqjs/branch/master/graph/badge.svg)](https://codecov.io/gh/egoist/reqjs)
|
4 | [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate)
|
5 |
|
6 | ## Install
|
7 |
|
8 | ```bash
|
9 | yarn add reqjs
|
10 | ```
|
11 |
|
12 | CDN: [UNPKG](https://unpkg.com/reqjs/dist/) | [jsDelivr](https://cdn.jsdelivr.net/npm/reqjs/dist/)
|
13 |
|
14 | ## Usage
|
15 |
|
16 | ```js
|
17 | const req = require('reqjs')
|
18 |
|
19 | const life = req(`module.exports = () => 42`)
|
20 |
|
21 | life() === 42 // true
|
22 | ```
|
23 |
|
24 | ## Gotchas
|
25 |
|
26 | This is not really a CommonJS spec implementation, the code you `req` only supports `module.exports` and `exports`, you **cannot** use `require` inside the code!
|
27 |
|
28 | The primary use case is that I want to evaluate a piece of user-supplied code, and allowing user to specify what I need using `module.exports` syntax. (Note that this may be **dangerous**!)
|
29 |
|
30 | ## Contributing
|
31 |
|
32 | 1. Fork it!
|
33 | 2. Create your feature branch: `git checkout -b my-new-feature`
|
34 | 3. Commit your changes: `git commit -am 'Add some feature'`
|
35 | 4. Push to the branch: `git push origin my-new-feature`
|
36 | 5. Submit a pull request :D
|
37 |
|
38 |
|
39 | ## Author
|
40 |
|
41 | **reqjs** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
|
42 | Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/reqjs/contributors)).
|
43 |
|
44 | > [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@rem_rin_rin](https://twitter.com/rem_rin_rin)
|