Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→array-group-str-omit-num-charnext

array-group-str-omit-num-char6.2.1

Groups array of strings by omitting number characters

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — GROUPSTR()
  • API — VERSION
  • API — TYPES
  • Changelog

Installation

Quick Take

Examples

  • Use a custom wildcard in grouped patterns
  • Count duplicate strings instead of deduplicating them
  • Preserve numeric chunks that stay constant across a group
  • Keep strings that contain no numeric chunks

Purpose

When we use atomic CSS in email templates, we generate around ten thousand CSS styles and email-comb removes 99% of them, every unused class.

The challenge is, how do we report what was removed? We can’t list tens of thousands of CSS class names!

For example, consider this array atomic CSS class names coming from some report (for example, email-comb output object’s key deletedFromHead):

["wbr425-padding-top-1", "wbr425-padding-top-2", "main-title", "wbr425-padding-top-3"];

This npm library groups strings, in this case producing:

{
  "wbr425-padding-top-*": 3,
  "main-title": 1
}

Notice the “425″ in wbr425 (meaning width-breakpoint-425) was not replaced with a wildcard because it was constant on all input strings. This feature, retaining constant digits, was the reason why we got into hassle producing this library.

You see, the quickest, alternative algorithm is to replace all digits with ”*“ and filter the unique values, but ”425“ in wbr425 would be lost. That’s why we need this library.

API — groupStr()

The main function groupStr() is imported like this:

It is a function which takes two arguments: an array of zero or more strings and an optional options object:

The optional options object has the following shape:

KeyTypeDefaultDescription
wildcard
Type: String
Default: *
wildcardString*What to use to mark grouped characters
dedupePlease
Type: Boolean
Default: true
dedupePleaseBooleantrueBy default, input array’s contents will be deduped. But that’s at a cost of performance, so if you’re 100% sure your strings will be unique, set it to false.

Here are all defaults in one place for copying:

The function returns a plain object where each key is a grouped string and value is count, for example:

{
  "a*-*": 2,
  "b3-3": 1,
  "c4-4": 1
}

API — version

You can import version:

API — types

This package is written in TypeScript and exports the following types:

TypeDescription
MappingObj
Type: MappingObj
MappingObjWhat groupStr() returns — keys are the grouped, wildcard-bearing strings, values are the arrays of originals behind each.
Opts
Type: Opts
OptsThe Optional Options Object of groupStr(), documented above.
Range
Type: Range
RangeA single range, re-exported from ranges-apply.
Ranges
Type: Ranges
RangesZero or more Ranges, or null, re-exported from ranges-apply.
import type { MappingObj, Opts, Range, Ranges } from "array-group-str-omit-num-char";

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab