generated from ehmicky/template-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.d.ts
38 lines (38 loc) · 1.09 KB
/
main.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Returns a copy of `input`:
*
* - From byte `start`
* - If specified: up to byte `end` (excluded)
*
* `start` and `end`:
*
* - Are integers that start at 0
* - Can be negative to search from the end instead
* - If out-of-bound, stop at the start or end of `input`
*
* @example
* ```js
* // Works like `string.slice()`
* stringByteSlice('abcd', 1) // "bcd"
* stringByteSlice('abcd', 1, 3) // "bc"
* stringByteSlice('abcd', -3) // "bcd"
* stringByteSlice('abcd', 0, -1) // "abc"
* stringByteSlice('abcd', 0, 100) // "abcd"
* stringByteSlice('abcd', 0, -100) // ""
*
* // UTF-8 bytes length is taken into account
* stringByteSlice('abcdef', 0, 4) // "abcd"
* stringByteSlice('\nbcdef', 0, 4) // "\nbcd"
* stringByteSlice('±bcdef', 0, 4) // "±bc"
* stringByteSlice('★bcdef', 0, 4) // "★b"
* stringByteSlice('🦄bcdef', 0, 4) // "🦄"
*
* // Partially cut characters are discarded
* stringByteSlice('🦄bcdef', 0, 3) // ""
* ```
*/
export default function stringByteSlice<T extends string>(
input: T,
byteStart: number,
byteEnd?: number,
): T extends '' ? '' : string