Skip to content

feat(text, collections): Added missing functions for collections and text modules#7229

Open
hey-amanthakur wants to merge 19 commits into
denoland:mainfrom
hey-amanthakur:feat/add-common-missing-functions
Open

feat(text, collections): Added missing functions for collections and text modules#7229
hey-amanthakur wants to merge 19 commits into
denoland:mainfrom
hey-amanthakur:feat/add-common-missing-functions

Conversation

@hey-amanthakur

Copy link
Copy Markdown

Added groupBy, shuffle, range, difference, flatten, countBy

  • groupBy(array, keyFn): Groups elements by a key function into a
    Record<K, T[]>. The most requested collection utility across all
    ecosystems (Lodash, Kotlin, etc.).

  • shuffle(array): Returns a new array with elements randomly permuted
    using the Fisher-Yates algorithm. Does not mutate the input.

  • range(startOrEnd, end?, {step?}): Generates a sequence of numbers
    from start (default 0) up to but not including end. Auto-detects
    direction (ascending/descending) when step is omitted.

  • difference(a, b): Returns elements present in array a but not in
    array b. Uses a Set for O(n) lookup performance.

  • flatten(array): Flattens an array of arrays one level deep into a
    single array. Does not perform recursive deep flattening.

  • countBy(array, keyFn): Counts occurrences of each key returned by
    the key function, returning a Record<K, number>.


Added capitalize, stripAnsi, isAlpha, isNumeric, isAlphanumeric, escapeHtml, unescapeHtml

  • capitalize(input): Capitalizes the first character and lowercases
    the rest of the string.

  • stripAnsi(input): Removes ANSI escape codes from terminal strings
    using a comprehensive regex covering SGR, cursor, and control sequences.

  • isAlpha(input): Checks if a string contains only ASCII alphabetic
    characters (A-Z, a-z).

  • isNumeric(input): Checks if a string contains only ASCII numeric
    characters (0-9).

  • isAlphanumeric(input): Checks if a string contains only ASCII
    alphanumeric characters (A-Z, a-z, 0-9).

  • escapeHtml(input): Escapes HTML special characters (&, <, >, ", ')
    using named and numeric character references.

  • unescapeHtml(input): Reverses HTML entity escaping, converting
    named entities and numeric references back to original characters.

hey-amanthakur and others added 17 commits July 10, 2026 21:07
Groups elements of an array by a key returned by the given function.
Returns a Record mapping each key to an array of matching elements.
Returns a new array with elements randomly shuffled using the
Fisher-Yates algorithm. Does not mutate the original array.
Generates an array of numbers progressing from start up to but not
including end, with an optional step value. Supports ascending and
descending ranges via auto-detection or explicit step option.
Returns elements present in the first array but not in the second.
Uses a Set for O(n) lookup performance.
Flattens an array of arrays one level deep into a single array.
Does not perform deep recursive flattening.
Counts occurrences of each key returned by the given function.
Returns a Record mapping each unique key to its count.
Adds 6 new function exports to the collections package:
groupBy, shuffle, range, difference, flatten, countBy
Capitalizes the first character of a string and converts the rest to lowercase.
Removes ANSI escape codes from a string using a comprehensive regex
pattern that covers SGR codes, cursor movements, and other terminal
control sequences.
Checks if a string contains only alphabetic ASCII characters (A-Z, a-z).
Checks if a string contains only numeric ASCII characters (0-9).
Checks if a string contains only alphanumeric ASCII characters (A-Z, a-z, 0-9).
Escapes HTML special characters: & < > " and single quote.
Uses named entities for &, <, >, " and the &denoland#39; numeric entity for single quote.
Reverses HTML entity escaping, converting named entities and numeric
character references back to their original characters.
Adds 7 new function exports to the text package:
capitalize, stripAnsi, isAlpha, isNumeric, isAlphanumeric,
escapeHtml, unescapeHtml
feat(collections): add groupBy, shuffle, range, difference, flatten, countBy
feat(text): add capitalize, stripAnsi, isAlpha, isNumeric, isAlphanumeric, escapeHtml, unescapeHtml
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.01%. Comparing base (ad7c87b) to head (0d81869).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7229    +/-   ##
========================================
  Coverage   95.00%   95.01%            
========================================
  Files         617      621     +4     
  Lines       51674    51472   -202     
  Branches     9326     9291    -35     
========================================
- Hits        49093    48905   -188     
+ Misses       2038     2029     -9     
+ Partials      543      538     -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hey-amanthakur hey-amanthakur changed the title Added missing functions for collections and text modules feat(text, collections): Added missing functions for collections and text modules Jul 10, 2026
@babiabeo

babiabeo commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Thanks for drafting this. Here's my feedback:

collections:
- groupBy: superseded by Object.groupBy()
- shuffle: redundant with @std/random/shuffle
- difference: superseded by Set.difference()
- flatten: superseded by Array.flat()

text:
- capitalize: redundant with toPascalCase/toSentenceCase/toTitleCase
- stripAnsi: redundant with @std/fmt/colors/stripAnsiCode
- escapeHtml/unescapeHtml: redundant with @std/html
@hey-amanthakur

Copy link
Copy Markdown
Author

Hi @babiabeo,

Thank you for taking the time to review my PR. I've made the requested changes, could you please take another look when you have a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants