Skip to content

Commit

Permalink
feat: (string.ts) Add chunk()
Browse files Browse the repository at this point in the history
  • Loading branch information
dperuo authored Aug 21, 2024
1 parent 017b2a2 commit c0caa0f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/fns/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ export const uppercase = (x: string) => x.toUpperCase();

/** Removes all whitespace and line terminators around a string. Same as `x.trim()`. */
export const trim = (x: string) => x.trim();

/** Returns `text` as a string broken into chunks of `size`, separated by spaces. */
export const chunk = (size: number) => (text: string): string => (text.match(new RegExp(`.{1,${size}}`, 'g')) ?? []).join(' ');

0 comments on commit c0caa0f

Please sign in to comment.