Skip to content

Commit

Permalink
Merge pull request #19 from tough-griff/typescript
Browse files Browse the repository at this point in the history
Typescript refactor
  • Loading branch information
tough-griff authored Apr 26, 2021
2 parents da0b59f + 8f85fd1 commit 478fea4
Show file tree
Hide file tree
Showing 19 changed files with 1,831 additions and 860 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: Test

on:
push:
branches:
- main
branches: [main]
pull_request:
branches:
- main
branches: [main]

env:
CI: true
Expand All @@ -18,7 +16,7 @@ jobs:
strategy:
matrix:
os: [macOS-latest, ubuntu-latest, windows-latest]
node-version: [10.x, 12.x, 14.x]
node-version: [12, 14, 16]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.nyc_output/
coverage/
lib/
node_modules/

*.tsbuildinfo
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
23 changes: 17 additions & 6 deletions .noderc.example → .noderc.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/** @typedef {import("vm").Context} Context */

const chalk = require('chalk');
const _ = require('lodash'); // eslint-disable-line import/no-extraneous-dependencies
const _ = require('lodash');

/**
* Default value callback, returns a number based on index, starting with 1.
Expand All @@ -25,9 +25,20 @@ const defaultKeyCb = (n) => String.fromCharCode(96 + (n + 1));
* @param {Context} context
*/
const init = (context) => {
const lodash = _.runInContext(context);

Object.defineProperties(context, {
Array: {
value: Array,
},
_: {
value: _.runInContext(context),
value: lodash,
},
lodash: {
value: lodash,
},
Object: {
value: Object,
},
});
};
Expand All @@ -44,7 +55,7 @@ module.exports = function configure(repl) {
init(repl.context);
repl.on('reset', init);

Object.defineProperty(Array, 'toy', {
Object.defineProperty(repl.context.Array, 'toy', {
/**
* Generates an array of length `n` with values generated by the provided
* callback.
Expand All @@ -54,11 +65,11 @@ module.exports = function configure(repl) {
* @returns {T[]}
*/
value: function toy(n = 10, valCb = defaultValCb) {
return _.times(n, valCb);
return repl.context._.times(n, valCb);
},
});

Object.defineProperty(Object, 'toy', {
Object.defineProperty(repl.context.Object, 'toy', {
/**
* Generates an object with `n` key value pairs. Each key and value is
* generated by a provided callback.
Expand All @@ -72,7 +83,7 @@ module.exports = function configure(repl) {
const keyArray = Array.toy(n, keyCb);
const valArray = Array.toy(n, valCb);

return _.zipObject(keyArray, valArray);
return repl.context._.zipObject(keyArray, valArray);
},
});
};
File renamed without changes.
2 changes: 1 addition & 1 deletion .noderc.test → .noderc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (repl) => {
assert.ok(repl instanceof REPLServer);
console.log('PASS');
} catch (err) {
console.error('FAIl');
console.error('FAIL');
console.error(err);
}
};
File renamed without changes.
File renamed without changes.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = (repl) => {
};
```

See [_.noderc.example_](https://github.com/tough-griff/rrepl/blob/main/.noderc.example)
See [_.noderc.example.js_](https://github.com/tough-griff/rrepl/blob/main/.noderc.example.js)
as a sample of what you can do with `rrepl`!

### NODE_OPTIONS
Expand All @@ -44,3 +44,15 @@ env NODE_OPTIONS="--experimental-repl-await" rrepl
```

to enable top-level await keyword support.

## Programmatic Usage

Furthermore, you can programmatically create a repl with the following:

```js
import { createRepl } from 'rrepl';
// or
const { createRepl } = require('rrepl');

const repl = await createRepl();
```
100 changes: 0 additions & 100 deletions index.js

This file was deleted.

Loading

0 comments on commit 478fea4

Please sign in to comment.