@@ -4,6 +4,7 @@ var support = require("./support");
4
4
var base64 = require ( "./base64" ) ;
5
5
var nodejsUtils = require ( "./nodejsUtils" ) ;
6
6
var external = require ( "./external" ) ;
7
+ // @ts -expect-error - Legacy fallback, it seems
7
8
require ( "setimmediate" ) ;
8
9
9
10
@@ -12,7 +13,7 @@ require("setimmediate");
12
13
* array but may have > 255 char codes. Be sure to take only the first byte
13
14
* and returns the byte array.
14
15
* @param {String } str the string to transform.
15
- * @return {Array|Uint8Array } the string in a binary format.
16
+ * @return {Array<number> |Uint8Array } the string in a binary format.
16
17
*/
17
18
function string2binary ( str ) {
18
19
var result = null ;
@@ -76,8 +77,8 @@ function identity(input) {
76
77
/**
77
78
* Fill in an array with a string.
78
79
* @param {String } str the string to use.
79
- * @param {Array|ArrayBuffer |Uint8Array|Buffer } array the array to fill in (will be mutated).
80
- * @return {Array|ArrayBuffer |Uint8Array|Buffer } the updated array.
80
+ * @param {Array<number> |Uint8Array|Buffer } array the array to fill in (will be mutated).
81
+ * @return {Array<number> |Uint8Array|Buffer } the updated array.
81
82
*/
82
83
function stringToArrayLike ( str , array ) {
83
84
for ( var i = 0 ; i < str . length ; ++ i ) {
@@ -95,24 +96,24 @@ var arrayToStringHelper = {
95
96
/**
96
97
* Transform an array of int into a string, chunk by chunk.
97
98
* See the performances notes on arrayLikeToString.
98
- * @param {Array|ArrayBuffer |Uint8Array|Buffer } array the array to transform.
99
- * @param {String } type the type of the array.
100
- * @param {Integer } chunk the chunk size.
99
+ * @param {Array<number> |Uint8Array|Buffer } array the array to transform.
100
+ * @param {"array" | "nodebuffer" | "uint8array" } type the type of the array.
101
+ * @param {number } chunk the chunk size.
101
102
* @return {String } the resulting string.
102
103
* @throws Error if the chunk is too big for the stack.
103
104
*/
104
105
stringifyByChunk : function ( array , type , chunk ) {
105
106
var result = [ ] , k = 0 , len = array . length ;
106
107
// shortcut
107
108
if ( len <= chunk ) {
108
- return String . fromCharCode . apply ( null , array ) ;
109
+ return String . fromCharCode . apply ( null , [ ] . slice . call ( array ) ) ;
109
110
}
110
111
while ( k < len ) {
111
112
if ( type === "array" || type === "nodebuffer" ) {
112
- result . push ( String . fromCharCode . apply ( null , array . slice ( k , Math . min ( k + chunk , len ) ) ) ) ;
113
+ result . push ( String . fromCharCode . apply ( null , [ ] . slice . call ( /** @type { number[] | Buffer } */ ( array ) . slice ( k , Math . min ( k + chunk , len ) ) ) ) ) ;
113
114
}
114
115
else {
115
- result . push ( String . fromCharCode . apply ( null , array . subarray ( k , Math . min ( k + chunk , len ) ) ) ) ;
116
+ result . push ( String . fromCharCode . apply ( null , [ ] . slice . call ( /** @type { Uint8Array } */ ( array ) . subarray ( k , Math . min ( k + chunk , len ) ) ) ) ) ;
116
117
}
117
118
k += chunk ;
118
119
}
@@ -122,7 +123,7 @@ var arrayToStringHelper = {
122
123
* Call String.fromCharCode on every item in the array.
123
124
* This is the naive implementation, which generate A LOT of intermediate string.
124
125
* This should be used when everything else fail.
125
- * @param {Array|ArrayBuffer |Uint8Array|Buffer } array the array to transform.
126
+ * @param {Array<number> |Uint8Array|Buffer } array the array to transform.
126
127
* @return {String } the result.
127
128
*/
128
129
stringifyByChar : function ( array ) {
@@ -138,7 +139,7 @@ var arrayToStringHelper = {
138
139
*/
139
140
uint8array : ( function ( ) {
140
141
try {
141
- return support . uint8array && String . fromCharCode . apply ( null , new Uint8Array ( 1 ) ) . length === 1 ;
142
+ return support . uint8array && String . fromCharCode . apply ( null , [ ] . slice . call ( new Uint8Array ( 1 ) ) ) . length === 1 ;
142
143
} catch ( e ) {
143
144
return false ;
144
145
}
@@ -148,7 +149,7 @@ var arrayToStringHelper = {
148
149
*/
149
150
nodebuffer : ( function ( ) {
150
151
try {
151
- return support . nodebuffer && String . fromCharCode . apply ( null , nodejsUtils . allocBuffer ( 1 ) ) . length === 1 ;
152
+ return support . nodebuffer && String . fromCharCode . apply ( null , [ ] . slice . call ( nodejsUtils . allocBuffer ( 1 ) ) ) . length === 1 ;
152
153
} catch ( e ) {
153
154
return false ;
154
155
}
@@ -158,7 +159,7 @@ var arrayToStringHelper = {
158
159
159
160
/**
160
161
* Transform an array-like object to a string.
161
- * @param {Array|ArrayBuffer |Uint8Array|Buffer } array the array to transform.
162
+ * @param {Array<number> |Uint8Array|Buffer } array the array to transform.
162
163
* @return {String } the result.
163
164
*/
164
165
function arrayLikeToString ( array ) {
@@ -345,8 +346,8 @@ exports.resolve = function(path) {
345
346
/**
346
347
* Return the type of the input.
347
348
* The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer.
348
- * @param {Object } input the input to identify.
349
- * @return {String } the (lowercase) type of the input.
349
+ * @param {string|object } input the input to identify.
350
+ * @return {"string"|"array"|"nodebuffer"|"arraybuffer"|"uint8array" } the (lowercase) type of the input.
350
351
*/
351
352
exports . getTypeOf = function ( input ) {
352
353
if ( typeof input === "string" ) {
@@ -368,11 +369,12 @@ exports.getTypeOf = function(input) {
368
369
369
370
/**
370
371
* Throw an exception if the type is not supported.
371
- * @param {String } type the type to check.
372
+ * @param {string } type the type to check.
372
373
* @throws {Error } an Error if the browser doesn't support the requested type.
374
+ * @returns {asserts type is keyof support }
373
375
*/
374
376
exports . checkSupport = function ( type ) {
375
- var supported = support [ type . toLowerCase ( ) ] ;
377
+ var supported = support [ /** @ type { keyof support } */ ( type . toLowerCase ( ) ) ] ;
376
378
if ( ! supported ) {
377
379
throw new Error ( type + " is not supported by this platform" ) ;
378
380
}
@@ -398,8 +400,11 @@ exports.pretty = function(str) {
398
400
399
401
/**
400
402
* Defer the call of a function.
401
- * @param {Function } callback the function to call asynchronously.
402
- * @param {Array } args the arguments to give to the callback.
403
+ * @template {(this: This, ...args: any[]) => void} T
404
+ * @template This
405
+ * @param {T } callback the function to call asynchronously.
406
+ * @param {Parameters<T> } args the arguments to give to the callback.
407
+ * @param {This | null } self
403
408
*/
404
409
exports . delay = function ( callback , args , self ) {
405
410
setImmediate ( function ( ) {
0 commit comments