6.0.18 • Published 11 months ago

string-convert-indexes v6.0.18

Weekly downloads
42
License
MIT
Repository
github
Last release
11 months ago

Install

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).

npm i string-convert-indexes

Quick Take

import { strict as assert } from "assert";

import { nativeToUnicode, unicodeToNative } from "string-convert-indexes";

// CONVERTING NATIVE JS INDEXES TO UNICODE-CHAR-COUNT-BASED
// 𝌆 - \uD834\uDF06

// at index 1, we have low surrogate, that's still grapheme index zero
assert.equal(nativeToUnicode("\uD834\uDF06aa", "1"), "0");
// notice it's retained as string. The same type as input is retained!

// at index 2, we have first letter a - that's second index, counting graphemes
assert.equal(nativeToUnicode("\uD834\uDF06aa", 3), 2);

// convert many indexes at once - any nested data structure is fine:
assert.deepEqual(nativeToUnicode("\uD834\uDF06aa", [1, 0, 2, 3]), [0, 0, 1, 2]);

// numbers from an AST-like complex structure are still picked out and converted:
assert.deepEqual(nativeToUnicode("\uD834\uDF06aa", [1, "0", [[[2]]], 3]), [
  0, // notice matching type is retained
  "0", // notice matching type is retained
  [[[1]]],
  2,
]);

// CONVERTING UNICODE-CHAR-COUNT-BASED TO NATIVE JS INDEXES
// 𝌆 - \uD834\uDF06

assert.deepEqual(unicodeToNative("\uD834\uDF06aa", [0, 1, 2]), [0, 2, 3]);

assert.deepEqual(unicodeToNative("\uD834\uDF06aa", [1, 0, 2]), [2, 0, 3]);

assert.throws(() => unicodeToNative("\uD834\uDF06aa", [1, 0, 2, 3]));
// throws an error!
// that's because there's no character (counting Unicode characters) with index 3
// we have only three Unicode characters, so indexes go only up until 2

Documentation

Please visit codsen.com for a full description of the API.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License.

Copyright © 2010-2024 Roy Revelt and other contributors.

6.0.18

11 months ago

6.0.17

12 months ago

6.0.16

1 year ago

6.0.15

1 year ago

6.0.14

1 year ago

6.0.13

2 years ago

6.0.12

2 years ago

6.0.11

2 years ago

6.0.10

2 years ago

6.0.7

2 years ago

6.0.9

2 years ago

6.0.8

2 years ago

5.1.6

2 years ago

5.1.5

2 years ago

5.1.4

2 years ago

5.1.3

2 years ago

5.1.2

2 years ago

6.0.6

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.5

2 years ago

6.0.4

2 years ago

5.0.14

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

5.0.13

3 years ago

5.0.10

3 years ago

5.0.11

3 years ago

5.0.12

3 years ago

5.0.7

3 years ago

5.0.6

3 years ago

5.0.5

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.1.0

4 years ago

4.0.16

4 years ago

4.0.15

4 years ago

4.0.14

4 years ago

4.0.13

4 years ago

4.0.12

4 years ago

4.0.11

4 years ago

4.0.10

4 years ago

4.0.9

4 years ago

4.0.8

4 years ago

4.0.7

4 years ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.10.18

4 years ago

1.10.17

4 years ago

1.10.16

4 years ago

1.10.15

4 years ago

1.10.14

4 years ago

1.10.13

5 years ago

1.10.11

5 years ago

1.10.12

5 years ago

1.10.10

5 years ago

1.10.9

5 years ago

1.10.8

5 years ago

1.10.7

5 years ago

1.10.6

5 years ago

1.10.5

5 years ago

1.10.4

5 years ago

1.10.3

5 years ago

1.10.2

5 years ago

1.10.1

5 years ago

1.10.0

5 years ago

1.9.57

5 years ago

1.9.56

5 years ago

1.9.55

5 years ago

1.9.54

5 years ago

1.9.53

5 years ago

1.9.52

5 years ago

1.9.51

5 years ago

1.9.50

5 years ago

1.9.49

5 years ago

1.9.48

5 years ago

1.9.47

5 years ago

1.9.46

5 years ago

1.9.45

5 years ago

1.9.44

5 years ago

1.9.43

5 years ago

1.9.42

5 years ago

1.9.41

5 years ago

1.9.40

5 years ago

1.9.39

5 years ago

1.9.38

5 years ago

1.9.37

5 years ago

1.9.36

5 years ago

1.9.35

5 years ago

1.9.34

5 years ago

1.9.33

5 years ago

1.9.32

5 years ago

1.9.31

5 years ago

1.9.29

5 years ago

1.9.28

5 years ago

1.9.27

5 years ago

1.9.26

6 years ago

1.9.25

6 years ago

1.9.24

6 years ago

1.9.23

6 years ago

1.9.22

6 years ago

1.9.21

6 years ago

1.9.20

6 years ago

1.9.19

6 years ago

1.9.18

6 years ago

1.9.17

6 years ago

1.9.16

6 years ago

1.9.15

6 years ago

1.9.14

6 years ago

1.9.13

6 years ago

1.9.12

6 years ago

1.9.9

6 years ago

1.9.8

6 years ago

1.9.7

6 years ago

1.9.6

6 years ago

1.9.5

6 years ago

1.9.4

6 years ago

1.9.3

6 years ago

1.9.2

6 years ago

1.9.0

6 years ago

1.8.3

6 years ago

1.8.2

6 years ago

1.8.1

6 years ago

1.8.0

6 years ago

1.6.7

6 years ago

1.6.6

6 years ago

1.6.5

6 years ago

1.6.4

6 years ago

1.6.3

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago