1.0.3 • Published 5 years ago

split-to-chunks v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

split-to-chunks

Splits an array or a string to an array of chunks of the given size

basic usage

const splitToChunks = require('split-to-chunks');
const output = splitToChunks('AABBCC', 2);

console.log(output);
// >> [['A', 'A'], ['B', 'B'], ['C', 'C']]

Example: reverse the pixels from a 3*1 bitmap

// Basic hex data for a 3*1px 24bit image going red, then green and blue
const img = [0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF]

// Reverse the image so it goes blue then green and red
const reversed = splitToChunks(img, 3).reverse()

const output = reversed.reduce((a, c) => {
    c.forEach(piece => a.push(piece))
    return a
}, [])

console.log(output)
// >> [0, 0, 255, 0, 255, 0, 255, 0, 0]
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago