Augment JavaScript arrays with Ruby array methods, using Proxies
Branch: master
Clone or download
Latest commit 76186c9 Feb 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
methods Add esdoc comments for .each() method Feb 18, 2019
public Add override CSS to hide redundant sidebar links Jan 31, 2019
scripts Pass babel options directly instead of defining in .babelrc Feb 16, 2019
.editorconfig Add .editorconfig Jan 25, 2019
.esdoc.json
.eslintrc Turn off eslint multiline-comment-style rule Jan 31, 2019
.gitignore
.travis.yml Add .travis.yml Jan 25, 2019
ava.config.js Update test files config in ava.config.js Jan 25, 2019
index.js Add .each() method to proxy handlers Feb 18, 2019
license Replace copyright holder in license to Uncaught Exception Feb 12, 2019
package-lock.json Remove @babel/cli from devDependencies Feb 16, 2019
package.json Update lint-staged command to only lint staged JS files Feb 17, 2019
readme.md
tests.js Fix failing test related to concordance.compare rules Jan 28, 2019

readme.md

rbjs

Augment JavaScript arrays with Ruby array methods, using Proxies.

Installation

This package is not in npmjs.org yet, so for now it can be installed directly from this repository.

$ npm install https://github.com/uncaughtxcptn/rbjs

Usage

For complete documentation, visit https://rbjs.uncaughtexception.wtf/.

To load the entire rbjs library, which includes all the available methods:

import rbjs from 'rbjs';

In order to use Ruby array methods on JavaScript arrays, the array needs to be proxied by passing it to the rbjs function.

const array = rbjs([1, 2, 3]);
// `array` now contains all the implemented Ruby array methods

array.count(2); // => 1

Using individual methods

The methods can also be used on their own, without importing the entire rbjs library. This is done by importing the method definition directly.

import count from 'rbjs/methods/count';

count([1, 2, 3], 2); // => 1

The caveat of using rbjs this way is that the array to operate on needs to be passed as the first argument to the method being used.

ES5 build

If you want to use the ES5 build of this library, they can be imported from the es5 subdirectory.

const rbjs = require('rbjs/es5');
const count = require('rbjs/es5/methods/count');

Contributing

Thanks for wanting to contribute to this project! Please follow these steps:

  1. Open an issue in this repository about the contribution to be made
  2. Fork and clone this repository
  3. Install dependencies (npm install)
  4. Add your contributions ❤️
  5. Write tests for your added contributions
  6. Open a pull request to this repository

License

MIT License