Skip to content
Javascript Syntax Sugar for Higher-Order Messaging
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Initial commit Sep 19, 2017 Update Oct 10, 2017
tsconfig.json Adding working version and tests Oct 5, 2017


npm version Build Status Code Climate Test Coverage

Jewell leverages the power of ES6 Proxy to provide syntax sugar, allowing you to write cleaner code.

The best way to showcase Jewell is through code samples:

import {jewellPrototype} from 'jewell';

const diamonds = [...];

// Get price: [2k, 100k, 300k]; // 💎 => diamond.price); // Traditional

// Buy all pink diamonds; // 💎
diamonds.filter(diamond => =>; // Traditional

Getting Started


npm install jewell --save

And to import:

import jewell, {jewellPrototype} from 'jewell';

Note: You may need an ES6 Proxy polyfill to support older browsers.


  • jewell(object: object, propertyName: string): Proxies function property. Bear in mind the property must already exist.
  • jewellPrototype(class: object, except: string[]): Proxies all functions with zero or one argument in a class prototype.
  • ._fn: After proxying, the original method can be accessed through ._fn.

⚠ Warning: Be aware that jewell(...) and jewellPrototype(...) replace the original methods with proxies. This package was created for experimental purposes, but if you decide to use it in production, make sure you're not creating unintendend behaviors or performance issues.

Jewelling an instance property

This means only a single instance will be jewelled.

const object = [{name: 'John'}, {name: 'Jane'}];
jewell(object, 'map');

Jewelling a prototype property

This means all instances of a class will the property jewelled.

jewell(Array.prototype, 'map');

Jewelling a class

jewellPrototype(Array, ['shift']); // Proxy functions with one or zero args except 'shift


The examples below expect jewellPrototype(Array) to have been called.

Mapping attributes

const fruits = [{name: 'Apple'}, {name: 'Grape'}];; // ['Apple', 'Grape']

Equivalent to =>

Mapping the results of functions

const photos = [...];, 0, 50, 50);

Equivalent to => photo.crop(0, 0, 50, 50))

Calling function for each array item

const diamonds = [...];

Equivalent to diamonds.forEach(diamond => diamond.sell())

Calling function with argument for each array item

const kittens = [...];
kittens.forEach.feed('fish', 3);

Equivalent to kittens.forEach(kitten => kitten.feed('fish', 3))

Filtering items

const employees = [...];

Filtering items with argument

const employees = [...];

Equivalent to employees.filter(employee => employee.compliesTo('rule'))

Filtering and mapping

const animals = [...];;

Equivalent to animals.filter(animal => animal.friendly).map(animal =>

Checking if all items comply to a rule

const employees = [...];
employees.every.retired; // true or false

Equivalent to employees.every(employee => employee.retired)

Accessing the original method

jewell(array, 'shift');
array.shift._fn // Original method

More examples

If you have some other cool examples, you're very welcome to open a PR.



Jewell is inspired by @franzliedke's implementation of higher-order messaging for Laravel and by Nat Pryce's article on higher-order messaging with Ruby.

Ultimately it would be very nice to have higher-order messaging implemented as a native Javascript feature, but until then, there's Jewell.



You can’t perform that action at this time.