@deveko/utils
v1.3.0
Published
Lightweight utility functions for every day JavaScript tasks
Maintainers
Readme
@deveko/utils
Lightweight utility functions for everyday JavaScript tasks. Built and maintained by Deveko.
🚀 Installation
npm install @deveko/utilsUsage
ESM
import { string, number } from "@deveko/utils";
console.log(string.kebabCase("Yoooo Whats up my-';'.'.'.'.|bro"));
// yoooo-whats-up-my-bro
console.log(number.gcd(101, 10));
// 1
console.log(array.chunk([1, 2, 3, 4, 5], 2));
// [[1,2],[3,4],[5]]
const users = [
{ name: "Alice", age: 25 },
{ name: "Bob" }, // age missing
{ name: "Charlie", age: 28 },
];
console.log(array.pluck(users, "name"));
// ["Alice", "Bob", "Charlie"]
console.log(array.compact([false, null, 0, "", undefined, NaN, "hello", 42]));
// ['hello', 42]CJS
const { string, number } = require("@deveko/utils");
console.log(string.kebabCase("Yoooo Whats up my-';'.'.'.'.|bro"));
// yoooo-whats-up-my-bro
console.log(number.gcd(101, 10));
// 1
console.log(array.chunk([1, 2, 3, 4, 5], 2));
// [[1,2],[3,4],[5]]
const users = [
{ name: "Alice", age: 25 },
{ name: "Bob" }, // age missing
{ name: "Charlie", age: 28 },
];
console.log(array.pluck(users, "name"));
// ["Alice", "Bob", "Charlie"]
console.log(array.compact([false, null, 0, "", undefined, NaN, "hello", 42]));
// ['hello', 42]🔧 Available Functions
string
capitalize(str)→ makes the first letter uppercase, rest lowercasecamelCase(str)→ converts "hello world_test" → "helloWorldTest"kebabCase(str)→ converts "Hello World" → "hello-world"truncate(str, length)→ shortens a string with "..." if too long
number
isEven(num)→ Returns true if a number is even.isOdd(num)→ Returns true if a number is odd.clamp(num, min, max)→ Restricts a number to stay within a given range.toFixed(num, decimals)→ Rounds a number to a specified number of decimal places.roundToNearest(num, step)→ Rounds a number to the nearest multiple of a given step.randomInt(min, max)→ Returns a random integer between min and max (inclusive).randomFloat(min, max)→ Returns a random decimal number between min and max.average(...nums)→ Calculates the average of multiple numbers.sum(...nums)→ Calculates the sum of multiple numbers.gcd(a, b)→ Returns the greatest common divisor (HCF) of two numbers.lcm(a, b)→ Returns the least common multiple of two numbers.factorial(n)→ Returns the factorial of a non-negative integer.isPrime(n)→ Returns true if a number is prime.
array
first(arr)→ Returns the first element of an array.last(arr)→ Returns the last element of an array.flatten(arr)→ Flattens nested arrays into a single-level array.unique(arr)→ Removes duplicate values from an array.chunk(arr, size)→ Splits an array into smaller arrays of given size.shuffle(arr)→ Randomly shuffles the elements of an array.sumArray(arr)→ Returns the sum of all numbers in an array.contains(arr, value)→ Checks if an array contains a value.remove(arr, value)→ Removes all occurrences of a value from an array.pluck(arr, key)→ Extracts a property from objects in an array.range(start, end, step)→ Creates an array of numbers from start up to (but not including) end, stepping by step.compact(arr)→ Removes all falsy values (false, 0, '', null, undefined, NaN) from an array.intersection(arr1, arr2)→ Returns a new array of values that appear in both input arrays.difference(arr1, arr2)→ Returns values from arr1 that are not present in arr2.sortNumeric(arr, order)→ Sorts an array of numbers in ascending or descending order.
📦 Versioning
This project follows Semantic Versioning.
PATCHBug fixed only (1.0.11.0.2).MINORBackward-compatible new features (1.0.01.1.0).MAJORBreaking changes (1.0.02.0.0).
🫱🏽🫲🏽 Contributing
NOT AVAILABLE YET
📜 License
MIT © 2025 Deveko
📝 CHANGELOG.md
# Changelog
All notable changes to this project will be documented here.
## 1.3.0 - 2025-08-23
- Added Array utilities
- Added `first` function
- Added `last` function
- Added `flatten` function
- Added `unique` function
- Added `chunk` function
- Added `shuffle` function
- Added `sumArray` function
- Added `contains` function
- Added `remove` function
- Added `pluck` function
- Added `range` function
- Added `compact` function
- Added `intersection` function
- Added `difference` function
- Added `sortNumeric` function
## 1.2.0 - 2025-08-23
- Added Number utilities
- Added `isEven` function
- Added `isOdd` function
- Added `clamp` function
- Added `toFixed` function
- Added `roundToNearest` function
- Added `randomInt` function
- Added `randomFloat` function
- Added `average` function
- Added `sum` function
- Added `gcd` function
- Added `lcm` function
- Added `factorial` function
- Added `isPrime` function
## 1.1.2 - 2025-08-23
- Edited `README.md` and `CHANGELOG.md`
## 1.1.1 - 2025-08-23
- Fixed error by renaming `commonjs` files to use `.cjs`
## 1.1.0 - 2025-08-23
- Removed `isEven` function
- Removed `chunk` function
- Added `camelCase` function
- Added `kebabCase` function
- Added `truncate` function
- Refactored Package folder structure
- Added support for both `commonjs` and `ESM`
## 1.0.1 - 2025-08-22
- Edited `README.md` and `CHANGELOG.md`
## 1.0.0 - 2025-08-22
- Initial release 🚀
- Added `capitalize` function
- Added `isEven` function
- Added `chunk` function