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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sweet-js-tools

v0.2.0

Published

A library of simple, practical and efficient JavaScript/TypeScript utilities to streamline JS development.

Downloads

222

Readme

Sweet JS Tools

npm license typescript

A library of practical & reusable utilities designed to streamline everyday development, making JavaScript/TypeScript code cleaner, safer, and more consistent.

Overview ✨

As a tool set, Sweet JS Tools focuses on:

  • ease of use
  • reducing repetitive logic
  • safe defaults (no unexpected crashes)
  • improving code clarity without adding complexity

The library provides a set of tools and common operations for arrays, numbers, objects, strings, and structured data.

tl;dr: Streamline JS/TS development. Practical, simple, easy. ✨

Installation

npm install sweet-js-tools

Contents

🔤 String Tools

Helpers for cleaning, formatting, and transforming text.

  • capitalization and sentence formatting: capitalize, capitalizeText
  • pattern matching and counting: matchCount, wordCount
  • spacing and normalization: trimExtra, normalizeString, normalizeText
  • slug and case conversion: slugMaker, toSnakeCase, toKebabCase
  • symbol handling: removeSymbols, replaceSymbols
  • regex helpers: escapeRegex

Example usage:

capitalizeText("hello. how are you?")
// "Hello. How are you?"

slugMaker("Münchener Straße")
// "munchener-strasse"

wordCount("hello @you 123")
// 3

🏹 Array Tools

Utilities for creating, filtering, sorting & working with arrays.

  • generate sequences from numbers: arrayFromNr, zeroToNumber
  • map and extract object properties: propMap, propMapCull
  • sorting and transformation: sortNumbers, toArray
  • access and selection: arrayLast, randomArrayItem
  • cleanup and structure: removeDuplicates, arrayParts, paginationSlices
  • type-based filtering (Sweet Types): includeType, excludeType, typeOrDefault, typeMatchMap
  • random selection: randomArrayItem
  • pagination helpers: paginationSlices

Example usage:

arrayFromNr(-5, 0)
// [-4, -3, -2, -1, 0]

removeDuplicates([1, 2, 2, 3])
// [1, 2, 3]

🔢 Number Tools

Consistent and predictable number behavior.

  • rounding that works the same for positive and negative values: absValueFloor, absValueCeil
  • safe random number generation: randomNr, randomNr0, randomInRange, randomUpTo, randomBetween
  • decimal precision helpers: floorDecimal, ceilDecimal, roundDecimal
  • number checks and helpers: isOdd, isEven, evenOdd
  • range control: clamp
  • factor utilities: findFactors, findLowestCommonFactor

Example usage:

absValueFloor(-2.1)
// -2 (instead of -3 with Math.floor)

randomInRange(2, 5)
// 2, 3, 4, or 5

📦 Object Tools

Utilities for cleaning, filtering, modifying, and reshaping objects.

  • inspect object entry types: objEntryTypes
  • clean empty or unclear values: fixEmptyVals, fixEmptyX
  • extract cleaned object data: cleanEntries, cleanKeys, cleanValues
  • extract clear object data: clearObjEntries, clearObjKeys, clearObjValues
  • filter object entries: objFilter
  • modify object keys or values: objModKeys, objModVals
  • safely select or exclude keys: objPick, objOmit

Example usage:

fixEmptyVals({
  name: "",
  age: 32,
  city: "Munich"
})
// { age: 32, city: "Munich" }

objModKeys(
  { firstName: "Lina" },
  key => key.toUpperCase()
)
// { FIRSTNAME: "Lina" }

objPick(
  { name: "La", surname: "Gos" },
  ["name", "surname", "age"],
  "unknown"
)
// {
//   name: "La",
//   surname: "Gos",
//   age: "unknown"
// }

🗂️ Data Tools

Detect and parse structured data easily & automatically.

  • detect data formats: stringDataCheck, findDataType
  • JSON detection: isStructuredJSON
  • CSV parsing: splitCSVRow, isCSVString, csvObjectify
  • conversion helpers: csvToJSON, parseData

Example usage:

findDataType('{"name":"Lina"}')
// "json"

parseData("name,age\nLina,32")
// [{ name: "Lina", age: "32" }]

csvObjectify(
  'name,notes\nLina,"likes cats, coffee"'
)
// [
//   {
//     name: "Lina",
//     notes: "likes cats, coffee"
//   }
// ]

csvToJSON("name,age\nLina,32")
// '[{"name":"Lina","age":"32"}]'

🍬 Basic SweetTypes

A lightweight runtime type system designed for plain JavaScript and TypeScript.

Important:
This is the basic/internal SweetTypes layer included with Sweet JS Tools.
It works entirely at runtime and does NOT require TypeScript.

A more advanced standalone Sweet Types system is planned separately.

SweetTypes expands normal JavaScript type checks with:

  • safer runtime validation
  • more specific checks
  • “usable value” detection
  • cleaner handling of common JS edge cases

Includes:

  • base type checks: isString, isNumber, isBoolean, isObject, isArray, isNull, isUndefined, isBigInt, isFunction, isSymbol
  • precision checks: isTrue, isFalse, isNumeric
  • strict/usable checks (XTypes): isStringX, isObjectX, isArrayX, isNumberX, isSymbolX
  • value state helpers: isNullish, isEmptyVal, isClearValue
  • type inspection helpers: findSweetType
  • unified type checking: sweetTypeCheck

Example usage:

isNumeric(" 12 ")
// true

isNumeric(12)
// false

isObject([1, 2])
// false

isArray([1, 2])
// true

findSweetType([1, 2])
// "arrayX"

isClearValue(false)
// false