npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

array-mixer

v0.7.3

Published

ArrayMixer is a simple function to reorder a group of arrays in the way you want.

Downloads

29

Readme

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:

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 | |-----------------------|-----------------------|-----------------------------------|------------------------------------------------------------------------------| | [:dog:, :dog:, :dog:] | [:cat:, :cat:, :cat:] | [:penguin:, :penguin:, :penguin:] | [:dog:, :cat:, :penguin:, :dog:, :cat:, :penguin:, :dog:, :cat:, :penguin:] |

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

Coming soon

License

MIT - Jota Teles - 2017

Special thanks