Gathering detailed insights and metrics for string-convert-indexes
Gathering detailed insights and metrics for string-convert-indexes
Gathering detailed insights and metrics for string-convert-indexes
Gathering detailed insights and metrics for string-convert-indexes
npm install string-convert-indexes
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (58.83%)
TypeScript (38.92%)
HTML (2.23%)
Shell (0.02%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
201 Stars
8,451 Commits
25 Forks
2 Watchers
1 Branches
3 Contributors
Updated on Jul 09, 2025
Latest Version
6.0.21
Package Id
string-convert-indexes@6.0.21
Unpacked Size
44.38 kB
Size
15.73 kB
File Count
7
NPM Version
10.9.2
Node Version
23.9.0
Published on
Mar 02, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
Convert between native JS string character indexes and grapheme-count-based indexes
This package is pure ESM. If you're not ready yet, install an older version of this program, 4.1.0 (npm i string-convert-indexes@4.1.0
).
1npm i string-convert-indexes
1import { strict as assert } from "assert"; 2 3import { nativeToUnicode, unicodeToNative } from "string-convert-indexes"; 4 5// CONVERTING NATIVE JS INDEXES TO UNICODE-CHAR-COUNT-BASED 6// 𝌆 - \uD834\uDF06 7 8// at index 1, we have low surrogate, that's still grapheme index zero 9assert.equal(nativeToUnicode("\uD834\uDF06aa", "1"), "0"); 10// notice it's retained as string. The same type as input is retained! 11 12// at index 2, we have first letter a - that's second index, counting graphemes 13assert.equal(nativeToUnicode("\uD834\uDF06aa", 3), 2); 14 15// convert many indexes at once - any nested data structure is fine: 16assert.deepEqual(nativeToUnicode("\uD834\uDF06aa", [1, 0, 2, 3]), [0, 0, 1, 2]); 17 18// numbers from an AST-like complex structure are still picked out and converted: 19assert.deepEqual(nativeToUnicode("\uD834\uDF06aa", [1, "0", [[[2]]], 3]), [ 20 0, // notice matching type is retained 21 "0", // notice matching type is retained 22 [[[1]]], 23 2, 24]); 25 26// CONVERTING UNICODE-CHAR-COUNT-BASED TO NATIVE JS INDEXES 27// 𝌆 - \uD834\uDF06 28 29assert.deepEqual(unicodeToNative("\uD834\uDF06aa", [0, 1, 2]), [0, 2, 3]); 30 31assert.deepEqual(unicodeToNative("\uD834\uDF06aa", [1, 0, 2]), [2, 0, 3]); 32 33assert.throws(() => unicodeToNative("\uD834\uDF06aa", [1, 0, 2, 3])); 34// throws an error! 35// that's because there's no character (counting Unicode characters) with index 3 36// we have only three Unicode characters, so indexes go only up until 2
Please visit codsen.com for a full description of the API.
To report bugs or request features or assistance, raise an issue on GitHub.
MIT License.
Copyright © 2010-2025 Roy Revelt and other contributors.
No vulnerabilities found.
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
6 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
no SAST tool detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More