stringr 1.3.0
stringr: ^1.3.0 copied to clipboard
String case conversion (camelCase, snake_case, kebab-case), slugify, remove diacritics (latinize), truncate and count words, with Unicode and grapheme support.
1.3.0 2026 #
Correctness release. The public API is unchanged (no member was removed, renamed or re-typed); the behaviour changes below are bug fixes.
Behaviour changes #
escapeRegExp()puts a single backslash before each regular expression syntax character:\ ^ $ . * + ? ( ) [ ] { } |.'a.b'.escapeRegExp()is nowa\.b(it wasa\\.b, which never matched) andRegExp(text.escapeRegExp())matchestextliterally. Characters that are not regex syntax (- ! < = : # ,) are no longer escaped, so the result also compiles and matches literally withRegExp(..., unicode: true). The output is meant for use outside a character classunescapeRegExp()(and the deprecatedunEscapeRegExp()) is now the true inverse ofescapeRegExp(): it removes one backslash from each backslash pair, so\.becomes.and\\becomes\. It previously stripped every backslash. A lone trailing backslash is kepttranslate()replaces in a single pass over the original string, so replacements no longer cascade ('ab'.translate({'a': 'b', 'b': 'c'})isbc, notcc). Matching is leftmost-longest: at each position the longest matching key wins, so the order of the map no longer matters. Empty keys are ignoredunescapeHtml()decodes in a single pass, so&quot;becomes"instead of"latinize()mapsßtossandẞtoSS(straßewasstrase).slugify()benefits too. All other mappings are unchanged. In the exporteddiacriticsmap the's'entry no longer containsß, and there are new'ss'(ß) and'SS'(ẞ) keystruncate()no longer throws whentruncateLengthis shorter thanendString; it returnsendStringcut totruncateLength('hello world'.truncate(2)is..)splice()no longer throws whendeleteCountruns past the end of the string; it deletes up to the end ('hello'.splice(99, 0, 'X')isX). A hugedeleteCountno longer overflowsfirst(),last(),truncate(),prune(),insert()andsplice()never split a grapheme cluster (surrogate pairs, combining marks, ZWJ emoji,\r\n). Lengths and indices stay UTF-16 code unit based; a cut that would fall inside a cluster moves to the nearest cluster boundary that keeps the result within the requested length (insertputs the text before the cluster,splicewidens the range to whole clusters). Results for text where every grapheme is one code unit are unchanged. A negative length infirst(),last()andprune()returns an empty string instead of throwingcapitalize()anddecapitalize()operate on the first grapheme cluster instead of the first code unit, and so docamelCase(),toPascalCaseandtitleCase(), which use them. This only changes results for words that start with a character outside the Basic Multilingual Plane or with a multi-code-unit grapheme. TheHELLOtoHelloversusmacBooktoMacBookrules are unchangedwords(pattern:)uses aRegExp(or any other non-StringPattern) directly, so its flags are respected. AStringpattern is still compiled withRegExp(pattern). The default behaviour is unchangedtitleCase()lowercases a contraction suffix: a word that directly follows an apostrophe ('or’) that directly follows a letter is lowercased when it is, ignoring case, one ofs,t,d,m,ll,reorve. Soit'sandIT'SbecomeIt's,DON'TbecomesDon't,we'llbecomesWe'llandthey’vebecomesThey’ve. Every other apostrophe behaves as before, soo'neilisO'Neil,l'étéisL'Étéand'tisis'Tis. Apart from the first-grapheme change above, input without apostrophes gives the same output as 1.2.2
Bug Fixes #
words(pattern: RegExp(r'\w+'))returned an empty list because the pattern was rebuilt fromRegExp.toString()
Performance #
- The default word regular expressions used by
words(),titleCase()and the case conversions are compiled once instead of on every call latinize()returns pure ASCII strings as is, without allocating. The fast path is only taken when no ASCII character has a replacement in the lookup tables, so ASCII entries added todiacriticsare still honoured- Added a
benchmark/script (excluded from the published package)
Documentation #
- Restructured the README: question-based sections, an API reference and a "Things to know" section describing the grapheme and code unit behaviour. Examples were checked against the code
- Updated the package description, added
repository,issue_trackerandtopicstopubspec.yaml, and refreshed the example
Tests #
- Added regression tests for every fix above
- Added fixture-backed Unicode regression tests for combining marks, emoji grapheme clusters, Devanagari and Arabic word boundaries, dotted
İ, eszett and acronym-heavy identifiers
1.2.2 2026 #
1.2.1 2025 #
1.2.0 2025 #
New Features #
- Added
unescapeHtml()method to unescape HTML entities - Added
escapeHtml()as the new camelCase version ofescapeHTML() - Added
countOccurrences()with correct spelling - Added convenience getters:
toCamelCase,toSnakeCase,toKebabCase,toTitleCase,toPascalCase
Bug Fixes #
- Fixed malformed regex patterns in
const_regex.dart(JS-style delimiters removed) - Fixed performance bug in
latinize()- maps are now lazily initialized instead of rebuilt on every call - Fixed
prune()to handle tabs and other whitespace, not just spaces - Fixed nullable return types in
words(),chars(),codePoints(),graphemes()
Deprecations (will be removed in 2.0.0) #
escapeHTML()- useescapeHtml()insteadunEscapeRegExp()- useunescapeRegExp()insteadcountOccurences()- usecountOccurrences()instead (typo fix)count()- use.lengthinsteadchars()- use.split('')insteadcodePoints()- use.codeUnitsinsteadcharAt()- usestring[index]insteadlowerCase()- use.toLowerCase()insteadupperCase()- use.toUpperCase()instead
Code Quality #
- Optimized
swapCase()usingStringBufferfor O(n) performance - Made escape character maps
constfor compile-time optimization - Added modern Dart 3.0+ switch expressions in case methods
- Improved code documentation
1.1.0 2025 #
- Updated to Dart 3.0+ with modern SDK constraints (>=3.0.0 <4.0.0)
- Added
unescapeRegExp()method to unescape regex strings - Code refactoring and improved maintainability
- Updated dependencies to latest compatible versions
1.0.0 2021 #
- First stable release
- All string manipulation features from prerelease now stable
0.0.1-prerelease 04/01/2021 #
- Added functionalities either missing from String class.
- Functionalities are inspired from Voca JS.
- escapeRegEx() is not working for certain RegEx strings.
0.0.2-prerelease 04/01/2021 #
- Trying to get full pub score