All Projects → pedsmoreira → Jewell

pedsmoreira / Jewell

Licence: mit
Javascript Syntax Sugar for Higher-Order Messaging

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
es6
455 projects

Labels

Projects that are alternatives of or similar to Jewell

Generate Random Web V7.19.03
Projeto para um cliente, afim de automatizar a escolha de números, pois o mesmo é jogador de loterias e queria um sistema para gerar jogos prontos.
Stars: ✭ 19 (-73.61%)
Mutual labels:  array
Geeksforgeeks Dsa 2
This repository contains all the assignments and practice questions solved during the Data Structures and Algorithms course in C++ taught by the Geeks For Geeks team.
Stars: ✭ 53 (-26.39%)
Mutual labels:  array
Pycuda
CUDA integration for Python, plus shiny features
Stars: ✭ 1,112 (+1444.44%)
Mutual labels:  array
Kakajson
Fast conversion between JSON and model in Swift.
Stars: ✭ 867 (+1104.17%)
Mutual labels:  array
Golang Combinations
Golang library which provide an algorithm to generate all combinations out of a given string array.
Stars: ✭ 51 (-29.17%)
Mutual labels:  array
Immutable Array Prototype
A collection of Immutable Array prototype methods(Per method packages).
Stars: ✭ 56 (-22.22%)
Mutual labels:  array
Pyopencl
OpenCL integration for Python, plus shiny features
Stars: ✭ 790 (+997.22%)
Mutual labels:  array
Presento
Presento - Transformer & Presenter Package for PHP
Stars: ✭ 71 (-1.39%)
Mutual labels:  array
Array Unique
Return an array free of duplicate values. Very fast implementation.
Stars: ✭ 51 (-29.17%)
Mutual labels:  array
Array view
Wrapper for references to array in C++.
Stars: ✭ 58 (-19.44%)
Mutual labels:  array
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (-51.39%)
Mutual labels:  array
Pgo
Go library for PHP community with convenient functions
Stars: ✭ 51 (-29.17%)
Mutual labels:  array
Cartesian Product
PHP - A simple, low-memory footprint function to generate all combinations from a multi-dimensionnal array.
Stars: ✭ 58 (-19.44%)
Mutual labels:  array
Shallow Clone
Make a shallow clone of an object, array or primitive.
Stars: ✭ 23 (-68.06%)
Mutual labels:  array
Hibernate Types
The Hibernate Types library gives you extra types that are not supported by the Hibernate ORM core.
Stars: ✭ 1,122 (+1458.33%)
Mutual labels:  array
Array First
Get the first element or first n elements of an array.
Stars: ✭ 6 (-91.67%)
Mutual labels:  array
Zarr.js
Javascript implementation of Zarr
Stars: ✭ 54 (-25%)
Mutual labels:  array
Componentarrays.jl
Arrays with arbitrarily nested named components.
Stars: ✭ 72 (+0%)
Mutual labels:  array
Mjextension
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.
Stars: ✭ 8,458 (+11647.22%)
Mutual labels:  array
Array Sort
Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.
Stars: ✭ 58 (-19.44%)
Mutual labels:  array

Jewell

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';
jewellPrototype(Array);

const diamonds = [...];

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

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

Getting Started

Installation

npm install jewell --save

And to import:

import jewell, {jewellPrototype} from 'jewell';

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

API

  • 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

Examples

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

Mapping attributes

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

Equivalent to fruits.map(fruit => fruit.name).

Mapping the results of functions

const photos = [...];
photos.map.crop(0, 0, 50, 50);

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

Calling function for each array item

const diamonds = [...];
diamonds.forEach.sell();

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 = [...];
employees.filter.retired;

Filtering items with argument

const employees = [...];
employees.filter.compliesTo('rule');

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

Filtering and mapping

const animals = [...];
animals.filter.friendly.map.name;

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

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.

Resources

Motivation

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.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].