, a 1-minute read
handyscript: the helpers javascript left out
What handyscript adds to JavaScript's own built-ins, the ten sorts it carries, and the HashMap and Matrix it brings, with the code to show it.
handyscript started as the helpers I kept rewriting in every project: chunk an array, shuffle it, a random integer in a range. In 2023 I put them in one npm package, written with two other developers, with tests for every module.
on the built-ins
Import it once, and JavaScript's own built-ins grow:
import "handyscript";
[1, 2, 3, 4, 5, 6, 7].chunk(3); // [[1, 2, 3], [4, 5, 6], [7]]
[5, 3, 1, 4].shuffle().bubbleSort(); // [1, 3, 4, 5]
Math.randomInt(1, 10); // a whole number from 1 to 10
"hello world".toCamelCase(); // "helloWorld"
(1000).toHuman(); // "1K"Each part also comes alone, handyscript/lib/math or handyscript/lib/string, and the whole library ships as one file for a script tag, on jsDelivr and unpkg.
sorting, ten ways
Arrays carry ten sort algorithms, from bubble and insertion sort to merge, quick, heap, shell, bucket, counting and radix, and binarySearch takes the one to sort with before it searches.
new structures
import { HashMap, Matrix } from "handyscript";
const flags = new HashMap({ isMarried: true, isStudent: true, age: 20 });
flags.getKeysByValue(true); // ["isMarried", "isStudent"]
const a = new Matrix([[1, 2, 3], [4, 5, 6]]);
const b = new Matrix([[1, 2], [3, 4], [5, 6]]);
Matrix.multiply(a, b).log();what I'd do differently
It extends the built-ins themselves, Array.prototype and Math. That's what makes it handy, and it's also why a year later my next library, toothscript, made its first rule no global pollution.
First published on Medium, 25 June 2023; rewritten here, 24 November 2026. The original, on Medium