@creejs/commons-lang 2.1.7 → 2.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index-dev.cjs +181 -6
- package/dist/cjs/index-dev.cjs.map +1 -1
- package/dist/cjs/index-min.cjs +1 -1
- package/dist/cjs/index-min.cjs.map +1 -1
- package/dist/esm/index-dev.js +180 -7
- package/dist/esm/index-dev.js.map +1 -1
- package/dist/esm/index-min.js +1 -1
- package/dist/esm/index-min.js.map +1 -1
- package/dist/umd/index.dev.js +181 -6
- package/dist/umd/index.dev.js.map +1 -1
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -1
- package/types/array-buffer-utils.d.ts +26 -0
- package/types/index.d.ts +5 -1
- package/types/type-assert.d.ts +64 -56
- package/types/type-utils.d.ts +99 -92
package/dist/cjs/index-dev.cjs
CHANGED
|
@@ -12,7 +12,7 @@ var LangUtils = {
|
|
|
12
12
|
defaults,
|
|
13
13
|
extend,
|
|
14
14
|
extends: extend,
|
|
15
|
-
equals,
|
|
15
|
+
equals: equals$1,
|
|
16
16
|
isBrowser,
|
|
17
17
|
isNode
|
|
18
18
|
};
|
|
@@ -80,7 +80,7 @@ function extend (target, ...sources) {
|
|
|
80
80
|
* @param {*} value2 - Second value to compare
|
|
81
81
|
* @returns {boolean} True if values are equal, false otherwise
|
|
82
82
|
*/
|
|
83
|
-
function equals (value1, value2) {
|
|
83
|
+
function equals$1 (value1, value2) {
|
|
84
84
|
if (value1 === value2) {
|
|
85
85
|
return true
|
|
86
86
|
}
|
|
@@ -153,7 +153,8 @@ var TypeUtils = {
|
|
|
153
153
|
isFloat64Array,
|
|
154
154
|
isBigInt64Array,
|
|
155
155
|
isBigUint64Array,
|
|
156
|
-
isTypedArray
|
|
156
|
+
isTypedArray,
|
|
157
|
+
isArrayBuffer
|
|
157
158
|
};
|
|
158
159
|
/**
|
|
159
160
|
* Checks if the given value is an array.
|
|
@@ -483,7 +484,7 @@ function isInt32Array (value) {
|
|
|
483
484
|
function isUint32Array (value) {
|
|
484
485
|
return value instanceof Uint32Array
|
|
485
486
|
}
|
|
486
|
-
//
|
|
487
|
+
// function isFloat16Array (value) {
|
|
487
488
|
// return value instanceof Float16Array
|
|
488
489
|
// }
|
|
489
490
|
/**
|
|
@@ -519,6 +520,15 @@ function isBigUint64Array (value) {
|
|
|
519
520
|
return value instanceof BigUint64Array
|
|
520
521
|
}
|
|
521
522
|
|
|
523
|
+
/**
|
|
524
|
+
* Checks if the given value is an ArrayBuffer.
|
|
525
|
+
* @param {*} value - The value to check.
|
|
526
|
+
* @returns {boolean} True if the value is an ArrayBuffer, false otherwise.
|
|
527
|
+
*/
|
|
528
|
+
function isArrayBuffer (value) {
|
|
529
|
+
return value instanceof ArrayBuffer
|
|
530
|
+
}
|
|
531
|
+
|
|
522
532
|
// 3rd
|
|
523
533
|
// internal
|
|
524
534
|
// owned
|
|
@@ -557,7 +567,8 @@ var TypeAssert = {
|
|
|
557
567
|
assertFloat64Array,
|
|
558
568
|
assertBigInt64Array,
|
|
559
569
|
assertBigUint64Array,
|
|
560
|
-
assertTypedArray
|
|
570
|
+
assertTypedArray,
|
|
571
|
+
assertArrayBuffer
|
|
561
572
|
};
|
|
562
573
|
/**
|
|
563
574
|
* if value is not Array, throw error
|
|
@@ -911,6 +922,18 @@ function assertBigUint64Array (value, paramName) {
|
|
|
911
922
|
}
|
|
912
923
|
}
|
|
913
924
|
|
|
925
|
+
/**
|
|
926
|
+
* Asserts that the given value is an ArrayBuffer.
|
|
927
|
+
* @param {*} value - The value to check.
|
|
928
|
+
* @param {string} [paramName] - Optional parameter name for error message.
|
|
929
|
+
* @throws {Error} Throws an error if the value is not an ArrayBuffer.
|
|
930
|
+
*/
|
|
931
|
+
function assertArrayBuffer (value, paramName) {
|
|
932
|
+
if (!isArrayBuffer(value)) {
|
|
933
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ' '}Not ArrayBuffer`)
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
|
|
914
937
|
// 3rd
|
|
915
938
|
// internal
|
|
916
939
|
// owned
|
|
@@ -1861,6 +1884,154 @@ var ReflectUtils = {
|
|
|
1861
1884
|
getMethodsOfObject: getMethods
|
|
1862
1885
|
};
|
|
1863
1886
|
|
|
1887
|
+
// internal
|
|
1888
|
+
|
|
1889
|
+
|
|
1890
|
+
// owned
|
|
1891
|
+
|
|
1892
|
+
/**
|
|
1893
|
+
* @typedef {
|
|
1894
|
+
Int8Array|
|
|
1895
|
+
Uint8Array|
|
|
1896
|
+
Uint8ClampedArray|
|
|
1897
|
+
Int16Array|
|
|
1898
|
+
Uint16Array|
|
|
1899
|
+
Int32Array|
|
|
1900
|
+
Uint32Array|
|
|
1901
|
+
Float32Array|
|
|
1902
|
+
Float64Array|
|
|
1903
|
+
BigInt64Array|
|
|
1904
|
+
BigUint64Array
|
|
1905
|
+
} TypedArray
|
|
1906
|
+
*/
|
|
1907
|
+
|
|
1908
|
+
var TypedArrayUtils = {
|
|
1909
|
+
startsWith,
|
|
1910
|
+
isSameType,
|
|
1911
|
+
equals
|
|
1912
|
+
};
|
|
1913
|
+
|
|
1914
|
+
/**
|
|
1915
|
+
* Checks if a string starts with the specified substring.
|
|
1916
|
+
* @param {TypedArray} src - The source string to check.
|
|
1917
|
+
* @param {TypedArray} searching - The substring to search for at the start of `src`.
|
|
1918
|
+
* @returns {boolean} True if `src` starts with `searching`, false otherwise.
|
|
1919
|
+
* @throws {Error} If either `src` or `searching` is null or undefined.
|
|
1920
|
+
*/
|
|
1921
|
+
function startsWith (src, searching) {
|
|
1922
|
+
assertNotNil(src, 'src');
|
|
1923
|
+
assertNotNil(searching, 'searching');
|
|
1924
|
+
|
|
1925
|
+
const header = src.subarray(0, searching.length);
|
|
1926
|
+
return equals(header, searching)
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
/**
|
|
1930
|
+
* Checks if two values have the same constructor type.
|
|
1931
|
+
* @param {*} src - The source value to compare.
|
|
1932
|
+
* @param {*} target - The target value to compare against.
|
|
1933
|
+
* @returns {boolean} True if both values have the same constructor type, false otherwise.
|
|
1934
|
+
* @throws Will throw if either src or target is null/undefined.
|
|
1935
|
+
*/
|
|
1936
|
+
function isSameType (src, target) {
|
|
1937
|
+
assertNotNil(src, 'src');
|
|
1938
|
+
assertNotNil(target, 'target');
|
|
1939
|
+
return constructorName(src) === constructorName(target)
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
/**
|
|
1943
|
+
* Checks if two typed arrays are equal by comparing their contents.
|
|
1944
|
+
* 1. Must be Same Type
|
|
1945
|
+
* 2. Must have Same Length
|
|
1946
|
+
* 3. Must have same contents
|
|
1947
|
+
* @param {TypedArray} src - The source typed array to compare.
|
|
1948
|
+
* @param {TypedArray} target - The target typed array to compare against.
|
|
1949
|
+
* @returns {boolean} True if the typed arrays are equal, false otherwise.
|
|
1950
|
+
* @throws {Error} If either `src` or `target` is null or undefined.
|
|
1951
|
+
*/
|
|
1952
|
+
function equals (src, target) {
|
|
1953
|
+
assertNotNil(src, 'src');
|
|
1954
|
+
assertNotNil(target, 'target');
|
|
1955
|
+
if (!isSameType(src, target)) {
|
|
1956
|
+
return false
|
|
1957
|
+
}
|
|
1958
|
+
if (src.byteLength !== target.byteLength) {
|
|
1959
|
+
return false
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
const view1 = new DataView(src.buffer, src.byteOffset, src.byteLength);
|
|
1963
|
+
const view2 = new DataView(target.buffer, target.byteOffset, target.byteLength);
|
|
1964
|
+
|
|
1965
|
+
for (let i = 0; i < src.byteLength; i++) {
|
|
1966
|
+
if (view1.getUint8(i) !== view2.getUint8(i)) {
|
|
1967
|
+
return false
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
return true
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
var ArrayBufferUtils = {
|
|
1974
|
+
readString,
|
|
1975
|
+
writeString
|
|
1976
|
+
};
|
|
1977
|
+
|
|
1978
|
+
// module vars
|
|
1979
|
+
const textDecoder = new TextDecoder();
|
|
1980
|
+
const textEncoder = new TextEncoder();
|
|
1981
|
+
/**
|
|
1982
|
+
* Reads a string from an ArrayBuffer at the specified offset and length.
|
|
1983
|
+
* 1. if offset >= buffer.byteLength, return undefined
|
|
1984
|
+
* 2. if length is not specified, read all bytes from offset to the end of buffer
|
|
1985
|
+
* 3. if length is specified
|
|
1986
|
+
* * if offset + length >= buffer.byteLength, return a Uint8Array from offset to the end of buffer
|
|
1987
|
+
* * if offset + length < buffer.byteLength, return a Uint8Array from offset to offset + length
|
|
1988
|
+
* @param {ArrayBuffer} buffer - The buffer to read from.
|
|
1989
|
+
* @param {number} [offset=0] - The offset in bytes to start reading from.
|
|
1990
|
+
* @param {number} [length] - The number of bytes to read.
|
|
1991
|
+
* @returns {string|undefined} The decoded string.
|
|
1992
|
+
*/
|
|
1993
|
+
function readString (buffer, offset = 0, length) {
|
|
1994
|
+
assertArrayBuffer(buffer);
|
|
1995
|
+
assertNotNegative(offset);
|
|
1996
|
+
if (offset >= buffer.byteLength) {
|
|
1997
|
+
return undefined
|
|
1998
|
+
}
|
|
1999
|
+
let uint8Array = null;
|
|
2000
|
+
if (length != null) {
|
|
2001
|
+
assertPositive(length);
|
|
2002
|
+
if (offset + length >= buffer.byteLength) {
|
|
2003
|
+
uint8Array = new Uint8Array(buffer, offset);
|
|
2004
|
+
} else {
|
|
2005
|
+
uint8Array = new Uint8Array(buffer, offset, length);
|
|
2006
|
+
}
|
|
2007
|
+
} else {
|
|
2008
|
+
uint8Array = new Uint8Array(buffer, offset);
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
// An ArrayBuffer, a TypedArray, or a DataView object containing the encoded text to decode.
|
|
2012
|
+
return textDecoder.decode(uint8Array)
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
/**
|
|
2016
|
+
* Writes a string to an ArrayBuffer at the specified offset.
|
|
2017
|
+
* @param {ArrayBuffer} buffer - The buffer to write to
|
|
2018
|
+
* @param {string} str - The string to write
|
|
2019
|
+
* @param {number} [offset=0] - The offset in bytes to start writing
|
|
2020
|
+
* @returns {void}
|
|
2021
|
+
*/
|
|
2022
|
+
function writeString (buffer, str, offset = 0) {
|
|
2023
|
+
assertArrayBuffer(buffer, 'buffer');
|
|
2024
|
+
assertString(str, 'str');
|
|
2025
|
+
assertNotNegative(offset, 'offset');
|
|
2026
|
+
const uint8Array = textEncoder.encode(str);
|
|
2027
|
+
const strByteLength = uint8Array.byteLength;
|
|
2028
|
+
if (offset + strByteLength > buffer.byteLength) {
|
|
2029
|
+
throw new Error(`offset + str.byteLength > buffer.byteLength:${offset + strByteLength} > ${buffer.byteLength}`)
|
|
2030
|
+
}
|
|
2031
|
+
const dataView = new Uint8Array(buffer, offset, uint8Array.byteLength);
|
|
2032
|
+
dataView.set(uint8Array);
|
|
2033
|
+
}
|
|
2034
|
+
|
|
1864
2035
|
/**
|
|
1865
2036
|
* @module Lang
|
|
1866
2037
|
* @description Core language utilities for type checking, string manipulation, and common operations.
|
|
@@ -1879,9 +2050,12 @@ var index = {
|
|
|
1879
2050
|
Exec: ExecUtils,
|
|
1880
2051
|
ClassProxyUtils,
|
|
1881
2052
|
InstanceProxyUtils,
|
|
1882
|
-
ReflectUtils
|
|
2053
|
+
ReflectUtils,
|
|
2054
|
+
TypedArrayUtils,
|
|
2055
|
+
ArrayBufferUtils
|
|
1883
2056
|
};
|
|
1884
2057
|
|
|
2058
|
+
exports.ArrayBufferUtils = ArrayBufferUtils;
|
|
1885
2059
|
exports.ClassProxyUtils = ClassProxyUtils;
|
|
1886
2060
|
exports.Exec = ExecUtils;
|
|
1887
2061
|
exports.ExecUtils = ExecUtils;
|
|
@@ -1894,5 +2068,6 @@ exports.StringUtils = StringUtils;
|
|
|
1894
2068
|
exports.Type = TypeUtils;
|
|
1895
2069
|
exports.TypeAssert = TypeAssert;
|
|
1896
2070
|
exports.TypeUtils = TypeUtils;
|
|
2071
|
+
exports.TypedArrayUtils = TypedArrayUtils;
|
|
1897
2072
|
exports.default = index;
|
|
1898
2073
|
//# sourceMappingURL=index-dev.cjs.map
|