All Projects → teles → array-mixer

teles / array-mixer

Licence: MIT License
Powerful, super tiny and easy to use lib to reorder your javascript arrays.

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to array-mixer

Morphism
⚡ Type-safe data transformer for JavaScript, TypeScript & Node.js.
Stars: ✭ 336 (+950%)
Mutual labels:  functional, array
Param.macro
Partial application syntax and lambda parameters for JavaScript, inspired by Scala's `_` & Kotlin's `it`
Stars: ✭ 170 (+431.25%)
Mutual labels:  babel, functional
Moses
Utility library for functional programming in Lua
Stars: ✭ 541 (+1590.63%)
Mutual labels:  functional, array
linqjs
Perform queries on collections in the manner of C#s System.Linq in JavaScript
Stars: ✭ 14 (-56.25%)
Mutual labels:  functional, array
Babel Plugin Partial Application
[DEPRECATED] Please use https://github.com/citycide/param.macro
Stars: ✭ 60 (+87.5%)
Mutual labels:  babel, functional
ustd
Micro-standard-library providing minimal and portable array, queue and map for attiny avr, arduinos, esp8266/32 and linux, mac
Stars: ✭ 14 (-56.25%)
Mutual labels:  functional, array
Algorithms
✨ a bunch of algorithms in a bunch of languages ✨
Stars: ✭ 55 (+71.88%)
Mutual labels:  array
mimsa
small programming language. pls be gentle.
Stars: ✭ 23 (-28.12%)
Mutual labels:  functional
react-full-stack-starter
🎈Full-stack React boilerplate using `create-react-app`, Babel, Node.js, and express
Stars: ✭ 22 (-31.25%)
Mutual labels:  babel
babel-plugin-source-map-support
A Babel plugin which automatically makes stack traces source-map aware
Stars: ✭ 41 (+28.13%)
Mutual labels:  babel
node-starter-kit
Node.js / GraphQL project template pre-configured with TypeScript, PostgreSQL, login flow, transactional emails, unit tests, CI/CD workflow.
Stars: ✭ 76 (+137.5%)
Mutual labels:  babel
Swiftz-Validation
A data structure for validations. It implements the applicative functor interface
Stars: ✭ 15 (-53.12%)
Mutual labels:  functional
validation
Validation in Ruby objects
Stars: ✭ 18 (-43.75%)
Mutual labels:  functional
babel-plugin-transform-replace-expressions
A Babel plugin for replacing expressions with other expressions
Stars: ✭ 23 (-28.12%)
Mutual labels:  babel
snabbdom-pragma
'NotReact.createElement' jsx pragma although for snabbdom
Stars: ✭ 47 (+46.88%)
Mutual labels:  babel
array-api-comparison
Data and tooling to compare the API surfaces of various array libraries.
Stars: ✭ 46 (+43.75%)
Mutual labels:  array
starbase
⭐ Production-ready website boilerplate made with webpack 5, modern JS (via Babel 7) & Sass
Stars: ✭ 70 (+118.75%)
Mutual labels:  babel
php-traits
A collection of (more or less) useful traits for PHP7.2+
Stars: ✭ 17 (-46.87%)
Mutual labels:  array
ignite-reactjs
Projetos desenvolvidos em ReactJS durante a trilha de ReactJS do Ignite da Rocketseat. 💜🚀
Stars: ✭ 20 (-37.5%)
Mutual labels:  babel
react-stateful-component
Functional stateful React components with sideEffect support
Stars: ✭ 19 (-40.62%)
Mutual labels:  functional


Logo ArrayMixer

This repository contains the ArrayMixer source code. ArrayMixer is a tiny javascript lib with less than 1kb made to help ordering groups of arrays in a very personalized manner. Powerful and easy to use.

Table of contents

Common usage

Let's think we have two arrays: photos and ads.

photos.length === 12; // true
ads.length === 6; // true

Use ArrayMixer to create a new array containing 2 photos followed by 1 ad until the end of both arrays.

let mixedArray = ArrayMixer({P:photos, A:ads}, ["2P", "1A"]);

So mixedArray will contain:

Installation

ArrayMixer can be used in node projects and web projects.

Node projects

Requires node version 5.7 or later.

npm install array-mixer --save

Import it to your code using:

const ArrayMixer = require("array-mixer");

Web projects

Download latest ES5 transpiled version from unpkg.com.

Import ES5 transpiled version to your code.

<script src="https://unpkg.com/[email protected]/release/array-mixer.js"></script>

Parameters

ArrayMixer has only two mandatory parameters.

let aliases = {M:myArray, O:otherArray};
let sequence = ["3M", "5O"];

let mixed = ArrayMixer(aliases, sequence);

Aliases

This parameter should be an object with keys used as alias for sequence and key values pointing to avaliable arrays.

Sequence

This parameters uses the aliases defined on aliases parameter to create a sequence order to display the arrays.

Examples

ArrayMixer can be used combining different arrays, aliases and sequences. The following examples shows some ways to use it.

Example 1) For every 7 photos display an ad:

ArrayMixer({F: Photos, A: Ads}, ["7P", "1A"]);

or (as number 1 on sequence can be ommited):

ArrayMixer({F: Photos, A: Ads}, ["7P", "A"]);

Example 2) For every 4 paragraphs of text include 2 images:

ArrayMixer({P: paragraphs, I: images}, ["4P", "2I"]);

Example 3) In a group of 8 related links reserve positions 5 and 6 for sponsored links:

ArrayMixer({R: related, S: sponsored}, ["4R", "2S", "2R"]);

Example 4) Display a list of songs including the most successful songs for every 10 songs:

ArrayMixer({M: musics, H: hits}, ["10M", "2H"]);

Example 5) You can also use larger aliases and the ES6 object shorthand:

ArrayMixer({days, weekend}, ["5days", "2weekend"]);

You can manipulate more than two vectors at a time, as in the following example:

Example 6) View photos of puppies, kittens and penguins in sequence:

let mixed = ArrayMixer({puppies, kittens, penguins}, ["puppies", "kittens", "penguins"));
puppies kittens penguins mixed
[🐶, 🐶, 🐶] [🐱, 🐱, 🐱] [🐧, 🐧, 🐧] [🐶, 🐱, 🐧, 🐶, 🐱, 🐧, 🐶, 🐱, 🐧]

Example 7) Include 1 large photo for every 2 medium size photos followed by 3 small photos:

Tip: ArrayMixer lets you mix three or more arrays at once.

ArrayMixer({L:large, M:medium, S:small}, ["2M", "3S", "L"]);

Disclaimer: All arrays mentioned in this section must exist for the examples to work.

More examples

For more example please check the specification file.

Contributing

You may contribute in several ways like creating new features, fixing bugs, improving documentation and examples or translating any document here to your language. Find more information in CONTRIBUTING.md.

License

MIT - Jota Teles - 2017

Special thanks

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].