@creejs/commons-lang 2.1.9 → 2.1.11

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.
@@ -1972,7 +1972,8 @@ function equals (src, target) {
1972
1972
 
1973
1973
  var ArrayBufferUtils = {
1974
1974
  readString,
1975
- writeString
1975
+ writeString,
1976
+ writeArrayBuffer
1976
1977
  };
1977
1978
 
1978
1979
  // module vars
@@ -2032,6 +2033,84 @@ function writeString (buffer, str, offset = 0) {
2032
2033
  dataView.set(uint8Array);
2033
2034
  }
2034
2035
 
2036
+ /**
2037
+ * Writes an ArrayBuffer into a target ArrayBuffer at the specified offset.
2038
+ * 1. targetOffset
2039
+ * * Negative index counts back from the end of the buffer
2040
+ * * if -target.length <= targetOffset < 0, start + target.length is used.
2041
+ * * If targetOffset < -buffer.length or targetOffset is omitted, 0 is used.
2042
+ * * If targetOffset >= buffer.length, throw "Out of target Bounds" Error
2043
+ * 2. dataOffset
2044
+ * * Negative index counts back from the end of the buffer
2045
+ * * if -dataArrayBuffer.length <= dataOffset < 0, start + dataArrayBuffer.length is used.
2046
+ * * If dataOffset < -buffer.length or dataOffset is omitted, 0 is used.
2047
+ * * If dataOffset >= buffer.length, throw "Out of data Bounds" Error
2048
+ * 3. dataLength
2049
+ * * if dataLength <= 0, throw "Not Positive" Error
2050
+ * * if dataLength is omitted, read all bytes from dataOffset to the end of dataArrayBuffer
2051
+ * * if dataLength + dataOffset > dataArrayBuffer.length, read all bytes from dataOffset to the end of dataArrayBuffer
2052
+ * @param {ArrayBuffer} target - The target buffer to write into.
2053
+ * @param {ArrayBuffer} dataArrayBuffer - The data ArrayBuffer to write.
2054
+ * @param {number} [targetOffset=0] - Zero-based index at which to start write.
2055
+ * @param {number} [dataOffset=0] - The offset in the dataArrayBuffer
2056
+ * @param {number} [dataLength] - how many bytes extract from dataArrayBuffer
2057
+ * @returns {void}
2058
+ */
2059
+ function writeArrayBuffer (target, dataArrayBuffer, targetOffset = 0, dataOffset = 0, dataLength) {
2060
+ assertArrayBuffer(target);
2061
+ assertArrayBuffer(dataArrayBuffer);
2062
+ assertNumber(targetOffset);
2063
+ assertNumber(dataOffset);
2064
+ const targetLength = target.byteLength;
2065
+ if (targetOffset < -1 * targetLength) { // targetOffset < -buffer.length
2066
+ targetOffset = 0;
2067
+ } else if (targetOffset < 0) { // -target.length <= targetOffset < 0
2068
+ targetOffset += targetLength;
2069
+ } else if (targetOffset >= targetLength) {
2070
+ throw new Error(`Out of target Bounds: targetOffset(${targetOffset}) >= targetLength(${targetLength})`)
2071
+ }
2072
+
2073
+ const dataArrayBufferLength = dataArrayBuffer.byteLength;
2074
+ if (dataOffset < -1 * dataArrayBufferLength) {
2075
+ dataOffset = 0;
2076
+ } else if (dataOffset < 0) {
2077
+ dataOffset += dataArrayBufferLength;
2078
+ } else if (dataOffset >= dataArrayBufferLength) {
2079
+ throw new Error(`Out of data Bounds: dataOffset(${dataOffset}) >= dataArrayBufferLength(${dataArrayBufferLength})`)
2080
+ }
2081
+
2082
+ if (dataLength != null) {
2083
+ assertPositive(dataLength, 'dataLength');
2084
+ // offset+dataLengt out of dataArrayBuffer bounds, treat as no limitation, read to end
2085
+ if (dataOffset + dataLength > dataArrayBufferLength) {
2086
+ dataLength = undefined;
2087
+ }
2088
+ }
2089
+ const dataView = new Uint8Array(dataArrayBuffer, dataOffset, dataLength);
2090
+ if (dataView.byteLength > targetLength - targetOffset) {
2091
+ throw new Error(`Out of target Bounds: from targetOffset(${targetOffset}), No Space to store dataArrayBuffer(${dataOffset}, ${dataLength ?? 'NoLimit'})`)
2092
+ }
2093
+ const targetView = new Uint8Array(target);
2094
+ targetView.set(dataView, targetOffset);
2095
+ }
2096
+
2097
+ var TimeUtils = {
2098
+ timestamp64
2099
+ };
2100
+
2101
+ const ms2ns = BigInt(1_000_000);
2102
+ /**
2103
+ * Gets the current timestamp in nanoseconds (if running in Node.js) or milliseconds (in browser).
2104
+ * Uses `process.hrtime.bigint()` for high-resolution timestamps in Node.js, falls back to `Date.now()` in browsers.
2105
+ * @returns {bigint} Current timestamp as a BigInt
2106
+ */
2107
+ function timestamp64 () {
2108
+ if (typeof performance !== 'undefined') {
2109
+ return BigInt(Math.floor(performance.timeOrigin + performance.now())) * ms2ns
2110
+ }
2111
+ return BigInt(Date.now()) * ms2ns
2112
+ }
2113
+
2035
2114
  /**
2036
2115
  * @module Lang
2037
2116
  * @description Core language utilities for type checking, string manipulation, and common operations.
@@ -2052,7 +2131,8 @@ var index = {
2052
2131
  InstanceProxyUtils,
2053
2132
  ReflectUtils,
2054
2133
  TypedArrayUtils,
2055
- ArrayBufferUtils
2134
+ ArrayBufferUtils,
2135
+ TimeUtils
2056
2136
  };
2057
2137
 
2058
2138
  exports.ArrayBufferUtils = ArrayBufferUtils;
@@ -2065,6 +2145,7 @@ exports.LangUtils = LangUtils;
2065
2145
  exports.PromiseUtils = PromiseUtils;
2066
2146
  exports.ReflectUtils = ReflectUtils;
2067
2147
  exports.StringUtils = StringUtils;
2148
+ exports.TimeUtils = TimeUtils;
2068
2149
  exports.Type = TypeUtils;
2069
2150
  exports.TypeAssert = TypeAssert;
2070
2151
  exports.TypeUtils = TypeUtils;