diff --git a/en/application-dev/reference/apis/js-apis-arraylist.md b/en/application-dev/reference/apis/js-apis-arraylist.md index 283786a82fd1ce50d7632b9354b99f32ff4419fb..0cd79c938c8bb74f7fb919c7e6dc2e1afaa97cd8 100644 --- a/en/application-dev/reference/apis/js-apis-arraylist.md +++ b/en/application-dev/reference/apis/js-apis-arraylist.md @@ -1,8 +1,5 @@ # @ohos.util.ArrayList (Linear Container ArrayList) -> **NOTE** -> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. - **ArrayList** is a linear data structure that is implemented based on arrays. **ArrayList** can dynamically adjust the capacity based on project requirements. It increases the capacity by 50% each time. Similar to **ArrayList**, **[Vector](js-apis-vector.md)** is also implemented based on arrays and can dynamically adjust the capacity. It increases the capability by 100% each time. @@ -14,6 +11,11 @@ When compared with **[LinkedList](js-apis-linkedlist.md)**, **ArrayList** is mor This topic uses the following to identify the use of generics: - T: Type +> **NOTE** +> +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + ## Modules to Import ```ts @@ -160,9 +162,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let arrayList = new ArrayList(); -let result = arrayList.has("squirrel"); arrayList.add("squirrel"); -let result1 = arrayList.has("squirrel"); +let result = arrayList.has("squirrel"); ``` ### getIndexOf @@ -535,9 +536,7 @@ arrayList.add(2); arrayList.add(4); arrayList.add(5); arrayList.add(4); -let result1 = arrayList.subArrayList(2, 4); -let result2 = arrayList.subArrayList(4, 3); -let result3 = arrayList.subArrayList(2, 6); +let result = arrayList.subArrayList(2, 4); ``` ### clear diff --git a/en/application-dev/reference/apis/js-apis-buffer.md b/en/application-dev/reference/apis/js-apis-buffer.md index 72e65e53e63380ef4ea0aa9b33796e236bc7ee84..5a014e7cfe5618c7e31741b43d32ce743d86a0b2 100644 --- a/en/application-dev/reference/apis/js-apis-buffer.md +++ b/en/application-dev/reference/apis/js-apis-buffer.md @@ -54,7 +54,7 @@ Creates and initializes a **Buffer** instance of the specified length. | Type| Description| | -------- | -------- | -| Buffer | Initialized **Buffer** instance.| +| Buffer | **Buffer** instance created.| **Example** @@ -417,11 +417,11 @@ Checks whether the specified object is a **Buffer** instance. ```ts import buffer from '@ohos.buffer'; -buffer.isBuffer(buffer.alloc(10)); // true -buffer.isBuffer(buffer.from('foo')); // true -buffer.isBuffer('a string'); // false -buffer.isBuffer([]); // false -buffer.isBuffer(new Uint8Array(1024)); // false +let result = buffer.isBuffer(buffer.alloc(10)); // true +let result1 = buffer.isBuffer(buffer.from('foo')); // true +let result2 = buffer.isBuffer('a string'); // false +let result3 = buffer.isBuffer([]); // false +let result4 = buffer.isBuffer(new Uint8Array(1024)); // false ``` ## buffer.isEncoding @@ -436,7 +436,7 @@ Checks whether the encoding format is supported. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| encoding | string | Yes| Encoding format to check. | +| encoding | string | Yes| Encoding format.| **Return value** @@ -838,7 +838,7 @@ console.log(buf.lastIndexOf('buffer').toString()); // Print: 17 readBigInt64BE(offset?: number): bigint -Reads a signed, big-endian 64-bit integer from this **Buffer** instance at the specified offset. +Reads a signed, big-endian 64-bit big integer from this **Buffer** instance at the specified offset. **System capability**: SystemCapability.Utils.Lang @@ -852,7 +852,7 @@ Reads a signed, big-endian 64-bit integer from this **Buffer** instance at the s | Type| Description| | -------- | -------- | -| bigint | A signed, big-endian 64-bit Big integer. | +| bigint | Data read.| **Error codes** @@ -872,14 +872,14 @@ let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, console.log(buf.readBigInt64BE(0).toString()); let buf1 = buffer.allocUninitializedFromPool(8); -buf1.writeBigInt64BE(0x0102030405060708n, 0); +let result = buf1.writeBigInt64BE(0x0102030405060708n, 0); ``` ### readBigInt64LE readBigInt64LE(offset?: number): bigint -Reads a signed, little-endian 64-bit Big integer from this **Buffer** instance at the specified offset. +Reads a signed, little-endian 64-bit big integer from this **Buffer** instance at the specified offset. **System capability**: SystemCapability.Utils.Lang @@ -893,7 +893,7 @@ Reads a signed, little-endian 64-bit Big integer from this **Buffer** instance a | Type| Description| | -------- | -------- | -| bigint | A signed, little-endian 64-bit Big integer. | +| bigint | Data read.| **Error codes** @@ -913,14 +913,14 @@ let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, console.log(buf.readBigInt64LE(0).toString()); let buf1 = buffer.allocUninitializedFromPool(8); -buf1.writeBigInt64BE(0x0102030405060708n, 0); +let result = buf1.writeBigInt64BE(0x0102030405060708n, 0); ``` ### readBigUInt64BE readBigUInt64BE(offset?: number): bigint -Reads an unsigned, big-endian 64-bit Big integer from this **Buffer** instance at the specified offset. +Reads an unsigned, big-endian 64-bit big integer from this **Buffer** instance at the specified offset. **System capability**: SystemCapability.Utils.Lang @@ -934,7 +934,7 @@ Reads an unsigned, big-endian 64-bit Big integer from this **Buffer** instance a | Type| Description| | -------- | -------- | -| bigint | An unsigned, big-endian 64-bit Big integer. | +| bigint | Data read.| **Error codes** @@ -954,14 +954,14 @@ let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, console.log(buf.readBigUInt64BE(0).toString()); let buf1 = buffer.allocUninitializedFromPool(8); -buf1.writeBigUInt64BE(0xdecafafecacefaden, 0); +let result = buf1.writeBigUInt64BE(0xdecafafecacefaden, 0); ``` ### readBigUInt64LE readBigUInt64LE(offset?: number): bigint -Reads an unsigned, little-endian 64-bit Big integer from this **Buffer** instance at the specified offset. +Reads an unsigned, little-endian 64-bit big integer from this **Buffer** instance at the specified offset. **System capability**: SystemCapability.Utils.Lang @@ -975,7 +975,7 @@ Reads an unsigned, little-endian 64-bit Big integer from this **Buffer** instanc | Type| Description| | -------- | -------- | -| bigint | An unsigned, little-endian 64-bit Big integer. | +| bigint | Data read.| **Error codes** @@ -995,14 +995,14 @@ let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, console.log(buf.readBigUInt64LE(0).toString()); let buf1 = buffer.allocUninitializedFromPool(8); -buf1.writeBigUInt64BE(0xdecafafecacefaden, 0); +let result = buf1.writeBigUInt64BE(0xdecafafecacefaden, 0); ``` ### readDoubleBE readDoubleBE(offset?: number): number -Reads a big-endian double-precision floating-point number from this **Buffer** instance at the specified offset. +Reads a 64-bit, big-endian floating-point number from this **Buffer** instance at the specified offset. **System capability**: SystemCapability.Utils.Lang @@ -1016,7 +1016,7 @@ Reads a big-endian double-precision floating-point number from this **Buffer** i | Type| Description| | -------- | -------- | -| number | A big-endian double-precision floating-point number. | +| number | Data read.| **Error codes** @@ -1035,14 +1035,14 @@ let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); console.log(buf.readDoubleBE(0).toString()); let buf1 = buffer.allocUninitializedFromPool(8); -buf1.writeDoubleBE(123.456, 0); +let result = buf1.writeDoubleBE(123.456, 0); ``` ### readDoubleLE readDoubleLE(offset?: number): number -Reads a little-endian double-precision floating-point number from this **Buffer** instance at the specified offset. +Reads a 64-bit, little-endian floating-point number from this **Buffer** instance at the specified offset. **System capability**: SystemCapability.Utils.Lang @@ -1056,7 +1056,7 @@ Reads a little-endian double-precision floating-point number from this **Buffer* | Type| Description| | -------- | -------- | -| number | A little-endian double-precision floating-point number. | +| number | Data read.| **Error codes** @@ -1075,14 +1075,14 @@ let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); console.log(buf.readDoubleLE(0).toString()); let buf1 = buffer.allocUninitializedFromPool(8); -buf1.writeDoubleLE(123.456, 0); +let result = buf1.writeDoubleLE(123.456, 0); ``` ### readFloatBE readFloatBE(offset?: number): number -Reads a big-endian single-precision floating-point number from this **Buffer** instance at the specified offset. +Reads a 32-bit, big-endian floating-point number from this **Buffer** instance at the specified offset. **System capability**: SystemCapability.Utils.Lang @@ -1096,7 +1096,7 @@ Reads a big-endian single-precision floating-point number from this **Buffer** i | Type| Description| | -------- | -------- | -| number | A big-endian single-precision floating-point number. | +| number | Data read.| **Error codes** @@ -1115,14 +1115,14 @@ let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); console.log(buf.readFloatBE(0).toString()); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeFloatBE(0xcabcbcbc, 0); +let result = buf1.writeFloatBE(0xcabcbcbc, 0); ``` ### readFloatLE readFloatLE(offset?: number): number -Reads a little-endian single-precision floating-point number from this **Buffer** instance at the specified offset. +Reads a 32-bit, little-endian floating-point number from this **Buffer** instance at the specified offset. **System capability**: SystemCapability.Utils.Lang @@ -1136,7 +1136,7 @@ Reads a little-endian single-precision floating-point number from this **Buffer* | Type| Description| | -------- | -------- | -| number | A little-endian single-precision floating-point number. | +| number | Data read.| **Error codes** @@ -1155,7 +1155,7 @@ let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); console.log(buf.readFloatLE(0).toString()); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeFloatLE(0xcabcbcbc, 0); +let result = buf1.writeFloatLE(0xcabcbcbc, 0); ``` ### readInt8 @@ -1176,7 +1176,7 @@ Reads a signed 8-bit integer from this **Buffer** instance at the specified offs | Type| Description| | -------- | -------- | -| number | A signed 8-bit integer. | +| number | Data read.| **Error codes** @@ -1196,7 +1196,7 @@ console.log(buf.readInt8(0).toString()); // Print: -1 console.log(buf.readInt8(1).toString()); // Print: 5 let buf1 = buffer.allocUninitializedFromPool(2); -buf1.writeInt8(0x12); +let result = buf1.writeInt8(0x12); ``` ### readInt16BE @@ -1217,7 +1217,7 @@ Reads a signed, big-endian 16-bit integer from this **Buffer** instance at the s | Type| Description| | -------- | -------- | -| number | A signed, big-endian 16-bit integer.| +| number | Data read.| **Error codes** @@ -1236,7 +1236,7 @@ let buf = buffer.from([0, 5]); console.log(buf.readInt16BE(0).toString()); // Print: 5 let buf1 = buffer.alloc(2); -buf1.writeInt16BE(0x1234, 0); +let result = buf1.writeInt16BE(0x1234, 0); ``` ### readInt16LE @@ -1257,7 +1257,7 @@ Reads a signed, little-endian 16-bit integer from this **Buffer** instance at th | Type| Description| | -------- | -------- | -| number | A signed, little-endian 16-bit integer.| +| number | Data read.| **Error codes** @@ -1276,7 +1276,7 @@ let buf = buffer.from([0, 5]); console.log(buf.readInt16LE(0).toString()); // Print: 1280 let buf1 = buffer.alloc(2); -buf1.writeInt16BE(0x1234, 0); +let result = buf1.writeInt16BE(0x1234, 0); ``` ### readInt32BE @@ -1297,7 +1297,7 @@ Reads a signed, big-endian 32-bit integer from this **Buffer** instance at the s | Type| Description| | -------- | -------- | -| number | A signed, big-endian 32-bit integer.| +| number | Data read.| **Error codes** @@ -1316,7 +1316,7 @@ let buf = buffer.from([0, 0, 0, 5]); console.log(buf.readInt32BE(0).toString()); // Print: 5 let buf1 = buffer.alloc(4); -buf1.writeInt32BE(0x12345678, 0); +let result = buf1.writeInt32BE(0x12345678, 0); ``` ### readInt32LE @@ -1337,7 +1337,7 @@ Reads a signed, little-endian 32-bit integer from this **Buffer** instance at th | Type| Description| | -------- | -------- | -| number | A signed, little-endian 32-bit integer.| +| number | Data read.| **Error codes** @@ -1356,7 +1356,7 @@ let buf = buffer.from([0, 0, 0, 5]); console.log(buf.readInt32LE(0).toString()); // Print: 83886080 let buf1 = buffer.alloc(4); -buf1.writeInt32BE(0x12345678, 0); +let result = buf1.writeInt32BE(0x12345678, 0); ``` ### readIntBE @@ -1399,7 +1399,7 @@ let num = buf.readIntBE(0, 1); console.log(num.toString()); // 97 let buf1 = buffer.allocUninitializedFromPool(6); -buf1.writeIntBE(0x123456789011, 0, 6); +let result = buf1.writeIntBE(0x123456789011, 0, 6); ``` @@ -1442,7 +1442,7 @@ let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]); console.log(buf.readIntLE(0, 6).toString(16)); let buf1 = buffer.allocUninitializedFromPool(6); -buf1.writeIntLE(0x123456789011, 0, 6); +let result = buf1.writeIntLE(0x123456789011, 0, 6); ``` ### readUInt8 @@ -1464,7 +1464,7 @@ Reads an unsigned 8-bit integer from this **Buffer** instance at the specified o | Type| Description| | -------- | -------- | -| number | An unsigned 8-bit integer.| +| number | Data read.| **Error codes** @@ -1484,7 +1484,7 @@ console.log(buf.readUInt8(0).toString()); console.log(buf.readUInt8(1).toString()); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeUInt8(0x42); +let result = buf1.writeUInt8(0x42); ``` ### readUInt16BE @@ -1506,7 +1506,7 @@ Reads an unsigned, big-endian 16-bit integer from this **Buffer** instance at th | Type| Description| | -------- | -------- | -| number | An unsigned, big-endian 16-bit integer.| +| number | Data read.| **Error codes** @@ -1526,7 +1526,7 @@ console.log(buf.readUInt16BE(0).toString(16)); console.log(buf.readUInt16BE(1).toString(16)); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeUInt16BE(0x1234, 0); +let result = buf1.writeUInt16BE(0x1234, 0); ``` ### readUInt16LE @@ -1548,7 +1548,7 @@ Reads an unsigned, little-endian 16-bit integer from this **Buffer** instance at | Type| Description| | -------- | -------- | -| number | An unsigned, little-endian 16-bit integer.| +| number | Data read.| **Error codes** @@ -1568,7 +1568,7 @@ console.log(buf.readUInt16LE(0).toString(16)); console.log(buf.readUInt16LE(1).toString(16)); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeUInt16LE(0x1234, 0); +let result = buf1.writeUInt16LE(0x1234, 0); ``` ### readUInt32BE @@ -1590,7 +1590,7 @@ Reads an unsigned, big-endian 32-bit integer from this **Buffer** instance at th | Type| Description| | -------- | -------- | -| number | An unsigned, big-endian 32-bit integer.| +| number | Data read.| **Error codes** @@ -1609,7 +1609,7 @@ let buf = buffer.from([0x12, 0x34, 0x56, 0x78]); console.log(buf.readUInt32BE(0).toString(16)); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeUInt32BE(0x12345678, 0); +let result = buf1.writeUInt32BE(0x12345678, 0); ``` ### readUInt32LE @@ -1631,7 +1631,7 @@ Reads an unsigned, little-endian 32-bit integer from this **Buffer** instance at | Type| Description| | -------- | -------- | -| number | An unsigned, little-endian 32-bit integer.| +| number | Data read.| **Error codes** @@ -1650,7 +1650,7 @@ let buf = buffer.from([0x12, 0x34, 0x56, 0x78]); console.log(buf.readUInt32LE(0).toString(16)); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeUInt32LE(0x12345678, 0); +let result = buf1.writeUInt32LE(0x12345678, 0); ``` ### readUIntBE @@ -1692,7 +1692,7 @@ let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]); console.log(buf.readUIntBE(0, 6).toString(16)); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeUIntBE(0x13141516, 0, 4); +let result = buf1.writeUIntBE(0x13141516, 0, 4); ``` ### readUIntLE @@ -1715,7 +1715,7 @@ Reads the specified number of bytes from this **Buffer** instance at the specifi | Type| Description| | -------- | -------- | -| number | A signed, big-endian 64-bit integer.| +| number | Data read.| **Error codes** @@ -1734,7 +1734,7 @@ let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]); console.log(buf.readUIntLE(0, 6).toString(16)); let buf1 = buffer.allocUninitializedFromPool(4); -buf1.writeUIntLE(0x13141516, 0, 4); +let result = buf1.writeUIntLE(0x13141516, 0, 4); ``` ### subarray @@ -2045,7 +2045,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(8); -buf.writeBigInt64BE(0x0102030405060708n, 0); +let result = buf.writeBigInt64BE(0x0102030405060708n, 0); ``` ### writeBigInt64LE @@ -2084,7 +2084,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(8); -buf.writeBigInt64LE(0x0102030405060708n, 0); +let result = buf.writeBigInt64LE(0x0102030405060708n, 0); ``` ### writeBigUInt64BE @@ -2123,7 +2123,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(8); -buf.writeBigUInt64BE(0xdecafafecacefaden, 0); +let result = buf.writeBigUInt64BE(0xdecafafecacefaden, 0); ``` ### writeBigUInt64LE @@ -2162,7 +2162,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(8); -buf.writeBigUInt64LE(0xdecafafecacefaden, 0); +let result = buf.writeBigUInt64LE(0xdecafafecacefaden, 0); ``` ### writeDoubleBE @@ -2201,7 +2201,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(8); -buf.writeDoubleBE(123.456, 0); +let result = buf.writeDoubleBE(123.456, 0); ``` ### writeDoubleLE @@ -2240,7 +2240,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(8); -buf.writeDoubleLE(123.456, 0); +let result = buf.writeDoubleLE(123.456, 0); ``` ### writeFloatBE @@ -2279,7 +2279,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(8); -buf.writeFloatBE(0xcafebabe, 0); +let result = buf.writeFloatBE(0xcafebabe, 0); ``` @@ -2319,7 +2319,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(8); -buf.writeFloatLE(0xcafebabe, 0); +let result = buf.writeFloatLE(0xcafebabe, 0); ``` ### writeInt8 @@ -2358,8 +2358,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(2); -buf.writeInt8(2, 0); -buf.writeInt8(-2, 1); +let result = buf.writeInt8(2, 0); +let result1 = buf.writeInt8(-2, 1); ``` @@ -2399,7 +2399,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(2); -buf.writeInt16BE(0x0102, 0); +let result = buf.writeInt16BE(0x0102, 0); ``` @@ -2439,7 +2439,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(2); -buf.writeInt16LE(0x0304, 0); +let result = buf.writeInt16LE(0x0304, 0); ``` ### writeInt32BE @@ -2478,7 +2478,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(4); -buf.writeInt32BE(0x01020304, 0); +let result = buf.writeInt32BE(0x01020304, 0); ``` @@ -2518,7 +2518,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(4); -buf.writeInt32LE(0x05060708, 0); +let result = buf.writeInt32LE(0x05060708, 0); ``` ### writeIntBE @@ -2558,7 +2558,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(6); -buf.writeIntBE(0x1234567890ab, 0, 6); +let result = buf.writeIntBE(0x1234567890ab, 0, 6); ``` @@ -2599,7 +2599,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(6); -buf.writeIntLE(0x1234567890ab, 0, 6); +let result = buf.writeIntLE(0x1234567890ab, 0, 6); ``` ### writeUInt8 @@ -2638,10 +2638,10 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(4); -buf.writeUInt8(0x3, 0); -buf.writeUInt8(0x4, 1); -buf.writeUInt8(0x23, 2); -buf.writeUInt8(0x42, 3); +let result = buf.writeUInt8(0x3, 0); +let result1 = buf.writeUInt8(0x4, 1); +let result2 = buf.writeUInt8(0x23, 2); +let result3 = buf.writeUInt8(0x42, 3); ``` ### writeUInt16BE @@ -2680,8 +2680,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(4); -buf.writeUInt16BE(0xdead, 0); -buf.writeUInt16BE(0xbeef, 2); +let result = buf.writeUInt16BE(0xdead, 0); +let result1 = buf.writeUInt16BE(0xbeef, 2); ``` ### writeUInt16LE @@ -2720,8 +2720,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(4); -buf.writeUInt16LE(0xdead, 0); -buf.writeUInt16LE(0xbeef, 2); +let result = buf.writeUInt16LE(0xdead, 0); +let result1 = buf.writeUInt16LE(0xbeef, 2); ``` ### writeUInt32BE @@ -2760,7 +2760,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(4); -buf.writeUInt32BE(0xfeedface, 0); +let result = buf.writeUInt32BE(0xfeedface, 0); ``` ### writeUInt32LE @@ -2799,7 +2799,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(4); -buf.writeUInt32LE(0xfeedface, 0); +let result = buf.writeUInt32LE(0xfeedface, 0); ``` ### writeUIntBE @@ -2839,7 +2839,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(6); -buf.writeUIntBE(0x1234567890ab, 0, 6); +let result = buf.writeUIntBE(0x1234567890ab, 0, 6); ``` ### writeUIntLE @@ -2879,7 +2879,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco import buffer from '@ohos.buffer'; let buf = buffer.allocUninitializedFromPool(6); -buf.writeUIntLE(0x1234567890ab, 0, 6); +let result = buf.writeUIntLE(0x1234567890ab, 0, 6); ``` ## Blob @@ -2906,7 +2906,7 @@ A constructor used to create a **Blob** instance. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | sources | string[] \| ArrayBuffer[] \| TypedArray[] \| DataView[] \| Blob[] | Yes| Data sources of the **Blob** instance.| -| options | Object | No| options:
- **endings**: 'transparent' or 'native'.
- **type**: type of the data in **Blob**.| +| options | Object | No| options:
- **endings**: specifies how the terminator **'\n'** is output. The value can be **'native'** or **'transparent'**. **'native'** means that the terminator follows the system. **'transparent'** means that the terminator stored in the **Blob** instance remains unchanged. The default value is **'transparent'**.
- **type**: type of the data in the **Blob** instance. This type represents the MIME type of the data. However, it is not used for type format validation. The default value is **''**.| **Example** @@ -2951,9 +2951,9 @@ Creates a **Blob** instance by copying specified data from this **Blob** instanc | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| start | number | No| Offset to the start position of the data to copy.| -| end | number | No| Offset to the end position of the data to copy.| -| type | string | No| Type of the data in the new **Blob** instance.| +| start | number | No| Offset to the start position of the data to copy. The default value is **0**.| +| end | number | No| Offset to the end position of the data to copy. The default value is the data length in the original **Blob** instance.| +| type | string | No| Type of the data in the new **Blob** instance. The default value is **''**.| **Return value** | Type| Description| diff --git a/en/application-dev/reference/apis/js-apis-deque.md b/en/application-dev/reference/apis/js-apis-deque.md index 46d97bd96c27c9d3f05d519ebde6ff1ed8d3e4c5..7242e7dabbf12e7e44a98fa23bc44b9ead440a1e 100644 --- a/en/application-dev/reference/apis/js-apis-deque.md +++ b/en/application-dev/reference/apis/js-apis-deque.md @@ -156,9 +156,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let deque = new Deque(); -let result = deque.has("squirrel"); deque.insertFront("squirrel"); -let result1 = deque.has("squirrel"); +let result = deque.has("squirrel"); ``` ### popFirst diff --git a/en/application-dev/reference/apis/js-apis-hashmap.md b/en/application-dev/reference/apis/js-apis-hashmap.md index 807394ad4538e34997ac5b5eb917e47aad295161..c880644673fd9a8cd9d15ac05ec01afc9785bf3e 100644 --- a/en/application-dev/reference/apis/js-apis-hashmap.md +++ b/en/application-dev/reference/apis/js-apis-hashmap.md @@ -119,9 +119,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let hashMap = new HashMap(); -let result = hashMap.hasKey("squirrel"); hashMap.set("squirrel", 123); -let result1 = hashMap.hasKey("squirrel"); +let result = hashMap.hasKey("squirrel"); ``` @@ -157,9 +156,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let hashMap = new HashMap(); -let result = hashMap.hasValue(123); hashMap.set("squirrel", 123); -let result1 = hashMap.hasValue(123); +let result = hashMap.hasValue(123); ``` @@ -230,6 +228,7 @@ let hashMap = new HashMap(); hashMap.set("squirrel", 123); hashMap.set("sparrow", 356); let newHashMap = new HashMap(); +newHashMap.set("newMap", 99); hashMap.setAll(newHashMap); ``` diff --git a/en/application-dev/reference/apis/js-apis-hashset.md b/en/application-dev/reference/apis/js-apis-hashset.md index 8d21ef6d1994144aeb89be8d226ef041bdbdb95a..df65bfcb4a3167ed9c9f2292065554a505e9f4e1 100644 --- a/en/application-dev/reference/apis/js-apis-hashset.md +++ b/en/application-dev/reference/apis/js-apis-hashset.md @@ -1,8 +1,5 @@ # @ohos.util.HashSet (Nonlinear Container HashSet) -> **NOTE** -> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. - **HashSet** is implemented based on [HashMap](js-apis-hashmap.md). In **HashSet**, only the **value** object is processed. Unlike [TreeSet](js-apis-treeset.md), which stores and accesses data in sorted order, **HashSet** stores data in a random order. This means that **HashSet** may use a different order when storing and accessing elements. Both of them allows only unique elements. However, null values are allowed in **HashSet**, but not allowed in **TreeSet**. @@ -12,6 +9,11 @@ Unlike [TreeSet](js-apis-treeset.md), which stores and accesses data in sorted o This topic uses the following to identify the use of generics: - T: Type +> **NOTE** +> +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + ## Modules to Import ```ts @@ -125,9 +127,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let hashSet = new HashSet(); -let result = hashSet.has("squirrel"); hashSet.add("squirrel"); -let result1 = hashSet.has("squirrel"); +let result = hashSet.has("squirrel"); ``` diff --git a/en/application-dev/reference/apis/js-apis-lightweightmap.md b/en/application-dev/reference/apis/js-apis-lightweightmap.md index 057dc7e3f1f52f8d491ed1edf35037d42c7ee337..ed1848ad8df12b8a5526699908347ade635a9041 100644 --- a/en/application-dev/reference/apis/js-apis-lightweightmap.md +++ b/en/application-dev/reference/apis/js-apis-lightweightmap.md @@ -1,8 +1,5 @@ # @ohos.util.LightWeightMap (Nonlinear Container LightWeightMap) -> **NOTE** -> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. - **LightWeightMap** stores key-value (KV) pairs. Each key must be unique and have only one value. **LightWeightMap** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion. @@ -17,6 +14,11 @@ This topic uses the following to identify the use of generics: - K: Key - V: Value +> **NOTE** +> +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + ## Modules to Import ```ts @@ -197,9 +199,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let lightWeightMap = new LightWeightMap(); -let result = lightWeightMap.hasValue(123); lightWeightMap.set("squirrel", 123); -let result1 = lightWeightMap.hasValue(123); +let result = lightWeightMap.hasValue(123); ``` diff --git a/en/application-dev/reference/apis/js-apis-lightweightset.md b/en/application-dev/reference/apis/js-apis-lightweightset.md index 47295b0dd86d5b805607850b92a9692f71940dc7..05eba80d96783d32a427f1181bdc5b71bdab596b 100644 --- a/en/application-dev/reference/apis/js-apis-lightweightset.md +++ b/en/application-dev/reference/apis/js-apis-lightweightset.md @@ -1,8 +1,5 @@ # @ohos.util.LightWeightSet (Nonlinear Container LightWeightSet) -> **NOTE** -> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. - **LightWeightSet** stores a set of values, each of which must be unique. **LightWeightSet** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion. @@ -16,6 +13,11 @@ Compared with **[HashSet](js-apis-hashset.md)**, which can also store values, ** This topic uses the following to identify the use of generics: - T: Type +> **NOTE** +> +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + ## Modules to Import ```ts @@ -227,9 +229,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let lightWeightSet = new LightWeightSet(); -let result = lightWeightSet.has(123); lightWeightSet.add(123); -result = lightWeightSet.has(123); +let result = lightWeightSet.has(123); ``` @@ -267,7 +268,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco let lightWeightSet = new LightWeightSet(); lightWeightSet.add("squirrel"); lightWeightSet.add("sparrow"); -let obj = ["squirrel", "sparrow"]; +let obj = ["sparrow", "squirrel"]; let result = lightWeightSet.equal(obj); ``` diff --git a/en/application-dev/reference/apis/js-apis-linkedlist.md b/en/application-dev/reference/apis/js-apis-linkedlist.md index ceb144301277ac8cdd08f52713ae6cf576817a18..14382577e7b3fb1881e74527b8ec31ab87a89169 100644 --- a/en/application-dev/reference/apis/js-apis-linkedlist.md +++ b/en/application-dev/reference/apis/js-apis-linkedlist.md @@ -198,7 +198,6 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let linkedList = new LinkedList(); -let result1 = linkedList.has("squirrel"); linkedList.add("squirrel"); let result = linkedList.has("squirrel"); ``` @@ -802,7 +801,7 @@ linkedList.add(2); linkedList.add(4); linkedList.add(5); linkedList.add(4); -linkedList.getLast(); +let result = linkedList.getLast(); ``` ### [Symbol.iterator] diff --git a/en/application-dev/reference/apis/js-apis-list.md b/en/application-dev/reference/apis/js-apis-list.md index 295824f50139aca548f3dcd5952ce75c2bec7cfc..b7618d64c1d61a52324ada111347f666e7095c73 100644 --- a/en/application-dev/reference/apis/js-apis-list.md +++ b/en/application-dev/reference/apis/js-apis-list.md @@ -13,6 +13,7 @@ This topic uses the following to identify the use of generics: > > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + ## Modules to Import ```ts @@ -160,9 +161,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let list = new List(); -let result = list.has("squirrel"); list.add("squirrel"); -let result1 = list.has("squirrel"); +let result = list.has("squirrel"); ``` ### get @@ -288,7 +288,6 @@ list.add(2); list.add(1); list.add(2); list.add(4); -list.getIndexOf(2); let result = list.getIndexOf(2); ``` @@ -327,14 +326,11 @@ let list = new List(); list.add(2); list.add(4); list.add(5); -list.add(2); -let obj1 = new List(); -obj1.add(2); -obj1.add(4); -obj1.add(5); -list.equal(obj1); -let obj2 = {name : "Dylon", age : "13"}; -let result = list.equal(obj2); +let obj = new List(); +obj.add(2); +obj.add(4); +obj.add(5); +let result = list.equal(obj); ``` ### removeByIndex @@ -457,11 +453,9 @@ list.add(2); list.add(4); list.add(5); list.add(4); -list.replaceAllElements((value: number, index: number) => { - return value = 2 * value; -}); -list.replaceAllElements((value: number, index: number) => { - return value = value - 2; +list.replaceAllElements((value) => { + // Add the user operation logic based on the actual scenario. + return value; }); ``` @@ -589,9 +583,7 @@ list.add(2); list.add(4); list.add(5); list.add(4); -let result = list.getSubList(2, 4); -let result1 = list.getSubList(4, 3); -let result2 = list.getSubList(2, 6); +let result = list.getSubList(1, 3); ``` ### clear @@ -659,7 +651,7 @@ list.add(2); list.add(4); list.add(5); list.add(4); -list.set(2, "b"); +let result = list.set(2, "b"); ``` ### convertToArray diff --git a/en/application-dev/reference/apis/js-apis-plainarray.md b/en/application-dev/reference/apis/js-apis-plainarray.md index 387577bb2409ae399f46a225e53e3d00db9035e6..14f73f6d4b11059551b376f7fcb9e56ee4e1ab84 100644 --- a/en/application-dev/reference/apis/js-apis-plainarray.md +++ b/en/application-dev/reference/apis/js-apis-plainarray.md @@ -1,8 +1,5 @@ # @ohos.util.PlainArray (Nonlinear Container PlainArray) -> **NOTE** -> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. - **PlainArray** stores key-value (KV) pairs. Each key must be unique, be of the number type, and have only one value. **PlainArray** is based on generics and uses a lightweight structure. Keys in the array are searched using binary search and are mapped to values in other arrays. @@ -14,6 +11,11 @@ Both **PlainArray** and **[LightWeightMap](js-apis-lightweightmap.md)** are used This topic uses the following to identify the use of generics: - T: Type +> **NOTE** +> +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + ## Modules to Import ```ts @@ -21,7 +23,6 @@ import PlainArray from '@ohos.util.PlainArray'; ``` - ## PlainArray ### Attributes @@ -118,9 +119,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let plainArray = new PlainArray(); -plainArray.has(1); plainArray.add(1, "squirrel"); -let result1 = plainArray.has(1); +let result = plainArray.has(1); ``` diff --git a/en/application-dev/reference/apis/js-apis-queue.md b/en/application-dev/reference/apis/js-apis-queue.md index 56bb71d5b88e93c2364c23176543f131d134e9f2..c926b741543cd384f6c4b7649c2e8f1881883a55 100644 --- a/en/application-dev/reference/apis/js-apis-queue.md +++ b/en/application-dev/reference/apis/js-apis-queue.md @@ -1,8 +1,5 @@ # @ohos.util.Queue (Linear Container Queue) -> **NOTE** -> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. - **Queue** follows the principle of First In First Out (FIFO). It supports insertion of elements at the end and removal from the front of the queue. **Queue** is implemented based on the queue data structure. Unlike **[Deque](js-apis-deque.md)**, which supports insertion and removal at both the ends, **Queue** supports insertion at one end and removal at the other end. @@ -12,6 +9,11 @@ Unlike **[Deque](js-apis-deque.md)**, which supports insertion and removal at bo This topic uses the following to identify the use of generics: - T: Type +> **NOTE** +> +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + ## Modules to Import ```ts diff --git a/en/application-dev/reference/apis/js-apis-stack.md b/en/application-dev/reference/apis/js-apis-stack.md index 46b06f608af9615bbb138bc54d82cab7f566c0fa..9ecf69bced25271e1c68299bb78e2a19bbaab756 100644 --- a/en/application-dev/reference/apis/js-apis-stack.md +++ b/en/application-dev/reference/apis/js-apis-stack.md @@ -1,8 +1,5 @@ # @ohos.util.Stack (Linear Container Stack) -> **NOTE** -> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. - **Stack** is implemented based on the array data structure. It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end. Unlike **[Queue](js-apis-queue.md)**, which is implemented based on the queue data structure and supports insertion at one end and removal at the other end, **Stack** supports insertion and removal at the same end. @@ -12,6 +9,11 @@ Unlike **[Queue](js-apis-queue.md)**, which is implemented based on the queue da This topic uses the following to identify the use of generics: - T: Type +> **NOTE** +> +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + ## Modules to Import ```ts diff --git a/en/application-dev/reference/apis/js-apis-treemap.md b/en/application-dev/reference/apis/js-apis-treemap.md index 473b5cb99e94c1ab84069d23591b63555bfcb7d5..f05edc6533e92d21c49cf1dd2c91b7e9aa12ff0a 100644 --- a/en/application-dev/reference/apis/js-apis-treemap.md +++ b/en/application-dev/reference/apis/js-apis-treemap.md @@ -18,6 +18,7 @@ This topic uses the following to identify the use of generics: > > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + ## Modules to Import ```ts @@ -126,9 +127,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let treeMap = new TreeMap(); -let result = treeMap.hasKey("squirrel"); treeMap.set("squirrel", 123); -let result1 = treeMap.hasKey("squirrel"); +let result = treeMap.hasKey("squirrel"); ``` @@ -164,9 +164,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let treeMap = new TreeMap(); -let result = treeMap.hasValue(123); treeMap.set("squirrel", 123); -let result1 = treeMap.hasValue(123); +let result = treeMap.hasValue(123); ``` @@ -304,7 +303,7 @@ let map = new TreeMap(); map.set("demo", 12); map.setAll(treeMap); // Add all elements in the treeMap to the map. map.forEach((value, key) => { - console.log("test" + value, key); // Print result: 12 demo, 356 sparrow, and 123 squirrel + console.log("value" + value, "key" + key); // Print result: 12 demo, 356 sparrow, and 123 squirrel }) ``` @@ -380,7 +379,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco let treeMap = new TreeMap(); treeMap.set("squirrel", 123); treeMap.set("sparrow", 356); -treeMap.remove("sparrow"); +let result = treeMap.remove("sparrow"); ``` diff --git a/en/application-dev/reference/apis/js-apis-treeset.md b/en/application-dev/reference/apis/js-apis-treeset.md index 5ca493adcae4ff144341f04d9d1641035ae98db8..b3259d3ccbf19fab20c027accad98c6519bf7f52 100644 --- a/en/application-dev/reference/apis/js-apis-treeset.md +++ b/en/application-dev/reference/apis/js-apis-treeset.md @@ -14,6 +14,7 @@ This topic uses the following to identify the use of generics: > > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. + ## Modules to Import ```ts @@ -122,9 +123,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```ts let treeSet = new TreeSet(); -treeSet.has(123); treeSet.add(123); -let result1 = treeSet.has(123); +let result = treeSet.has(123); ``` diff --git a/en/application-dev/reference/apis/js-apis-uri.md b/en/application-dev/reference/apis/js-apis-uri.md index a8aed60f4a0bf23080f223eec440742847a258aa..78711db7ce38b363f068e679ce9c25187ebb414c 100644 --- a/en/application-dev/reference/apis/js-apis-uri.md +++ b/en/application-dev/reference/apis/js-apis-uri.md @@ -145,7 +145,7 @@ Obtains the query string applicable to this URI. ```js const result = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -result.toString() +let result1 = result.toString(); ``` @@ -205,7 +205,7 @@ Checks whether this URI is the same as another URI object. ```js const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -uriInstance.equalsTo(uriInstance1); +let result = uriInstance.equalsTo(uriInstance1); ``` ### checkIsAbsolute diff --git a/en/application-dev/reference/apis/js-apis-url.md b/en/application-dev/reference/apis/js-apis-url.md index d4d453a59685a23f228ca2d4bc7e56ac0608a8e8..24f66154decc36532fdc49d4bb3273ccf8a81ba1 100755 --- a/en/application-dev/reference/apis/js-apis-url.md +++ b/en/application-dev/reference/apis/js-apis-url.md @@ -225,7 +225,7 @@ Checks whether a key has a value. ```js let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2'); let paramsObject = new Url.URLParams(urlObject.search.slice(1)); -paramsObject.has('bard') === true; +let result = paramsObject.has('bard'); ``` @@ -336,7 +336,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th ```js const paramsObject = new Url.URLParams('fod=bay&edg=bap'); -for (const [name, value] of paramsObject) { +for (const [name, value] of paramsObject[Symbol.iterator]()) { console.log(name, value); } ``` @@ -460,7 +460,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco ```js let mm = 'https://username:password@host:8080'; let url = Url.URL.parseURL(mm); -url.toString(); // Output 'https://username:password@host:8080/'; +let result = url.toString(); // Output 'https://username:password@host:8080/' ``` ### tostring @@ -481,7 +481,7 @@ Converts the parsed URL into a string. ```js const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -url.toString(); +let result = url.toString(); ``` ### toJSON @@ -501,7 +501,7 @@ Converts the parsed URL into a JSON string. **Example** ```js const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -url.toJSON(); +let result = url.toJSON(); ``` ## URLSearchParams(deprecated) diff --git a/en/application-dev/reference/apis/js-apis-util.md b/en/application-dev/reference/apis/js-apis-util.md index 16a80bd27e4c9b89397afcaaa83d098fe91eaa10..1a60dc51ae1404aee3947f799c166180ac13dde2 100755 --- a/en/application-dev/reference/apis/js-apis-util.md +++ b/en/application-dev/reference/apis/js-apis-util.md @@ -1,6 +1,6 @@ # @ohos.util (util) -The **util** module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types. +The **util** module provides common utility functions, such as [TextEncoder](#textencoder) and [TextDecoder](#textdecoder) for string encoding and decoding, [RationalNumber8+](#rationalnumber8) for rational number operations, [LRUCache9+](#lrucache9) for cache management, [ScopeHelper9+](#scopehelper9) for range determination, [Base64Helper9+](#base64helper9) for Base64 encoding and decoding, and [types8+](#types8) for built-in object type check. > **NOTE** > @@ -337,6 +337,8 @@ Processes an asynchronous function and returns a promise. ## TextDecoder +Provides APIs to decode byte arrays into strings. It supports multiple formats, including UTF-8, UTF-16LE, UTF-16BE, ISO-8859, and Windows-1251. + ### Attributes **System capability**: SystemCapability.Utils.Lang @@ -367,15 +369,15 @@ Creates a **TextDecoder** object. It provides the same function as the deprecate | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------ | -| encoding | string | No | Encoding format. | +| encoding | string | No | Encoding format. The default format is **'utf-8'**. | | options | Object | No | Encoding-related options, which include **fatal** and **ignoreBOM**.| **Table 1.1** options | Name | Type| Mandatory| Description | | --------- | -------- | ---- | ------------------ | -| fatal | boolean | No | Whether to display fatal errors.| -| ignoreBOM | boolean | No | Whether to ignore the BOM. | +| fatal | boolean | No | Whether to display fatal errors. The default value is **false**.| +| ignoreBOM | boolean | No | Whether to ignore the BOM. The default value is **false**. | **Example** @@ -443,15 +445,15 @@ A constructor used to create a **TextDecoder** object. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| encoding | string | No| Encoding format.| +| encoding | string | No| Encoding format. The default format is **'utf-8'**.| | options | Object | No| Encoding-related options, which include **fatal** and **ignoreBOM**.| **Table 1** options | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| fatal | boolean | No| Whether to display fatal errors.| -| ignoreBOM | boolean | No| Whether to ignore the BOM.| +| fatal | boolean | No| Whether to display fatal errors. The default value is **false**.| +| ignoreBOM | boolean | No| Whether to ignore the BOM. The default value is **false**.| **Example** @@ -508,13 +510,15 @@ Decodes the input content. ## TextEncoder +Provides APIs to encode strings into byte arrays. It supports multiple formats, including UTF-8, UTF-16LE, and UTF-16BE. When **TextEncoder** is used for encoding, the number of bytes occupied by a character varies according to the encoding format. For example, a Chinese character usually occupies three bytes in UTF-8 encoding format but two bytes in UTF-16LE or UTF-16BE encoding format. Therefore, when using **TextEncoder**, you must explicitly specify the encoding format to obtain the required encoding result. + ### Attributes **System capability**: SystemCapability.Utils.Lang | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.| +| encoding | string | Yes| No| Encoding format. The default format is **'utf-8'**.| ### constructor @@ -679,6 +683,8 @@ Encodes the input content. ## RationalNumber8+ +Provides APIs to compare rational numbers and obtain numerators and denominators. For example, the **toString()** API can be used to convert a rational number into a strings. + ### constructor9+ constructor() @@ -1063,6 +1069,8 @@ let result = util.RationalNumber.getCommonDivisor(4,6); ## LRUCache9+ +Provides APIs to discard the least recently used data to make rooms for new elements when the cache is full. This class uses the Least Recently Used (LRU) algorithm, which believes that the recently used data may be accessed again in the near future and the least accessed data is the least valuable data and should be removed from the cache. + ### Attributes **System capability**: SystemCapability.Utils.Lang @@ -1119,7 +1127,7 @@ Changes the **LruCache** capacity. If the new capacity is less than or equal to ```js let pro = new util.LRUCache(); -let result = pro.updateCapacity(100); +pro.updateCapacity(100); ``` @@ -1668,6 +1676,8 @@ Defines the type of values in a **Scope** object. ## ScopeHelper9+ +Provides APIs to define the valid range of a field. The constructor of this class creates comparable objects with lower and upper limits. + ### constructor9+ constructor(lowerObj: ScopeType, upperObj: ScopeType) @@ -1954,7 +1964,7 @@ let tempLower = new Temperature(30); let tempUpper = new Temperature(40); let tempMiDF = new Temperature(35); let range = new util.ScopeHelper(tempLower, tempUpper); -range.contains(tempMiDF); +let result = range.contains(tempMiDF); ``` @@ -2023,6 +2033,8 @@ let result = range.clamp(tempMiDF); ## Base64Helper9+ +The Base64 encoding table contains 62 characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). During encoding, the original data is divided into groups of three bytes, and each group contains a 6-bit number. Then, the corresponding characters in the Base64 encoding table are used to represent these numbers. If the last group contains only one or two bytes, the equal sign (=) is used for padding. + ### constructor9+ constructor() @@ -2224,6 +2236,8 @@ that.decode(array).then(val=>{ ## types8+ +Provides APIs to check different types of built-in objects, such as ArrayBuffer, Map, and Set, so as to avoid exceptions or crashes caused by type errors. + ### constructor8+ constructor()