diff --git a/en/application-dev/reference/apis/js-apis-abilityAccessCtrl.md b/en/application-dev/reference/apis/js-apis-abilityAccessCtrl.md new file mode 100644 index 0000000000000000000000000000000000000000..b69cb0e03eb33b0e683d773b4bdcb5a379bb6a41 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-abilityAccessCtrl.md @@ -0,0 +1,219 @@ +# Ability Access Control + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **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 + +``` +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' +``` + +## System Capabilities +SystemCapability.Security.AccessToken + +## abilityAccessCtrl.createAtManager + +createAtManager(): AtManager + +Creates an **AtManager** instance, which is used for ability access control. + +**Return value** + +| Type| Description| +| -------- | -------- | +| [AtManager](#atmanager) | **AtManager** instance obtained.| + +**Example** + +``` +var AtManager = abilityAccessCtrl.createAtManager(); +``` + +## AtManager + +Implements ability access control. + +### verifyAccessToken + +verifyAccessToken(tokenID: number, permissionName: string): Promise<GrantStatus> + +Checks whether an application has been granted the specified permission. This method uses a promise to return the result. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------- | ---- | ------------------------------------------ | +| tokenID | number | Yes| ID of the application.| +| permissionName | string | Yes| Name of the permission to verify.| + +**Return value** + +| Type| Description| +| :------------ | :---------------------------------- | +| Promise<GrantStatus> | Promise instance used to return the result.| + +**Example** + +``` +const AtManager = abilityAccessCtrl.createAtManager(); +let tokenID = 0; +let promise = AtManager.verifyAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); +promise.then(data => { + console.log(`promise: data->${JSON.stringify(data)}`); +}); +``` + +### grantUserGrantedPermission + +grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number): Promise<number> + +Grants a user granted permission to an application. This method uses a promise to return the result. + +Required permission: ohos.permission.GRANT_SENSITIVE_PERMISSIONS + +**Parameters** + +| Name| Type| Mandatory| Description| +| --------- | ------------------- | ---- | ------------------------------------------------------------ | +| tokenID | number | Yes| ID of the application.| +| permissionName | string | Yes| Name of the permission to grant.| +| permissionFlag | number | Yes| Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed.| + +**Return value** + +| Type| Description| +| :------------ | :---------------------------------- | +| Promise<number> | Promise instance used to return the result.| + +**Example** + +``` +const AtManager = abilityAccessCtrl.createAtManager(); +let tokenID = 0; +let promise = AtManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); +promise.then(data => { + console.log(`promise: data->${JSON.stringify(data)}`); +}); +``` + + + +### grantUserGrantedPermission + +grantUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number, callback: AsyncCallback<number>): void + +Grants a user granted permission to an application. This method uses an asynchronous callback to return the result. + +Required permission: ohos.permission.GRANT_SENSITIVE_PERMISSIONS + +**Parameters** + +| Name| Type| Mandatory| Description| +| --------- | ------------------- | ---- | ------------------------------------------------------------ | +| tokenID | number | Yes| ID of the application.| +| permissionName | string | Yes| Name of the permission to grant.| +| permissionFlag | number | Yes| Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed.| +| callback | AsyncCallback<number> | Yes| Callback used to return the result.| + +**Example** + +``` +const AtManager = abilityAccessCtrl.createAtManager(); +let tokenID = 0; +let permissionFlag = 1; +AtManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",permissionFlag, data => { + console.log(`callback: data->${JSON.stringify(data)}`); +}); +``` + +### revokeUserGrantedPermission + +revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number): Promise<number> + +Revokes a user granted permission given to an application. This method uses a promise to return the result. + +Required permission: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS + +**Parameters** + +| Name| Type| Mandatory| Description| +| --------- | ------------------- | ---- | ------------------------------------------------------------ | +| tokenID | number | Yes| ID of the application.| +| permissionName | string | Yes| Name of the permission to revoke.| +| permissionFlag | number | Yes| Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed.| + +**Return value** + +| Type| Description| +| :------------ | :---------------------------------- | +| Promise<number> | Promise instance used to return the result.| + +**Example** + +``` +const AtManager = abilityAccessCtrl.createAtManager(); +let tokenID = 0; +let permissionFlag = 1; +let promise = AtManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag); +promise.then(data => { + console.log(`promise: data->${JSON.stringify(data)}`); +}); +``` + +### revokeUserGrantedPermission + +revokeUserGrantedPermission(tokenID: number, permissionName: string, permissionFlag: number, callback: AsyncCallback<number>): void + +Revokes a user granted permission given to an application. This method uses an asynchronous callback to return the result. + +Required permission: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS + +**Parameters** + +| Name| Type| Mandatory| Description| +| --------- | ------------------- | ---- | ------------------------------------------------------------ | +| tokenID | number | Yes| ID of the application.| +| permissionName | string | Yes| Name of the permission to revoke.| +| permissionFlag | number | Yes| Permission flag. The value **1** means that a dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed.| +| callback | AsyncCallback<number> | Yes| Callback used to return the result.| + +**Example** + +``` +const AtManager = abilityAccessCtrl.createAtManager(); +let tokenID = 0; +AtManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",permissionFlag, data => { + console.log(`callback: data->${JSON.stringify(data)}`); +}); +``` + +### getPermissionFlags + +getPermissionFlags(tokenID: number, permissionName: string): Promise<number> + +Obtains the flags of the specified permission of a given application. This method uses a promise to return the result. + +**Parameters** + +| Name| Type| Mandatory| Description| +| --------- | ------------------- | ---- | ------------------------------------------------------------ | +| tokenID | number | Yes| ID of the application.| +| permissionName | string | Yes| Name of the permission to query.| + +**Return value** + +| Type| Description| +| :------------ | :---------------------------------- | +| Promise<number> | Promise instance used to return the result.| + +**Example** + +``` +const AtManager = abilityAccessCtrl.createAtManager(); +let tokenID = 0; +let promise = AtManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); +promise.then(data => { + console.log(`promise: data->${JSON.stringify(data)}`); +}); +``` diff --git a/en/application-dev/reference/apis/js-apis-convertxml.md b/en/application-dev/reference/apis/js-apis-convertxml.md index 7d3d923d94128325d197e6fda5d97c8c08752cd6..78cc0b59d10349c97dc3394e8d14442a5efc0604 100644 --- a/en/application-dev/reference/apis/js-apis-convertxml.md +++ b/en/application-dev/reference/apis/js-apis-convertxml.md @@ -1,277 +1,78 @@ -# XML-to-JavaScript Conversion +# XML-to-JavaScript Conversion ->![](public_sys-resources/icon-note.gif) **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. +> **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 + +## Modules to Import ``` import convertxml from '@ohos.convertxml'; ``` -## Required Permissions - -None - -## ConvertXML - -### convert - -convert\(xml: string, options?: ConvertOptions\) : Object +## System Capabilities -Converts an XML text into a JavaScript object. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

xml

-

string

-

Yes

-

XML text to convert.

-

options

-

ConvertOptions

-

No

-

Settings of the convert operation.

-
+SystemCapability.Utils.Lang -- Return values +## ConvertXML - - - - - - - - - -

Type

-

Description

-

string

-

JavaScript object.

-
-- Example +### convert - ``` - var xml = - '' + - '' + - ' Happy' + - ' Work' + - ' Play' + - ''; - var conv = new convertxml.ConvertXML(); - var result1 = conv.convert(xml, {trim: false, ignoreDeclaration: false}); - console.log(result1) - ``` +convert(xml: string, options?: ConvertOptions) : Object +Converts an XML text into a JavaScript object. -## ConvertOptions - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

trim

-

boolean

-

No

-

Whether to trim the whitespace characters before and after the text. The default value is false.

-

ignoreDeclaration

-

boolean

-

No

-

Whether to ignore the XML declaration. The default value is false.

-

ignoreInstruction

-

boolean

-

No

-

Whether to ignore the XML processing instruction. The default value is false.

-

ignoreAttributes

-

boolean

-

No

-

Whether to print attributes across multiple lines and indent attributes. The default value is false.

-

ignoreComment

-

boolean

-

No

-

Whether to ignore element comments. The default value is false.

-

ignoreCDATA

-

boolean

-

No

-

Whether to ignore the element's CDATA information. The default value is false.

-

ignoreDoctype

-

boolean

-

No

-

Whether to ignore the element's Doctype information. The default value is false.

-

ignoreText

-

boolean

-

No

-

Whether to ignore the element's text information. The default value is false.

-

declarationKey

-

string

-

No

-

Name of the attribute key for declaration in the output object. The default value is _declaration.

-

instructionKey

-

string

-

No

-

Name of the attribute key for instruction in the output object. The default value is _instruction.

-

attributesKey

-

string

-

No

-

Name of the attribute key for attributes in the output object. The default value is _attributes.

-

textKey

-

string

-

No

-

Name of the attribute key for text in the output object. The default value is _text.

-

cdataKey

-

string

-

No

-

Name of the attribute key for CDATA in the output object. The default value is _cdata.

-

doctypeKey

-

string

-

No

-

Name of the attribute key for Doctype in the output object. The default value is _doctype.

-

commentKey

-

string

-

No

-

Name of the attribute key for comment in the output object. The default value is _comment.

-

parentKey

-

string

-

No

-

Name of the attribute key for parent in the output object. The default value is _parent.

-

typeKey

-

string

-

No

-

Name of the attribute key for type in the output object. The default value is _type.

-

nameKey

-

string

-

No

-

Name of the attribute key for name in the output object. The default value is _name.

-

elementsKey

-

string

-

No

-

Name of the attribute key for elements in the output object. The default value is _elements.

-
+- Parameters + + | Name| Type| Mandatory| Description| + | ------- | --------------------------------- | ---- | ------------------ | + | xml | string | Yes| XML text to convert.| + | options | [ConvertOptions](#convertoptions) | No| Settings of the convert operation.| + +- Return value + + | Type| Description| + | ------ | ---------------------------- | + | string | JavaScript object.| + +- Example + + ``` + var xml = + '' + + '' + + ' Happy' + + ' Work' + + ' Play' + + ''; + var conv = new convertxml.ConvertXML(); + var result1 = conv.convert(xml, {trim: false, ignoreDeclaration: false}); + console.log(result1) + ``` + + +## ConvertOptions + +| Name| Type| Mandatory| Description| +| ----------------- | -------- | ---- | ----------------------------------------------------------- | +| trim | boolean | No| Whether to trim the whitespace characters before and after the text. The default value is **false**.| +| ignoreDeclaration | boolean | No| Whether to ignore the XML declaration. The default value is **false**.| +| ignoreInstruction | boolean | No| Whether to ignore the XML processing instruction. The default value is **false**.| +| ignoreAttributes | boolean | No| Whether to print attributes across multiple lines and indent attributes. The default value is **false**.| +| ignoreComment | boolean | No| Whether to ignore element comments. The default value is **false**.| +| ignoreCDATA | boolean | No| Whether to ignore the element's CDATA information. The default value is **false**.| +| ignoreDoctype | boolean | No| Whether to ignore the element's Doctype information. The default value is **false**.| +| ignoreText | boolean | No| Whether to ignore the element's text information. The default value is **false**.| +| declarationKey | string | No| Name of the attribute key for **declaration** in the output object. The default value is **_declaration**.| +| instructionKey | string | No| Name of the attribute key for **instruction** in the output object. The default value is **_instruction**.| +| attributesKey | string | No| Name of the attribute key for **attributes** in the output object. The default value is **_attributes**.| +| textKey | string | No| Name of the attribute key for **text** in the output object. The default value is **_text**.| +| cdataKey | string | No| Name of the attribute key for **CDATA** in the output object. The default value is **_cdata**.| +| doctypeKey | string | No| Name of the attribute key for **Doctype** in the output object. The default value is **_doctype**.| +| commentKey | string | No| Name of the attribute key for **comment** in the output object. The default value is **_comment**.| +| parentKey | string | No| Name of the attribute key for **parent** in the output object. The default value is **_parent**.| +| typeKey | string | No| Name of the attribute key for **type** in the output object. The default value is **_type**.| +| nameKey | string | No| Name of the attribute key for **name** in the output object. The default value is **_name**.| +| elementsKey | string | No| Name of the attribute key for **elements** in the output object. The default value is **_elements**.| diff --git a/en/application-dev/reference/apis/js-apis-faultLogger.md b/en/application-dev/reference/apis/js-apis-faultLogger.md index 05ce1637ae623fc37964847c2f0ead44fb8cac0d..10ac56bb7e13b598ae6d30cae770b5dcefcaee82 100644 --- a/en/application-dev/reference/apis/js-apis-faultLogger.md +++ b/en/application-dev/reference/apis/js-apis-faultLogger.md @@ -44,13 +44,15 @@ querySelfFaultLog(faultType: FaultType, callback: AsyncCallback<Array<Faul Obtains the fault information about the current process. This method uses a callback to return the fault information array obtained, which contains a maximum of 10 pieces of fault information. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | faultType | [FaultType](#faulttype) | Yes| Fault type.| - | callback | AsyncCallbackArray<Array<[FaultLogInfo](#faultloginfo)>> | Yes| Callback used to return the fault information array.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned. +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| faultType | [FaultType](#faulttype) | Yes| Fault type.| +| callback | AsyncCallbackArray<Array<[FaultLogInfo](#faultloginfo)>> | Yes| Callback used to return the fault information array.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval. In this case, an error string will be returned. + +**Example** -- Example ``` function queryFaultLogCallback(error, value) { if (error) { @@ -80,17 +82,20 @@ querySelfFaultLog(faultType: FaultType) : Promise<Array<FaultLogInfo>&g Obtains the fault information about the current process. This method uses a promise to return the fault information array obtained, which contains a maximum of 10 pieces of fault information. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | faultType | [FaultType](#faulttype) | Yes| Fault type.| +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| faultType | [FaultType](#faulttype) | Yes| Fault type.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| Promise<Array<[FaultLogInfo](#faultloginfo)>> | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.| -- Return value - | Type| Description| - | -------- | -------- | - | Promise<Array<[FaultLogInfo](#faultloginfo)>> | Promise used to return the fault information array. You can obtain the fault information instance in its **then()** method or use **await**.
The value is the fault information array obtained. If the value is **undefined**, an exception occurs during the information retrieval.| +**Example** -- Example ``` let value = await faultLogger.querySelfFaultLog(faultlogger.FaultType.JS_CRASH); if (value) { diff --git a/en/application-dev/reference/apis/js-apis-process.md b/en/application-dev/reference/apis/js-apis-process.md index 40c0baf56efe5173e0f1c679f21b1ec1e825821d..fa563d5a494b2c370950822e27c6397372f53669 100644 --- a/en/application-dev/reference/apis/js-apis-process.md +++ b/en/application-dev/reference/apis/js-apis-process.md @@ -1,1176 +1,551 @@ -# Obtaining Process Information +# Obtaining Process Information ->![](../../public_sys-resources/icon-note.gif) **NOTE:** ->The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Modules to Import + +## Modules to Import ``` import process from '@ohos.process'; ``` -## Required Permissions - -None - -## Attributes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

egid

-

number

-

Yes

-

No

-

Effective group identifier (EGID) of a process.

-

euid

-

number

-

Yes

-

No

-

Effective user identifier (EUID) of a process.

-

gid

-

number

-

Yes

-

No

-

Group identifier (GID) of a process.

-

uid

-

number

-

Yes

-

No

-

User identifier (UID) of a process.

-

groups

-

number[]

-

Yes

-

No

-

Array with supplementary group IDs.

-

pid

-

number

-

Yes

-

No

-

Process ID (PID) of a process.

-

ppid

-

number

-

Yes

-

No

-

Parent process ID (PPID) of a process.

-

tid8+

-

number

-

Yes

-

No

-

Thread ID (TID) of a process.

-
- -## ChildProcess - -Provides methods for a process to obtain the standard input and output of its child processes, send signals, and close its child processes. - -### Attributes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

pid

-

number

-

Yes

-

No

-

PID of the child process.

-

ppid

-

number

-

Yes

-

No

-

PPID of the child process.

-

exitCode

-

number

-

Yes

-

No

-

Exit code of the child process.

-

killed

-

boolean

-

Yes

-

No

-

Whether the parent process successfully sends a signal to the child process to terminate it.

-
- -### wait - -wait\(\): Promise +## System Capabilities + +SystemCapability.Utils.Lang + +## Attributes + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| egid | number | Yes| No| Effective group identifier (EGID) of a process.| +| euid | number | Yes| No| Effective user identifier (EUID) of a process.| +| gid | number | Yes| No| Group identifier (GID) of a process.| +| uid | number | Yes| No| User identifier (UID) of a process.| +| groups | number[] | Yes| No| Array with supplementary group IDs.| +| pid | number | Yes| No| Process ID (PID) of a process.| +| ppid | number | Yes| No| Parent process ID (PPID) of a process.| +| tid8+ | number | Yes| No| Thread ID (TID) of a process.| + + +## ChildProcess + +Allows a process to obtain the standard input and output of its child processes, send signals, and close its child processes. + + +### Attributes + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| pid | number | Yes| No| PID of the child process.| +| ppid | number | Yes| No| PPID of the child process.| +| exitCode | number | Yes| No| Exit code of the child process.| +| killed | boolean | Yes| No| Whether the parent process successfully sends a signal to the child process to terminate it.| + + +### wait + +wait(): Promise<number> Waits until the child process ends. This method uses a promise to return the exit code of the child process. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

Promise<number>

-

Promise used to return the exit code of the child process.

-
+| Type| Description| +| -------- | -------- | +| Promise<number> | Promise used to return the exit code of the child process.| -- Example +**Example** - ``` - var child = process.runCmd('ls'); - var result = child.wait(); - result.then(val=>{ - console.log("result = " + val); - }) - ``` +``` +var child = process.runCmd('ls'); +var result = child.wait(); +result.then(val=>{ + console.log("result = " + val); +}) +``` -### getOutput +### getOutput -getOutput\(\): Promise +getOutput(): Promise<Uint8Array> Obtains the standard output of the child process. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

Promise<Uint8Array>

-

Promise used to return the standard output in a Uint8Array.

-
+| Type| Description| +| -------- | -------- | +| Promise<Uint8Array> | Promise used to return the standard output in a Uint8Array.| -- Example +**Example** - ``` - var child = process.runCmd('ls'); - var result = child.wait(); - child.getOutput.then(val=>{ - console.log("child.getOutput = " + val); - }) - ``` +``` +var child = process.runCmd('ls'); +var result = child.wait(); +child.getOutput.then(val=>{ + console.log("child.getOutput = " + val); +}) +``` -### getErrorOutput +### getErrorOutput -getErrorOutput\(\): Promise +getErrorOutput(): Promise<Uint8Array> Obtains the standard error output of the child process. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

Promise<Uint8Array>

-

Promise used to return the standard error output in a Uint8Array.

-
+| Type| Description| +| -------- | -------- | +| Promise<Uint8Array> | Promise used to return the standard error output in a Uint8Array.| -- Example +**Example** - ``` - var child = process.runCmd('madir test.text'); - var result = child.wait(); - child.getErrorOutput.then(val=>{ - console.log("child.getErrorOutput= " + val); - }) - ``` +``` +var child = process.runCmd('madir test.text'); +var result = child.wait(); +child.getErrorOutput.then(val=>{ + console.log("child.getErrorOutput= " + val); +}) +``` -### close +### close -close\(\): void +close(): void Closes the child process in running. -- Example +**Example** - ``` - var child = process.runCmd('sleep 5; ls'); - child.close(); - ``` +``` +var child = process.runCmd('sleep 5; ls'); +child.close(); +``` -### kill +### kill -kill\(signal: number | string\): void +kill(signal: number | string): void Sends a signal to the specified child process to terminate it. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

signal

-

number | string

-

Yes

-

Number or string to send.

-
+**Parameters** -- Example +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| signal | number \| string | Yes| Number or string to send.| - ``` - var child = process.runCmd('sleep 5; ls'); - child.kill(9); - ``` +**Example** +``` +var child = process.runCmd('sleep 5; ls'); +child.kill(9); +``` -## process.isIsolatedProcess8+ -isIsolatedProcess\(\): boolean +## process.isIsolatedProcess8+ -Checks whether the process is isolated. +isIsolatedProcess(): boolean -- Return values +Checks whether this process is isolated. - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the process is isolated; returns false otherwise.

-
+**Return value** +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the process is isolated; returns **false** otherwise.| -- Example +**Example** - ``` - var result = process.isIsolatedProcess(); - ``` +``` +var result = process.isIsolatedProcess(); +``` -## process.isAppUid8+ +## process.isAppUid8+ -isAppUid\(v:number\): boolean +isAppUid(v:number): boolean Checks whether a UID belongs to this app. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

v

-

number

-

Yes

-

UID.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the UID is the app's UID; returns false otherwise.

-
- - -- Example - - ``` - var result = process.isAppUid(688); - ``` - - -## process.is64Bit8+ - -is64Bit\(\): boolean - -Checks whether the operating environment is of 64-bit. - -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the operating environment is of 64-bit; returns false otherwise.

-
- -- Example - - ``` - var ressult = process.is64Bit(); - ``` - - -## process.getUidForName8+ - -getUidForName\(v:string\): number +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| v | number | Yes| UID.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the UID is the app's UID; returns **false** otherwise.| + +**Example** + +``` +var result = process.isAppUid(688); +``` + + +## process.is64Bit8+ + +is64Bit(): boolean + +Checks whether this process is running in a 64-bit environment. + +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the process is running in a 64-bit environment; returns **false** otherwise.| + +**Example** + +``` +var ressult = process.is64Bit(); +``` + + +## process.getUidForName8+ + +getUidForName(v:string): number Obtains the process UID based on the process name. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

v

-

string

-

Yes

-

Process name.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Process UID.

-
- -- Example - - ``` - var pres = process.getUidForName("tool") - ``` - - -## process.getThreadPriority8+ - -getThreadPriority\(v:number\): number +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| v | string | Yes| Name of a process.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| number | Process UID.| + +**Example** + +``` +var pres = process.getUidForName("tool") +``` + + +## process.getThreadPriority8+ + +getThreadPriority(v:number): number Obtains the thread priority based on the specified TID. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

v

-

number

-

Yes

-

TID.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Priority of the thread.

-
- -- Example - - ``` - var tid = process.tid; - var pres = process.getThreadPriority(tid); - ``` - - -## process.getStartRealtime8+ - -getStartRealtime\(\) :number +**Parameters** -Obtains the duration, in milliseconds, from the time the system starts to the time the process starts. +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| v | number | Yes| TID.| -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

number

-

Time duration obtained.

-
+| Type| Description| +| -------- | -------- | +| number | Priority of the thread.| +**Example** -- Example +``` +var tid = process.getTid(); +var pres = process.getThreadPriority(tid); +``` - ``` - var realtime = process.getStartRealtime(); - ``` +## process.getStartRealtime8+ +getStartRealtime() :number + +Obtains the duration, in milliseconds, from the time the system starts to the time the process starts. -## process.getPastCputime8+ +**Return value** + +| Type| Description| +| -------- | -------- | +| number | Duration obtained.| + +**Example** + +``` +var realtime = process.getStartRealtime(); +``` -getPastCputime\(\) :number +## process.getPastCputime8+ -Obtains the CPU time \(in milliseconds\) from the time the process starts to the current time. +getPastCputime() :number -- Return values +Obtains the CPU time (in milliseconds) from the time the process starts to the current time. - - - - - - - - - -

Type

-

Description

-

number

-

CPU time obtained.

-
+**Return value** +| Type| Description| +| -------- | -------- | +| number | CPU time obtained.| -- Example +**Example** - ``` - var result = process.getPastCputime() ; - ``` +``` +var result = process.getPastCputime() ; +``` -## process.getSystemConfig8+ +## process.getSystemConfig8+ -getSystemConfig\(name:number\): number +getSystemConfig(name:number): number Obtains the system configuration. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

name

-

number

-

Yes

-

System configuration parameter name.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

System configuration obtained.

-
- -- Example - - ``` - var _SC_ARG_MAX = 0 - var pres = process.getSystemConfig(_SC_ARG_MAX) - ``` - - -## process.getEnvironmentVar8+ - -getEnvironmentVar\(name:string\): string +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | number | Yes| System configuration parameter name.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| number | System configuration obtained.| + +**Example** + +``` +var _SC_ARG_MAX = 0 +var pres = process.getSystemConfig(_SC_ARG_MAX) +``` + + +## process.getEnvironmentVar8+ + +getEnvironmentVar(name:string): string Obtains the value of an environment variable. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

name

-

string

-

Yes

-

Environment variable name.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Value of the environment variable.

-
- -- Example - - ``` - var pres = process.getEnvironmentVar("PATH") - ``` - - -## process.runCmd - -runCmd\(command: string, options?: \{ timeout : number, killSignal : number | string, maxBuffer : number \}\) : ChildProcess - -Forks a new process to run a shell command and returns the **ChildProcess** object. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

command

-

string

-

Yes

-

Shell command to run.

-

options

-

Object

-

No

-

Related parameters.

-
- - **Table 1** options - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

timeout

-

number

-

No

-

Maximum running time (in ms) of the child process. When the running time of the child process exceeds the value of this parameter, the parent process sends a killSignal to the child process to terminate it. The default value is 0.

-

killSignal

-

number | string

-

No

-

Signal sent to the child process when the running time of a child process exceeds the timeout period. The default value is SIGTERM.

-

maxBuffer

-

number

-

No

-

Maximum buffer size for the standard input and output of the child process. When the size is exceeded, the child process will be terminated. The default value is 1024 * 1024.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

ChildProcess

-

ChildProcess object.

-
- -- Example - - ``` - var child = process.runCmd('ls', { maxBuffer : 2 }); - var result = child.wait(); - child.getOutput.then(val=>{ - console.log("child.getOutput = " + val); - }) - ``` - - -## process.abort - -abort\(\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Environment variable name.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| string | Value of the environment variable.| + +**Example** + +``` +var pres = process.getEnvironmentVar("PATH") +``` + + +## process.runCmd + +runCmd(command: string, options?: { timeout : number, killSignal : number | string, maxBuffer : number }) : ChildProcess + +Forks a new process to run a shell command and returns the **ChildProcess** object. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| command | string | Yes| Shell command to run.| +| options | Object | No| Related parameters.| + +**Table 1** options + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| timeout | number | No| Maximum running time (in ms) of the child process. When the running time of the child process exceeds the value of this parameter, the parent process sends a **killSignal** to the child process to terminate it. The default value is **0**.| +| killSignal | number  \| string | No| Signal sent to the child process when the running time of a child process exceeds the timeout period. The default value is **SIGTERM**.| +| maxBuffer | number | No| Maximum buffer size for the standard input and output of the child process. When the size is exceeded, the child process will be terminated. The default value is **1024 \* 1024**.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| [ChildProcess](#childprocess) | **ChildProcess** object.| + +**Example** + +``` +var child = process.runCmd('ls', { maxBuffer : 2 }); +var result = child.wait(); +child.getOutput.then(val=>{ + console.log("child.getOutput = " + val); +}) +``` + + +## process.abort + +abort(): void Aborts a process and generates a core file. This method will cause a process to exit immediately. Exercise caution when using this method. -- Example +**Example** - ``` - process.abort(); - ``` +``` +process.abort(); +``` -## process.on +## process.on -on\(type: string, listener: EventListener\): void +on(type: string, listener: EventListener): void Stores the events triggered by the user. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Type of the events to store.

-

listener

-

EventListener

-

Yes

-

Callback invoked to return the event.

-
- - **Table 2** EventListener - - - - - - - - - - -

Name

-

Description

-

EventListener = (evt: Object) => void

-

Event to store.

-
- -- Example - - ``` - process.on("data", (e)=>{ - console.log("data callback"); - }) - ``` - - -## process.off - -off\(type: string\): boolean +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the events to store. | +| listener | EventListener | Yes| Callback invoked to return the event.| + +**Table 2** EventListener + +| Name| Description| +| -------- | -------- | +| EventListener = (evt: Object) => void | Event to store.| + +**Example** + +``` +process.on("data", (e)=>{ + console.log("data callback"); +}) +``` + + +## process.off + +off(type: string): boolean Deletes the event stored by the user. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Type of the event to delete.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the event is deleted; returns false otherwise.

-
- -- Example - - ``` - process.on("data", (e)=>{ - console.log("data callback"); - }) - var result = process.off("data"); - ``` - - -## process.exit - -exit\(code: number\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the event to delete.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the event is deleted; returns **false** otherwise.| + +**Example** + +``` +process.on("data", (e)=>{ + console.log("data callback"); +}) +var result = process.off("data"); +``` + + +## process.exit + +exit(code: number): void Terminates this process. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

code

-

number

-

Yes

-

Exit code of the process.

-
- -- Example - - ``` - process.exit(0); - ``` - - -## process.cwd - -cwd\(\): string +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| code | number | Yes| Exit code of the process.| + +**Example** + +``` +process.exit(0); +``` + + +## process.cwd + +cwd(): string Obtains the working directory of this process. -- Example +**Example** - ``` - var path = process.cwd(); - ``` +``` +var path = process.cwd(); +``` -## process.chdir +## process.chdir -chdir\(dir: string\): void +chdir(dir: string): void Changes the working directory of this process. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

dir

-

string

-

Yes

-

New working directory.

-
- -- Example - - ``` - process.chdir('/system'); - ``` - - -## process.uptime - -uptime\(\): number +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| dir | string | Yes| Path| + +**Example** + +``` +process.chdir('/system'); +``` + + +## process.uptime + +uptime(): number Obtains the running time of this process. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

number

-

Running time of the process, in seconds.

-
+| Type| Description| +| -------- | -------- | +| number | Running time of the process, in seconds.| -- Example +**Example** - ``` - var time = process.uptime(); - ``` +``` +var time = process.uptime(); +``` -## process.kill +## process.kill -kill\(pid: number, signal: number\): boolean +kill(pid: number, signal: number): boolean Sends a signal to the specified process to terminate it. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

pid

-

number

-

Yes

-

PID of the process, to which the signal will be sent.

-

signal

-

number

-

Yes

-

Signal to send.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the signal is sent successfully; returns false otherwise.

-
- -- Example - - ``` - var pres = process.pid - var result = that.kill(pres, 28) - ``` +**Parameters** +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| pid | number | Yes| PID of the process, to which the signal will be sent.| +| signal | number | Yes| Signal to send.| +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the signal is sent successfully; returns **false** otherwise.| + +**Example** +``` +var pres = process.pid +var result = that.kill(pres, 28) +``` diff --git a/en/application-dev/reference/apis/js-apis-uri.md b/en/application-dev/reference/apis/js-apis-uri.md index da74b02fb1d645b8eb9de101f421e2ee0ba3beba..a7af3cedf7584fd6c13dd29e199aff45968cf1cf 100644 --- a/en/application-dev/reference/apis/js-apis-uri.md +++ b/en/application-dev/reference/apis/js-apis-uri.md @@ -1,338 +1,141 @@ -# URI String Parsing +# URI String Parsing ->![](../../public_sys-resources/icon-note.gif) **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. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **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 + +## Modules to Import ``` import uri from '@ohos.uri' ``` -## Required Permissions - -None - -## URI - -### Attributes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

scheme

-

string

-

Yes

-

No

-

Protocol in the URI.

-

userInfo

-

string

-

Yes

-

No

-

User information in the URI.

-

host

-

string

-

Yes

-

No

-

Host name (without the port number) in the URI.

-

port

-

string

-

Yes

-

No

-

Port number in the URI.

-

path

-

string

-

Yes

-

No

-

Path in the URI.

-

query

-

string

-

Yes

-

No

-

Query part in the URI.

-

fragment

-

string

-

Yes

-

No

-

Fragment part in the URI.

-

authority

-

string

-

Yes

-

No

-

Authority part in the URI.

-

ssp

-

string

-

Yes

-

No

-

Scheme-specific part in the URI.

-
- -### constructor - -constructor\(uri: string\) +## System Capabilities + +SystemCapability.Utils.Lang + +## URI + + +### Attributes + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| scheme | string | Yes| No| Scheme in the URI.| +| userInfo | string | Yes| No| User information in the URI.| +| host | string | Yes| No| Host name (without the port number) in the URI.| +| port | string | Yes| No| Port number in the URI.| +| path | string | Yes| No| Path in the URI.| +| query | string | Yes| No| Query part in the URI.| +| fragment | string | Yes| No| Fragment part in the URI.| +| authority | string | Yes| No| Authority part in the URI.| +| ssp | string | Yes| No| Scheme-specific part in the URI.| + + +### constructor + +constructor(uri: string) A constructor used to create a URI instance. -- Parameters - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

url

-

string

-

Yes

-

Yes

-

Input parameter object.

-
- - -- Example - - ``` - var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; - new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; - ``` - - ``` - new uri.URI('http://username:password@host:8080'); // Output 'http://username:password@host:8080'; - ``` - - -### toString - -toString\(\): string +**Parameters** -Obtains the query string applicable to this URL. +| Name| Type.| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| url | string | Yes| Yes| Input object.| -- Return values +**Example** - - - - - - - - - -

Type

-

Description

-

string

-

Website address in a serialized string.

-
+``` +var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; +new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; +``` +``` +new uri.URI('http://username:password@host:8080'); // Output 'http://username:password@host:8080'; +``` + + +### toString +toString(): string -- Example +Obtains the query string applicable to this URL. + +**Return value** + +| Type.| Description| +| -------- | -------- | +| string | Website address in a serialized string.| - ``` - const url = new uri.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - url.toString() - ``` +**Example** +``` +const url = new uri.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); +url.toString() +``` -### equals -equals\(other: URI\): boolean +### equals + +equals(other: URI): boolean Checks whether this URI is the same as another URI object. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

other

-

URI

-

Yes

-

URI object to compare.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the two URIs are the same; returns false otherwise.

-
- - -- Example - - ``` - const uriInstance = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment'); - uriInstance.equals(uriInstance1); - ``` - - -### checkIsAbsolute - -checkIsAbsolute\(\): boolean - -Checks whether this URI is an absolute URI \(whether the scheme component is defined\). - -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the URI is an absolute URI; returns false otherwise.

-
- - -- Example - - ``` - const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080?query=pppppp'); - uriInstance.checkIsAbsolute(); - ``` - - -### normalize - -normalize\(\): URI +**Parameters** -Normalizes the path of this URI. +| Name| Type.| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| other | [URI](#uri) | Yes| URI object to compare.| + +**Return value** + +| Type.| Description| +| -------- | -------- | +| boolean | Returns **true** if the two URIs are the same; returns **false** otherwise.| + +**Example** + +``` +const uriInstance = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); +const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment'); +uriInstance.equals(uriInstance1); +``` + +### checkIsAbsolute + +checkIsAbsolute(): boolean -- Return values +Checks whether this URI is an absolute URI (whether the scheme component is defined). - - - - - - - - - -

Type

-

Description

-

URI

-

URI with the normalized path.

-
+**Return value** +| Type.| Description| +| -------- | -------- | +| boolean | Returns **true** if the URI is an absolute URI; returns **false** otherwise.| -- Example +**Example** - ``` - const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp'); - let uriInstance1 = uriInstance.normalize(); - uriInstance1.path; - ``` +``` +const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080?query=pppppp'); +uriInstance.checkIsAbsolute(); +``` + + +### normalize + +normalize(): URI +Normalizes the path of this URI. + +**Return value** + +| Type.| Description| +| -------- | -------- | +| URI | URI with the normalized path.| +**Example** +``` +const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp'); +let uriInstance1 = uriInstance.normalize(); +uriInstance1.path; +``` diff --git a/en/application-dev/reference/apis/js-apis-url.md b/en/application-dev/reference/apis/js-apis-url.md index bf7b0aca1a140b669759b1df81fff9b41cd26125..fcfc892f85f4220e3df4fa21e0a1337c7de9d2f8 100644 --- a/en/application-dev/reference/apis/js-apis-url.md +++ b/en/application-dev/reference/apis/js-apis-url.md @@ -1,6 +1,6 @@ # URL String Parsing -> ![](../../public_sys-resources/icon-note.gif) **Note:** +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -10,11 +10,9 @@ import Url from '@ohos.url' ``` +## System Capabilities -## Required Permissions - -None - +SystemCapability.Utils.Lang ## URLSearchParams @@ -25,19 +23,21 @@ constructor(init?: string[][] | Record<string, string> | string | URLSearc Creates a **URLSearchParams** instance. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | init | string[][] \| Record<string, string> \| string \| URLSearchParams | No| Input parameter objects, which include the following:
- **string[][]**: two-dimensional string array
- **Record<string, string>**: list of objects
- **string**: string
- **URLSearchParams**: object| +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| init | string[][] \| Record<string, string> \| string \| URLSearchParams | No| Input parameter objects, which include the following:
- **string[][]**: two-dimensional string array
- **Record<string, string>**: list of objects
- **string**: string
- **URLSearchParams**: object| + +**Example** -- Example - ``` - var objectParams = new URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); - var objectParams1 = new URLSearchParams({"fod" : 1 , "bard" : 2}); - var objectParams2 = new URLSearchParams('?fod=1&bard=2'); - var urlObject = new URL('https://developer.mozilla.org/?fod=1&bard=2'); - var params = new URLSearchParams(urlObject .search); - ``` +``` +var objectParams = new URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); +var objectParams1 = new URLSearchParams({"fod" : 1 , "bard" : 2}); +var objectParams2 = new URLSearchParams('?fod=1&bard=2'); +var urlObject = new URL('https://developer.mozilla.org/?fod=1&bard=2'); +var params = new URLSearchParams(urlObject .search); +``` ### append @@ -46,18 +46,20 @@ append(name: string, value: string): void Appends a key-value pair into the query string. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | name | string | Yes| Key of the key-value pair to append.| - | value | string | Yes| Value of the key-value pair to append.| +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Key of the key-value pair to append.| +| value | string | Yes| Value of the key-value pair to append.| + +**Example** -- Example - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.append('fod', 3); - ``` +``` +let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsObject = new URLSearchParams(urlObject.search.slice(1)); +paramsObject.append('fod', 3); +``` ### delete @@ -66,17 +68,19 @@ delete(name: string): void Deletes key-value pairs of the specified key. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | name | string | Yes| Key of the key-value pairs to delete.| +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Key of the key-value pairs to delete.| + +**Example** -- Example - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsobject = new URLSearchParams(urlObject.search.slice(1)); - paramsobject.delete('foo'); - ``` +``` +let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsobject = new URLSearchParams(urlObject.search.slice(1)); +paramsobject.delete('foo'); +``` ### getAll @@ -85,23 +89,26 @@ getAll(name: string): string[] Obtains all the key-value pairs based on the specified key. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | name | string | Yes| Key specified to obtain all key-value pairs.| +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Key specified to obtain all key-value pairs.| + +**Return value** -- Return values - | Type| Description| - | -------- | -------- | - | string[] | All key-value pairs matching the specified key.| +| Type| Description| +| -------- | -------- | +| string[] | All key-value pairs matching the specified key.| -- Example - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.append('fod', 3); // Add a second value for the foo parameter. - console.log(params.getAll('fod')) // Output ["1","3"]. - ``` +**Example** + +``` +let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsObject = new URLSearchParams(urlObject.search.slice(1)); +paramsObject.append('fod', 3); // Add a second value for the foo parameter. +console.log(params.getAll('fod')) // Output ["1","3"]. +``` ### entries @@ -110,18 +117,20 @@ entries(): IterableIterator<[string, string]> Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and the first and second fields of each array are the key and value respectively. -- Return values - | Type| Description| - | -------- | -------- | - | IterableIterator<[string, string]> | An ES6 iterator.| +**Return value** + +| Type| Description| +| -------- | -------- | +| IterableIterator<[string, string]> | An ES6 iterator.| -- Example - ``` - var searchParamsObject = new URLSearchParams("keyName1=valueName1&keyName2=valueName2"); - for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs - console.log(pair[0]+ ', '+ pair[1]); - } - ``` +**Example** + +``` +var searchParamsObject = new URLSearchParams("keyName1=valueName1&keyName2=valueName2"); +for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs + console.log(pair[0]+ ', '+ pair[1]); +} +``` ### forEach @@ -130,27 +139,29 @@ forEach(callbackfn: (value: string, key: string, searchParams: Object) => voi Traverses the key-value pairs in the **URLSearchParams** instance by using a callback. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callbackfn | function | Yes| Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance.| - | thisArg | Object | No| Value to use when the callback is invoked.| - - **Table 1** callbackfn parameter description - - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | value | string | Yes| Value that is currently traversed.| - | key | string | Yes| Key that is currently traversed.| - | searchParams | Object | Yes| Instance that invokes the **forEach** method.| - -- Example - ``` - const myURLObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - myURLObject.searchParams.forEach((value, name, searchParams) => { - console.log(name, value, myURLObject.searchParams === searchParams); - }); - ``` +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callbackfn | function | Yes| Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance.| +| thisArg | Object | No| Value to use when the callback is invoked.| + +**Table 1** callbackfn parameter description + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| value | string | Yes| Value that is currently traversed.| +| key | string | Yes| Key that is currently traversed.| +| searchParams | Object | Yes| Instance that invokes the **forEach** method.| + +**Example** + +``` +const myURLObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); +myURLObject.searchParams.forEach((value, name, searchParams) => { + console.log(name, value, myURLObject.searchParams === searchParams); +}); +``` ### get @@ -159,24 +170,27 @@ get(name: string): string | null Obtains the value of the first key-value pair based on the specified key. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | name | string | Yes| Key specified to obtain the value.| +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Key specified to obtain the value.| + +**Return value** -- Return values - | Type| Description| - | -------- | -------- | - | string | Returns the value of the first key-value pair if obtained.| - | null | Returns null if no value is obtained.| +| Type| Description| +| -------- | -------- | +| string | Returns the value of the first key-value pair if obtained.| +| null | Returns null if no value is obtained.| -- Example - ``` - var paramsOject = new URLSearchParams(document.location.search.substring(1)); - var name = paramsOject.get("name"); // is the string "Jonathan" - var age = parseInt(paramsOject.get("age"), 10); // is the number 18 - var address = paramsOject.get("address"); // null - ``` +**Example** + +``` +var paramsOject = new URLSearchParams(document.location.search.substring(1)); +var name = paramsOject.get("name"); // is the string "Jonathan" +var age = parseInt(paramsOject.get("age"), 10); // is the number 18 +var address = paramsOject.get("address"); // null +``` ### has @@ -184,22 +198,26 @@ Obtains the value of the first key-value pair based on the specified key. has(name: string): boolean Checks whether a key has a value. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | name | string | Yes| Key specified to search for its value.| -- Return values - | Type| Description| - | -------- | -------- | - | boolean | Returns **true** if the value exists; returns **false** otherwise.| +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Key specified to search for its value.| -- Example - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.has('bard') === true; - ``` +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the value exists; returns **false** otherwise.| + +**Example** + +``` +let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsObject = new URLSearchParams(urlObject.search.slice(1)); +paramsObject.has('bard') === true; +``` ### set @@ -208,18 +226,20 @@ set(name: string, value: string): void Sets the value for a key. If key-value pairs matching the specified key exist, the value of the first key-value pair will be set to the specified value and other key-value pairs will be deleted. Otherwise, the key-value pair will be appended to the query string. -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | name | string | Yes| Key of the value to set.| - | value | string | Yes| Value to set.| +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Key of the value to set.| +| value | string | Yes| Value to set.| -- Example - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.set('baz', 3); // Add a third parameter. - ``` +**Example** + +``` +let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsObject = new URLSearchParams(urlObject.search.slice(1)); +paramsObject.set('baz', 3); // Add a third parameter. +``` ### sort @@ -229,13 +249,13 @@ sort(): void Sorts all key-value pairs contained in this object based on the Unicode code points of the keys and returns undefined. This method uses a stable sorting algorithm, that is, the relative order between key-value pairs with equal keys is retained. +**Example** -- Example - ``` - var searchParamsObject = new URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object - searchParamsObject.sort(); // Sort the key/value pairs - console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 - ``` +``` +var searchParamsObject = new URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object +searchParamsObject.sort(); // Sort the key/value pairs +console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 +``` ### keys @@ -245,20 +265,20 @@ keys(): IterableIterator<string> Obtains an ES6 iterator that contains the keys of all the key-value pairs. +**Return value** -- Return values - | Type| Description| - | -------- | -------- | - | IterableIterator<string> | ES6 iterator that contains the keys of all the key-value pairs.| +| Type| Description| +| -------- | -------- | +| IterableIterator<string> | ES6 iterator that contains the keys of all the key-value pairs.| +**Example** -- Example - ``` - var searchParamsObject = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing - for (var key of searchParamsObject .keys()) { // Output key-value pairs - console.log(key); - } - ``` +``` +var searchParamsObject = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +for (var key of searchParamsObject .keys()) { // Output key-value pairs + console.log(key); +} +``` ### values @@ -267,41 +287,43 @@ values(): IterableIterator<string> Obtains an ES6 iterator that contains the values of all the key-value pairs. -- Return values - | Type| Description| - | -------- | -------- | - | IterableIterator<string> | ES6 iterator that contains the values of all the key-value pairs.| +**Return value** + +| Type| Description| +| -------- | -------- | +| IterableIterator<string> | ES6 iterator that contains the values of all the key-value pairs.| -- Example - ``` - var searchParams = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing - for (var value of searchParams.values()) { - console.log(value); - } - ``` +**Example** + +``` +var searchParams = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +for (var value of searchParams.values()) { + console.log(value); +} +``` ### [Symbol.iterator] -[Symbol.iterator](): IterableIterator<[string, string]> +[Symbol.iterator]\(): IterableIterator<[string, string]> Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and the first and second fields of each array are the key and value respectively. +**Return value** -- Return values - | Type| Description| - | -------- | -------- | - | IterableIterator<[string, string]> | An ES6 iterator.| +| Type| Description| +| -------- | -------- | +| IterableIterator<[string, string]> | ES6 iterator.| +**Example** -- Example - ``` - const paramsObject = new URLSearchParams('fod=bay&edg=bap'); - for (const [name, value] of paramsObject) { - console.log(name, value); - } - ``` +``` +const paramsObject = new URLSearchParams('fod=bay&edg=bap'); +for (const [name, value] of paramsObject) { + console.log(name, value); +} +``` ### tostring @@ -311,20 +333,20 @@ toString(): string Obtains search parameters that are serialized as a string and, if necessary, percent-encodes the characters in the string. +**Return value** -- Return values - | Type| Description| - | -------- | -------- | - | string | String of serialized search parameters, which is percent-encoded if necessary.| +| Type| Description| +| -------- | -------- | +| string | String of serialized search parameters, which is percent-encoded if necessary.| +**Example** -- Example - ``` - let url = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let params = new URLSearchParams(url.search.slice(1)); - params.append('fod', 3); - console.log(params.toString()); - ``` +``` +let url = new URL('https://developer.exampleUrl/?fod=1&bard=2'); +let params = new URLSearchParams(url.search.slice(1)); +params.append('fod', 3); +console.log(params.toString()); +``` ## URL @@ -355,29 +377,29 @@ constructor(url: string, base?: string | URL) Creates a URL. +**Parameters** -- Parameters - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | url | string | Yes| Input object.| - | base | string \| URL | No| Input parameter, which can be any of the following:
- **string**: string
- **URL**: string or object| +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| url | string | Yes| Input object.| +| base | string \| URL | No| Input parameter, which can be any of the following:
- **string**: string
- **URL**: string or object| +**Example** -- Example - ``` - var mm = 'http://username:password@host:8080'; - var a = new URL("/", mm); // Output 'http://username:password@host:8080/'; - var b = new URL(mm); // Output 'http://username:password@host:8080/'; - new URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; - var c = new URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; - new URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; - new URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; - new URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 - new URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL - new URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL - new URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/ - new URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/ - ``` +``` +var mm = 'http://username:password@host:8080'; +var a = new URL("/", mm); // Output 'http://username:password@host:8080/'; +var b = new URL(mm); // Output 'http://username:password@host:8080/'; +new URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; +var c = new URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; +new URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; +new URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; +new URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 +new URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL +new URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL +new URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/ +new URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/ +``` ### tostring @@ -386,18 +408,18 @@ toString(): string Converts the parsed URL into a string. +**Return value** -- Return values - | Type| Description| - | -------- | -------- | - | string | Website address in a serialized string.| +| Type| Description| +| -------- | -------- | +| string | Website address in a serialized string.| +**Example** -- Example - ``` - const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - url.toString() - ``` +``` +const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); +url.toString() +``` ### toJSON @@ -407,15 +429,14 @@ toJSON(): string Converts the parsed URL into a JSON string. +**Return value** -- Return values - | Type| Description| - | -------- | -------- | - | string | Website address in a serialized string.| - +| Type| Description| +| -------- | -------- | +| string | Website address in a serialized string.| -- Example - ``` - const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - url.toJSON() - ``` +**Example** +``` +const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); +url.toJSON() +``` diff --git a/en/application-dev/reference/apis/js-apis-util.md b/en/application-dev/reference/apis/js-apis-util.md index 420cddd41bad06fb5c125246c856af52a4eaacc3..902e9adeedc9de943a117461ccfcae4e6bfa1acb 100644 --- a/en/application-dev/reference/apis/js-apis-util.md +++ b/en/application-dev/reference/apis/js-apis-util.md @@ -1,2124 +1,996 @@ -# util +# util ->**NOTE:** ->The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -This 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. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Modules to Import + +This 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. + + +## Modules to Import ``` import util from '@ohos.util'; ``` -## Required Permissions +## System Capabilities -None. +SystemCapability.Utils.Lang -## util.printf +## util.printf -printf\(format: string, ...args: Object\[\]\): string +printf(format: string, ...args: Object[]): string Prints the input content in a formatted string. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

format

-

string

-

Yes

-

Format of the string to print.

-

...args

-

Object[]

-

No

-

Data to format.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

String in the specified format.

-
- -- Example - - ``` - var res = util.printf("%s", "hello world!"); - console.log(res); - ``` - - -## util.getErrorString - -getErrorString\(errno: number\): string +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | format | string | Yes| Format of the string to print.| + | ...args | Object[] | No| Data to format.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | String in the specified format.| + +- Example + ``` + var res = util.printf("%s", "hello world!"); + console.log(res); + ``` + + +## util.getErrorString + +getErrorString(errno: number): string Obtains detailed information about a system error code. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

errno

-

number

-

Yes

-

Error code generated.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Detailed information about the error code.

-
- -- Example - - ``` - var errnum = 10; // 10 is the system error code. - var result = util.getErrorString(errnum); - console.log("result = " + result); - ``` - - -## util.callbackWrapper - -callbackWrapper\(original: Function\): \(err: Object, value: Object \)=\>void - -Calls back an asynchronous function. In the callback, the first parameter indicates the cause of the rejection \(the value is **null** if the promise has been resolved\), and the second parameter indicates the resolved value. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

original

-

Function

-

Yes

-

Asynchronous function to process.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Function

-

Callback, in which the first parameter indicates the cause of the rejection (the value is null if the promise has been resolved) and the second parameter indicates the resolved value.

-
- -- Example - - ``` - async function promiseFn() { - return Promise.reject('value'); - } - var cb = util.callbackWrapper(promiseFn); - cb((err, ret) => { - console.log(err); - console.log(ret); - }) - ``` +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | errno | number | Yes| Error code generated.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Detailed information about the error code.| + +- Example + ``` + var errnum = 10; // 10 is the system error code. + var result = util.getErrorString(errnum); + console.log("result = " + result); + ``` + + +## util.callbackWrapper + +callbackWrapper(original: Function): (err: Object, value: Object )=>void + +Calls back an asynchronous function. In the callback, the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved), and the second parameter indicates the resolved value. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | original | Function | Yes| Asynchronous function.| -## util.promiseWrapper +- Return value + | Type| Description| + | -------- | -------- | + | Function | Callback, in which the first parameter indicates the cause of the rejection (the value is **null** if the promise has been resolved) and the second parameter indicates the resolved value.| -promiseWrapper\(original: \(err: Object, value: Object\) =\> void\): Object +- Example + ``` + async function promiseFn() { + return Promise.reject('value'); + } + var cb = util.callbackWrapper(promiseFn); + cb((err, ret) => { + console.log(err); + console.log(ret); + }) + ``` + + +## util.promiseWrapper + +promiseWrapper(original: (err: Object, value: Object) => void): Object Processes an asynchronous function and returns a promise version. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

original

-

Function

-

Yes

-

Asynchronous function to process.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Function

-

Function in the error-first style (that is, (err, value) =>... is called as the last parameter) and the promise version.

-
- -- Example - - ``` - function aysnFun(str1, str2, callback) { - if (typeof str1 === 'string' && typeof str1 === 'string') { - callback(null, str1 + str2); - } else { - callback('type err'); - } - } - let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); - newPromiseObj.then(res => { - console.log(res); - }) - ``` - - -## TextDecoder - -### Attributes - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

encoding

-

string

-

Yes

-

No

-

Encoding format.

-
  • Supported formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-8-i, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, koi8-r, koi8-u, macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, x-mac-cyrilli, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis, euc-kr, utf-16be, utf-16le
-

fatal

-

boolean

-

Yes

-

No

-

Whether to display fatal errors.

-

ignoreBOM

-

boolean

-

Yes

-

No

-

Whether to ignore the byte order marker (BOM). The default value is false, which indicates that the result contains the BOM.

-
- -### constructor - -constructor\(encoding?:string, options?:\{ fatal?:boolean;ignoreBOM?:boolean \}\) - -A constructor used to create a **TextDecoder** object. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

encoding

-

string

-

No

-

Encoding format.

-

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.

-
- -- Example - - ``` - var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM:true}); - ``` - - -### decode - -decode\(input: Unit8Array, options?:\{stream?:false\}\):string +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | original | Function | Yes| Asynchronous function to process.| + +- Return value + | Type| Description| + | -------- | -------- | + | Function | Function in the error-first style (that is, **(err, value) =>...** is called as the last parameter) and the promise version.| + +- Example + ``` + function aysnFun(str1, str2, callback) { + if (typeof str1 === 'string' && typeof str2 === 'string') { + callback(null, str1 + str2); + } else { + callback('type err'); + } + } + let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); + newPromiseObj.then(res => { + console.log(res); + }) + ``` + + +## TextDecoder + + +### Attributes + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| encoding | string | Yes| No| Encoding format.
- Supported formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-8-i, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, koi8-r, koi8-u, macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, x-mac-cyrilli, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis, euc-kr, utf-16be, utf-16le| +| fatal | boolean | Yes| No| Whether to display fatal errors.| +| ignoreBOM | boolean | Yes| No| Whether to ignore the byte order marker (BOM). The default value is **false**, which indicates that the result contains the BOM.| + + +### constructor + +constructor(encoding?:string, options?:{ fatal?:boolean;ignoreBOM?:boolean }) + +A constructor used to create a **TextDecoder** object. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | encoding | string | No| Encoding format.| + | 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.| + +- Example + ``` + var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM:true}); + ``` + + +### decode + +decode(input: Unit8Array, options?:{stream?:false}):string Decodes the input content. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

input

-

Unit8Array

-

Yes

-

Uint8Array to decode.

-

options

-

Object

-

No

-

Options related to decoding.

-
- - **Table 2** options - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

stream

-

boolean

-

No

-

Whether to allow data blocks in subsequent decode(). If data is processed in blocks, set this parameter to true. If this is the last data block to process or data is not divided into blocks, set this parameter to false. The default value is false.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Data decoded.

-
- -- Example - - ``` - var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM:true}); - var result = new Uint8Array(6); - result[0] = 0xEF; - result[1] = 0xBB; - result[2] = 0xBF; - result[3] = 0x61; - result[4] = 0x62; - result[5] = 0x63; - console.log("input num:"); - for(var j= 0; j < 6; j++) { - console.log(result[j]); - } - var retStr = textDecoder.decode( result , {stream:false}); - console.log("retStr = " + retStr); - ``` +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | input | Unit8Array | Yes| Uint8Array to decode.| + | options | Object | No| Options related to decoding.| + + **Table 2** options + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | stream | boolean | No| Whether to allow data blocks in subsequent **decode()**. If data is processed in blocks, set this parameter to **true**. If this is the last data block to process or data is not divided into blocks, set this parameter to **false**. The default value is **false**.| +- Return value + | Type| Description| + | -------- | -------- | + | string | Data decoded.| -## TextEncoder +- Example + ``` + var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM:true}); + var result = new Uint8Array(6); + result[0] = 0xEF; + result[1] = 0xBB; + result[2] = 0xBF; + result[3] = 0x61; + result[4] = 0x62; + result[5] = 0x63; + console.log("input num:"); + for(var j= 0; j < 6; j++) { + console.log(result[j]); + } + var retStr = textDecoder.decode( result , {stream:false}); + console.log("retStr = " + retStr); + ``` -### Attributes - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

encoding

-

string

-

Yes

-

No

-

Encoding format. The default format is utf-8.

-
+## TextEncoder -### constructor -constructor\(\) +### Attributes -A constructor used to create a **TextEncoder** object. +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.| -- Example - ``` - var textEncoder = new util.TextEncoder(); - ``` +### constructor +constructor() -### encode +A constructor used to create a **TextEncoder** object. -encode\(input?:string\):Uint8Array +- Example + ``` + var textEncoder = new util.TextEncoder(); + ``` + + +### encode + +encode(input?:string):Uint8Array Encodes the input content. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

input

-

string

-

Yes

-

String to encode.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Uint8Array

-

Encoded text.

-
- -- Example - - ``` - var textEncoder = new util.TextEncoder(); - var result = new Uint8Array(buffer); - result = textEncoder.encode("\uD800¥¥"); - ``` - - -### encodeInto - -encodeInto\(input:string, dest:Uint8Array, \):\{ read:number; written:number \} +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | input | string | Yes| String to encode.| + +- Return value + | Type| Description| + | -------- | -------- | + | Uint8Array | Encoded text.| + +- Example + ``` + var textEncoder = new util.TextEncoder(); + var result = new Uint8Array(buffer); + result = textEncoder.encode("\uD800¥¥"); + ``` + + +### encodeInto + +encodeInto(input:string, dest:Uint8Array, ):{ read:number; written:number } Stores the UTF-8 encoded text. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

input

-

string

-

Yes

-

String to encode.

-

dest

-

Uint8Array

-

Yes

-

Uint8Array object used to hold the UTF-8 encoded text.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Uint8Array

-

Encoded text.

-
- -- Example - - ``` - var that = new util.TextEncoder(); - var buffer = new ArrayBuffer(4); - this.dest = new Uint8Array(buffer); - var result = that.encodeInto("abcd", this.dest); - ``` - - -## RationalNumber8+ - -### constructor8+ - -constructor\(numerator:number,denominator:number\) - -A constructor used to create a **RationalNumber** object. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

numerator

-

number

-

Yes

-

Numerator, which is an integer.

-

denominator

-

number

-

Yes

-

Denominator, which is an integer.

-
- - -- Example - - ``` - var rationalNumber = new util.RationalNumber(1,2); - ``` - - -### createRationalFromString8+ - -static createRationalFromString​\(rationalString:string\):RationalNumber​ - -Creates a **RationalNumber** object using the given string. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

rationalString

-

string

-

Yes

-

String used to create the RationalNumber object.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

object

-

RationalNumber object created.

-
- - -- Example - - ``` - var rationalNumber = new util.RationalNumber(1,2); - var rational = rationalNumer.creatRationalFromString("3/4"); - ``` - - -### compareTo8+ - -compareTo​\(another:RationalNumber\):number​ - -Compares this **RationalNumber** object with a given object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

another

-

RationalNumber

-

Yes

-

Object used to compare with this RationalNumber object.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Returns 0 if the two objects are equal; returns 1 if the given object is less than this object; return -1 if the given object is greater than this object.

-
- - -- Example - - ``` - var rationalNumber = new util.RationalNumber(1,2); - var rational = rationalNumer.creatRationalFromString("3/4"); - var result = rationalNumber.compareTo(rational); - ``` - - -### valueOf8+ - -valueOf\(\):number - -Obtains the value of this **RationalNumber** object as an integer or a floating-point number. - -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

An integer or a floating-point number.

-
- - -- Example - - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.valueOf(); - ``` - - -### equals8+ - -equals​\(obj:Object\):boolean - -Checks whether this **RationalNumber** object equals the given object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

object

-

Object

-

Yes

-

Object used to compare with this RationalNumber object.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the two objects are equal; returns false otherwise.

-
- - -- Example - - ``` - var rationalNumber = new util.RationalNumber(1,2); - var rational = rationalNumer.creatRationalFromString("3/4"); - var result = rationalNumber.equals(rational); - ``` - - -### getCommonDivisor8+ - -static getCommonDivisor​\(number1:number,number2:number\):number - -Obtains the greatest common divisor of the two specified integers. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

number1

-

number

-

Yes

-

The first integer used to get the greatest common divisor.

-

number2

-

number

-

Yes

-

The second integer used to get the greatest common divisor.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Greatest common divisor obtained.

-
- - -- Example - - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.getCommonDivisor(4,6); - ``` - - -### getNumerator8+ - -getNumerator​\(\):number - -Obtains the numerator of this **RationalNumber** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Numerator of this RationalNumber object.

-
+- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | input | string | Yes| String to encode.| + | dest | Uint8Array | Yes| **Uint8Array** instance used to store the UTF-8 encoded text.| +- Return value + | Type| Description| + | -------- | -------- | + | Uint8Array | Encoded text.| -- Example - - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.getNumerator(); - ``` +- Example + ``` + var that = new util.TextEncoder(); + var buffer = new ArrayBuffer(4); + this.dest = new Uint8Array(buffer); + var result = that.encodeInto("abcd", this.dest); + ``` +## RationalNumber8+ -### getDenominator8+ -getDenominator​\(\):number +### constructor8+ -Obtains the denominator of this **RationalNumber** object. +constructor(numerator:number,denominator:number) -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Denominator of this RationalNumber object.

-
+A constructor used to create a **RationalNumber** object. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | numerator | number | Yes| Numerator, which is an integer.| + | denominator | number | Yes| Denominator, which is an integer.| -- Example +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + ``` - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.getDenominator(); - ``` +### createRationalFromString8+ -### isZero8+ +static createRationalFromString​(rationalString:string):RationalNumber​ -isZero​\(\):boolean +Creates a **RationalNumber** object based on the given string. -Checks whether this **RationalNumber** object is **0**. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | rationalString | string | Yes| String used to create the **RationalNumber** object.| -- Return values +- Return value + | Type| Description| + | -------- | -------- | + | object | **RationalNumber** object created.| - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the value of this RationalNumber object is 0; returns false otherwise.

-
+- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var rational = rationalNumer.creatRationalFromString("3/4"); + ``` -- Example +### compareTo8+ - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isZero(); - ``` +compareTo​(another:RationalNumber):number​ +Compares this **RationalNumber** object with a given object. -### isNaN8+ +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | another | RationalNumber | Yes| Object used to compare with this **RationalNumber** object.| -isNaN​\(\):boolean +- Return value + | Type| Description| + | -------- | -------- | + | number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.| -Checks whether this **RationalNumber** object is a Not a Number \(NaN\). +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var rational = rationalNumer.creatRationalFromString("3/4"); + var result = rationalNumber.compareTo(rational); + ``` -- Return values - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if this RationalNumber object is a NaN (the denominator and numerator are both 0); returns false otherwise.

-
+### valueOf8+ +valueOf():number -- Example +Obtains the value of this **RationalNumber** object as an integer or a floating-point number. - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isNaN(); - ``` +- Return value + | Type| Description| + | -------- | -------- | + | number | An integer or a floating-point number.| +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var result = rationalNumber.valueOf(); + ``` -### isFinite8+ -isFinite​\(\):boolean +### equals8+ -Checks whether this **RationalNumber** object represents a finite value. +equals​(obj:Object):boolean -- Return values +Checks whether this **RationalNumber** object equals the given object. - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if this RationalNumber object represents a finite value (the denominator is not 0); returns false otherwise.

-
+- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | object | Object | Yes| Object used to compare with this **RationalNumber** object.| +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the two objects are equal; returns **false** otherwise.| -- Example +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var rational = rationalNumer.creatRationalFromString("3/4"); + var result = rationalNumber.equals(rational); + ``` - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.isFinite(); - ``` - - -### toString8+ - -toString​\(\):string - -Obtains the string representation of this **RationalNumber** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Returns NaN if the numerator and denominator of this object are both 0; returns a string in Numerator/Denominator format otherwise, for example, 3/5.

-
+### getCommonDivisor8+ -- Example +static getCommonDivisor​(number1:number,number2:number):number - ``` - var rationalNumber = new util.RationalNumber(1,2); - var result = rationalNumber.toString(); - ``` - - -## LruBuffer8+ - -### Attributes - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

length

-

number

-

Yes

-

No

-

Total number of values in this buffer.

-
- -- Example - - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.put(1,8); - var result = pro.length; - ``` - - -### constructor8+ - -constructor\(capacity?:number\) - -A constructor used to create an **LruBuffer** instance. The default capacity of the buffer is 64. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

capacity

-

number

-

No

-

Capacity of the LruBuffer to create.

-
- - -- Example - - ``` - var lrubuffer= new util.LruBuffer(); - ``` - - -### updateCapacity8+ - -updateCapacity\(newCapacity:number\):void - -Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

newCapacity

-

number

-

Yes

-

New capacity of the buffer.

-
- -- Example - - ``` - var pro = new util.LruBuffer(); - var result = pro.updateCapacity(100); - ``` - - -### toString8+ - -toString\(\):string - -Obtains the string representation of this **LruBuffer** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

String representation of this object.

-
- - -- Example - - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.get(2); - pro.remove(20); - var result = pro.toString(); - ``` - - -### getCapacity8+ - -getCapacity\(\):number +Obtains the greatest common divisor of two specified integers. -Obtains the capacity of this buffer. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | number1 | number | Yes| The first integer used to get the greatest common divisor.| + | number2 | number | Yes| The second integer used to get the greatest common divisor.| -- Return values +- Return value + | Type| Description| + | -------- | -------- | + | number | Greatest common divisor obtained.| - - - - - - - - - -

Type

-

Description

-

number

-

Capacity of this buffer.

-
+- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var result = rationalNumber.getCommonDivisor(4,6); + ``` -- Example +### getNumerator8+ - ``` - var pro = new util.LruBuffer(); - var result = pro.getCapacity(); - ``` +getNumerator​():number +Obtains the numerator of this **RationalNumber** object. -### clear8+ +- Return value + | Type| Description| + | -------- | -------- | + | number | Numerator of this **RationalNumber** object.| -clear\(\):void +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var result = rationalNumber.getNumerator(); + ``` -Clears key-value pairs from this buffer. The **afterRemoval\(\)** method will be called to perform subsequent operations. -- Example +### getDenominator8+ - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.size(); - pro.clear(); - ``` +getDenominator​():number +Obtains the denominator of this **RationalNumber** object. -### getCreateCount8+ +- Return value + | Type| Description| + | -------- | -------- | + | number | Denominator of this **RationalNumber** object.| -getCreateCount\(\):number +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var result = rationalNumber.getDenominator(); + ``` -Obtains the number of return values for **createDefault\(\)**. -- Return values +### isZero8+ - - - - - - - - - -

Type

-

Description

-

number

-

Number of return values for createDefault().

-
+isZero​():boolean +Checks whether this **RationalNumber** object is **0**. -- Example +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the value of this **RationalNumber** object is **0**; returns **false** otherwise.| - ``` - var pro = new util.LruBuffer(); - pro.put(1,8); - var result = pro.getCreateCount(); - ``` +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var result = rationalNumber.isZero(); + ``` -### getMissCount8+ +### isNaN8+ -getMissCount\(\):number +isNaN​():boolean -Obtains the number of times that the queried values are mismatched. +Checks whether this **RationalNumber** object is a Not a Number (NaN). -- Return values +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if this **RationalNumber** object is a NaN (the denominator and numerator are both **0**); returns **false** otherwise.| - - - - - - - - - -

Type

-

Description

-

number

-

Number of times that the queried values are mismatched.

-
+- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var result = rationalNumber.isNaN(); + ``` -- Example +### isFinite8+ - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.get(2) - var result = pro.getMissCount(); - ``` +isFinite​():boolean +Checks whether this **RationalNumber** object represents a finite value. -### getRemovalCount8+ +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if this **RationalNumber** object represents a finite value (the denominator is not **0**); returns **false** otherwise.| -getRemovalCount\(\):number +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var result = rationalNumber.isFinite(); + ``` -Obtains the number of removals from this buffer. -- Return values +### toString8+ - - - - - - - - - -

Type

-

Description

-

number

-

Number of removals from the buffer.

-
+toString​():string +Obtains the string representation of this **RationalNumber** object. -- Example +- Return value + | Type| Description| + | -------- | -------- | + | string | Returns **NaN** if the numerator and denominator of this object are both **0**; returns a string in Numerator/Denominator format otherwise, for example, **3/5**.| - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.updateCapacity(2); - pro.put(50,22); - var result = pro.getRemovalCount(); - ``` +- Example + ``` + var rationalNumber = new util.RationalNumber(1,2); + var result = rationalNumber.toString(); + ``` +## LruBuffer8+ -### getMatchCount8+ -getMatchCount\(\):number +### Attributes -Obtains the number of times that the queried values are matched. +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| length | number | Yes| No| Total number of values in this buffer.| -- Return values +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + pro.put(1,8); + var result = pro.length; + ``` - - - - - - - - - -

Type

-

Description

-

number

-

Number of times that the queried values are matched.

-
+### constructor8+ -- Example +constructor(capacity?:number) - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.get(2); - var result = pro.getMatchCount(); - ``` +A constructor used to create an **LruBuffer** instance. The default capacity of the buffer is 64. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | capacity | number | No| Capacity of the **LruBuffer** to create.| -### getPutCount8+ +- Example + ``` + var lrubuffer= new util.LruBuffer(); + ``` -getPutCount\(\):number -Obtains the number of additions to this buffer. +### updateCapacity8+ -- Return values +updateCapacity(newCapacity:number):void - - - - - - - - - -

Type

-

Description

-

number

-

Number of additions to the buffer.

-
+Changes the **LruBuffer** capacity. If the new capacity is less than or equal to **0**, an exception will be thrown. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | newCapacity | number | Yes| New capacity of the **LruBuffer**.| -- Example +- Example + ``` + var pro = new util.LruBuffer(); + var result = pro.updateCapacity(100); + ``` - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.getPutCount(); - ``` +### toString8+ -### isEmpty8+ +toString():string -isEmpty\(\):boolean +Obtains the string representation of this **LruBuffer** object. -Checks whether this buffer is empty. +- Return value + | Type| Description| + | -------- | -------- | + | string | String representation of this **LruBuffer** object.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + pro.get(2); + pro.remove(20); + var result = pro.toString(); + ``` + + +### getCapacity8+ + +getCapacity():number + +Obtains the capacity of this buffer. + +- Return value + | Type| Description| + | -------- | -------- | + | number | Capacity of this buffer.| + +- Example + ``` + var pro = new util.LruBuffer(); + var result = pro.getCapacity(); + ``` -- Return values - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the buffer does not contain any value.

-
+### clear8+ +clear():void -- Example +Clears key-value pairs from this buffer. The **afterRemoval()** method will be called to perform subsequent operations. - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.isEmpty(); - ``` +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro.size(); + pro.clear(); + ``` -### get8+ +### getCreateCount8+ -get\(key:K\):V | undefined +getCreateCount():number + +Obtains the number of return values for **createDefault()**. + +- Return value + | Type| Description| + | -------- | -------- | + | number | Number of return values for **createDefault()**.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(1,8); + var result = pro.getCreateCount(); + ``` + + +### getMissCount8+ + +getMissCount():number + +Obtains the number of times that the queried values are mismatched. + +- Return value + | Type| Description| + | -------- | -------- | + | number | Number of times that the queried values are mismatched.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + pro.get(2); + var result = pro.getMissCount(); + ``` + + +### getRemovalCount8+ + +getRemovalCount():number + +Obtains the number of removals from this buffer. + +- Return value + | Type| Description| + | -------- | -------- | + | number | Number of removals from the buffer.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + pro.updateCapacity(2); + pro.put(50,22); + var result = pro.getRemovalCount(); + ``` + + +### getMatchCount8+ + +getMatchCount():number + +Obtains the number of times that the queried values are matched. + +- Return value + | Type| Description| + | -------- | -------- | + | number | Number of times that the queried values are matched.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + pro.get(2); + var result = pro.getMatchCount(); + ``` + + +### getPutCount8+ + +getPutCount():number + +Obtains the number of additions to this buffer. + +- Return value + | Type| Description| + | -------- | -------- | + | number | Number of additions to the buffer.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro.getPutCount(); + ``` + + +### isEmpty8+ + +isEmpty():boolean + +Checks whether this buffer is empty. + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the buffer does not contain any value.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro.isEmpty(); + ``` + + +### get8+ + +get(key:K):V | undefined Obtains the value of the specified key. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

K

-

Yes

-

Key based on which the value is queried.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

V | undefind

-

Returns the value of the key if a match is found in the buffer; returns undefined otherwise.

-
- - -- Example - - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.get(2); - ``` - - -### put8+ - -put\(key:K,value:V\):V +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | key | K | Yes| Key based on which the value is queried.| + +- Return value + | Type| Description| + | -------- | -------- | + | V \| undefind | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro.get(2); + ``` + + +### put8+ + +put(key:K,value:V):V Adds a key-value pair to this buffer. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

K

-

Yes

-

Key of the key-value pair to add.

-

value

-

V

-

Yes

-

Value of the key-value pair to add.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

V

-

Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown.

-
- - -- Example - - ``` - var pro = new util.LruBuffer(); - var result = pro.put(2,10); - ``` - - -### values8+ - -values\(\):V\[\] +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | key | K | Yes| Key of the key-value pair to add.| + | value | V | Yes| Value of the key-value pair to add.| -Obtains all values in this buffer, listed from the most to the least recently accessed. +- Return value + | Type| Description| + | -------- | -------- | + | V | Returns the existing value if the key already exists; returns the value added otherwise. If the key or value is null, an exception will be thrown. | -- Return values +- Example + ``` + var pro = new util.LruBuffer(); + var result = pro.put(2,10); + ``` - - - - - - - - - -

Type

-

Description

-

V []

-

All values in the buffer, listed from the most to the least recently accessed.

-
+### values8+ -- Example +values():V[] + +Obtains all values in this buffer, listed from the most to the least recently accessed. - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - pro.put(2,"anhu"); - pro.put("afaf","grfb"); - var result = pro.values(); - ``` +- Return value + | Type| Description| + | -------- | -------- | + | V [] | All values in the buffer, listed from the most to the least recently accessed.| +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + pro.put(2,"anhu"); + pro.put("afaf","grfb"); + var result = pro.values(); + ``` -### keys8+ -keys\(\):K\[\] +### keys8+ + +keys():K[] Obtains all keys in this buffer, listed from the most to the least recently accessed. -- Return values - - - - - - - - - - -

Type

-

Description

-

K []

-

All keys in the buffer, listed from the most to the least recently accessed.

-
- - -- Example - - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.keys(); - ``` - - -### remove8+ - -remove\(key:K\):V | undefined - -Deletes the specified key and its value from this buffer. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

K

-

Yes

-

Key to delete.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

V | undefind

-

Returns an Optional object containing the deleted key-value pair if the key exists in the buffer; returns an empty Optional object otherwise. If the key is null, an exception will be thrown.

-
- - -- Example - - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.remove(20); - ``` - - -### afterRemoval8+ - -afterRemoval\(isEvict:boolean,key:K,value:V,newValue:V\):void - -Performs subsequent operations after a value is deleted. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

isEvict

-

boolean

-

No

-

Whether the buffer capacity is insufficient. If the value is true, this method is called due to insufficient capacity.

-

key

-

K

-

Yes

-

Key deleted.

-

value

-

V

-

Yes

-

Value deleted.

-

newValue

-

V

-

No

-

New value for the key if the put() method is called and the key to be added already exists. In other cases, this parameter is left blank.

-
- - -- Example - - ``` - var arr = []; - class ChildLruBuffer extends util.LruBuffer - { - constructor() - { - super(); - } - static getInstance() - { - if(this.instance == null) - { - this.instance = new ChildLruBuffer(); - } - return this.instance; - } - afterRemoval(isEvict, key, value, newValue) - { - if (isEvict === false) - { - arr = [key, value, newValue]; - } - } - } - ChildLruBuffer.getInstance().afterRemoval(false,10,30,null); - ``` +- Return value + | Type| Description| + | -------- | -------- | + | K [] | All keys in the buffer, listed from the most to the least recently accessed.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro.keys(); + ``` + + +### remove8+ + +remove(key:K):V | undefined + +Removes the specified key and its value from this buffer. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | key | K | Yes| Key to remove.| + +- Return value + | Type| Description| + | -------- | -------- | + | V \| undefind | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.| + +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro.remove(20); + ``` + + +### afterRemoval8+ + +afterRemoval(isEvict:boolean,key:K,value:V,newValue:V):void + +Performs subsequent operations after a value is removed. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | isEvict | boolean | No| Whether the buffer capacity is insufficient. If the value is **true**, this method is called due to insufficient capacity.| + | key | K | Yes| Key removed.| + | value | V | Yes| Value removed.| + | newValue | V | No| New value for the key if the **put()** method is called and the key to be added already exists. In other cases, this parameter is left blank.| + +- Example + ``` + var arr = []; + class ChildLruBuffer extends util.LruBuffer + { + constructor() + { + super(); + } + static getInstance() + { + if(this.instance == null) + { + this.instance = new ChildLruBuffer(); + } + return this.instance; + } + afterRemoval(isEvict, key, value, newValue) + { + if (isEvict === false) + { + arr = [key, value, newValue]; + } + } + } + ChildLruBuffer.getInstance().afterRemoval(false,10,30,null); + ``` + + +### contains8+ + +contains(key:K):boolean + +Checks whether this buffer contains the specified key. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | key | K | Yes| Key to check.| -### contains8+ +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the buffer contains the specified key; returns **false** otherwise.| -contains\(key:K\):boolean +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro.contains(20); + ``` -Checks whether this buffer contains the specified key. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

K

-

Yes

-

Key to check.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the buffer contains the specified key; returns false otherwise.

-
- - -- Example - - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.contains(20); - ``` - - -### createDefault8+ - -createDefault\(key:K\):V +### createDefault8+ + +createDefault(key:K):V Creates a value if the value of the specified key is not available. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

key

-

K

-

Yes

-

Key of which the value is missing.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

V

-

Value of the key.

-
- - -- Example - - ``` - var pro = new util.LruBuffer(); - var result = pro.createDefault(50); - ``` - - -### entries8+ - -entries\(\):IterableIterator<\[K,V\]\> +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | key | K | Yes| Key of which the value is missing.| -Obtains a new iterator object that contains all key-value pairs in this object. +- Return value + | Type| Description| + | -------- | -------- | + | V | Value of the key.| -- Return values +- Example + ``` + var pro = new util.LruBuffer(); + var result = pro.createDefault(50); + ``` - - - - - - - - - -

Type

-

Description

-

[K, V]

-

Returns an iterable array.

-
+### entries8+ -- Example - - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro.entries(); - ``` +entries():IterableIterator<[K,V]> +Obtains a new iterator object that contains all key-value pairs in this object. -### \[Symbol.iterator\]8+ +- Return value + | Type| Description| + | -------- | -------- | + | [K, V] | Iterable array.| -\[Symbol.iterator\]\(\): IterableIterator<\[K, V\]\> +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro.entries(); + ``` -Obtains a two-dimensional array in key-value pairs. -- Return values +### [Symbol.iterator]8+ - - - - - - - - - -

Type

-

Description

-

[K, V]

-

A two-dimensional array in key-value pairs.

-
+[Symbol.iterator]\(): IterableIterator<[K, V]> +Obtains a two-dimensional array in key-value pairs. -- Example +- Return value + | Type| Description| + | -------- | -------- | + | [K, V] | Two-dimensional array in key-value pairs.| - ``` - var pro = new util.LruBuffer(); - pro.put(2,10); - var result = pro[symbol.iterator](); - ``` +- Example + ``` + var pro = new util.LruBuffer(); + pro.put(2,10); + var result = pro[symbol.iterator](); + ``` -## Scope8+ +## Scope8+ -### ScopeType8+ -Defines the type of values in a **Scope** object. The value type can be **ScopeComparable** or **number**. +### ScopeType8+ -The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable. +Defines the type of values in a **Scope** object. The value type can be **ScopeComparable** or **number**. +The values of the **ScopeComparable** type are used to implement the **compareTo** method. Therefore, ensure that the input parameters are comparable. ``` interface ScopeComparable{ compareTo(other:ScopeComparable):boolean; @@ -2126,10 +998,11 @@ interface ScopeComparable{ type ScopeType = ScopeComparable | number; ``` -Create a class to implement the **compareTo** method. In the subsequent sample code, **Temperature** is used as an example of the [ScopeType](#section876116244471) object. -Example +Create a class to implement the **compareTo** method. In the subsequent sample code, **Temperature** is used as an example of the [ScopeType](#scopetype8) object. + +Example ``` class Temperature{ constructor(value){ @@ -2147,3030 +1020,1307 @@ class Temperature{ } ``` -### constructor8+ - -constructor\(lowerObj:ScopeType,upperObje:ScopeType\) - -A constructor used to create a **Scope** object with the specified upper and lower limits. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

lowerObj

-

ScopeType

-

Yes

-

Lower limit of the Scope object.

-

upperObj

-

ScopeType

-

Yes

-

Upper limit of the Scope object.

-
- -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - ``` - - -### toString8+ - -toString\(\):string - -Obtains a string representation that contains this **Scope**. - -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

String representation containing the Scope.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.toString(); - ``` - - -### intersect8+ - -intersect\(range:Scope\):Scope - -Obtains the intersection of this **Scope** and the given **Scope**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

range

-

Scope

-

Yes

-

Scope specified.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

Scope

-

Intersection of this Scope and the given Scope.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var rangeFir = new util.Scope(tempMiDF, tempMidS); - range.intersect(rangeFir ); - ``` - - -### intersect8+ - -intersect\(lowerObj:ScopeType,upperObj:ScopeType\):Scope - -Obtains the intersection of this **Scope** and the given lower and upper limits. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

lowerObj

-

ScopeType

-

Yes

-

Lower limit.

-

upperObj

-

ScopeType

-

Yes

-

Upper limit.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

Scope

-

Intersection of this Scope and the given lower and upper limits.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var result = range.intersect(tempMiDF, tempMidS); - ``` - - -### getUpper8+ - -getUpper\(\):ScopeType - -Obtains the upper limit of this **Scope**. - -- Return values - - - - - - - - - - -

Type

-

Description

-

ScopeType

-

Upper limit of this Scope.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.getUpper(); - ``` - - -### getLower8+ - -getLower\(\):ScopeType - -Obtains the lower limit of this **Scope**. - -- Return values - - - - - - - - - - -

Type

-

Description

-

ScopeType

-

Lower limit of this Scope.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var result = range.getLower(); - ``` - - -### expand8+ - -expand\(lowerObj:ScopeType,upperObj:ScopeType\):Scope - -Obtains the union set of this **Scope** and the given lower and upper limits. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

lowerObj

-

ScopeType

-

Yes

-

Lower limit.

-

upperObj

-

ScopeType

-

Yes

-

Upper limit.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

Scope

-

Union set of this Scope and the given lower and upper limits.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var result = range.expand(tempMiDF, tempMidS); - ``` - - -### expand8+ - -expand\(range:Scope\):Scope - -Obtains the union set of this **Scope** and the given **Scope**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

range

-

Scope

-

Yes

-

Scope specified.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

Scope

-

Union set of this Scope and the given Scope.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var tempMidS = new Temperature(39); - var range = new util.Scope(tempLower, tempUpper); - var rangeFir = new util.Scope(tempMiDF, tempMidS); - var result = range.expand(rangeFir); - ``` - - -### expand8+ - -expand\(value:ScopeType\):Scope - -Obtains the union set of this **Scope** and the given value. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

ScopeType

-

Yes

-

Value specified.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

Scope

-

Union set of this Scope and the given value.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); - var result = range.expand(tempMiDF); - ``` - - -### contains8+ - -contains\(value:ScopeType\):boolean - -Checks whether a value is within this **Scope**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

ScopeType

-

Yes

-

Value specified.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the value is within this Scope; returns false otherwise.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); - range.contains(tempMiDF); - ``` - - -### contains8+ - -contains\(range:Scope\):boolean - -Checks whether a range is within this **Scope**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

range

-

Scope

-

Yes

-

Range specified.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the range is within this Scope; returns false otherwise.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var range = new util.Scope(tempLower, tempUpper); - var tempLess = new Temperature(20); - var tempMore = new Temperature(45); - var rangeSec = new util.Scope(tempLess, tempMore); - var result = range.contains(rangeSec); - ``` - - -### clamp8+ - -clamp\(value:ScopeType\):ScopeType - -Limits a value to this **Scope**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

ScopeType

-

Yes

-

Value specified.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

ScopeType

-

Returns lowerObj if the specified value is less than the lower limit; returns upperObj if the specified value is greater than the upper limit; returns the specified value if it is within this Scope.

-
- - -- Example - - ``` - var tempLower = new Temperature(30); - var tempUpper = new Temperature(40); - var tempMiDF = new Temperature(35); - var range = new util.Scope(tempLower, tempUpper); - var result = range.clamp(tempMiDF); - ``` - - -## Base648+ -### constructor8+ +### constructor8+ + +constructor(lowerObj:ScopeType,upperObje:ScopeType) + +A constructor used to create a **Scope** object with the specified upper and lower limits. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit of the **Scope** object.| + | upperObj | [ScopeType](#scopetype8) | Yes| Upper limit of the **Scope** object.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var range = new util.Scope(tempLower, tempUpper); + ``` + + +### toString8+ + +toString():string + +Obtains a string representation that contains this **Scope**. + +- Return value + | Type| Description| + | -------- | -------- | + | string | String representation containing the **Scope**.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var range = new util.Scope(tempLower, tempUpper); + var result = range.toString(); + ``` + + +### intersect8+ + +intersect(range:Scope):Scope + +Obtains the intersection of this **Scope** and the given **Scope**. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | range | [Scope](#scope8) | Yes| **Scope** specified.| + +- Return value + | Type| Description| + | -------- | -------- | + | [Scope](#scope8) | Intersection of this **Scope** and the given **Scope**.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var range = new util.Scope(tempLower, tempUpper); + var tempMiDF = new Temperature(35); + var tempMidS = new Temperature(39); + var rangeFir = new util.Scope(tempMiDF, tempMidS); + range.intersect(rangeFir ); + ``` + + +### intersect8+ + +intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope + +Obtains the intersection of this **Scope** and the given lower and upper limits. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.| + | upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.| + +- Return value + | Type| Description| + | -------- | -------- | + | [Scope](#scope8) | Intersection of this **Scope** and the given lower and upper limits.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var tempMiDF = new Temperature(35); + var tempMidS = new Temperature(39); + var range = new util.Scope(tempLower, tempUpper); + var result = range.intersect(tempMiDF, tempMidS); + ``` + + +### getUpper8+ + +getUpper():ScopeType + +Obtains the upper limit of this **Scope**. + +- Return value + | Type| Description| + | -------- | -------- | + | [ScopeType](#scopetype8) | Upper limit of this **Scope**.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var range = new util.Scope(tempLower, tempUpper); + var result = range.getUpper(); + ``` + + +### getLower8+ + +getLower():ScopeType + +Obtains the lower limit of this **Scope**. + +- Return value + | Type| Description| + | -------- | -------- | + | [ScopeType](#scopetype8) | Lower limit of this **Scope**.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var range = new util.Scope(tempLower, tempUpper); + var result = range.getLower(); + ``` + + +### expand8+ + +expand(lowerObj:ScopeType,upperObj:ScopeType):Scope + +Obtains the union set of this **Scope** and the given lower and upper limits. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | lowerObj | [ScopeType](#scopetype8) | Yes| Lower limit.| + | upperObj | [ScopeType](#scopetype8) | Yes| Upper limit.| + +- Return value + | Type| Description| + | -------- | -------- | + | [Scope](#scope8) | Union set of this **Scope** and the given lower and upper limits.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var tempMiDF = new Temperature(35); + var tempMidS = new Temperature(39); + var range = new util.Scope(tempLower, tempUpper); + var result = range.expand(tempMiDF, tempMidS); + ``` + + +### expand8+ + +expand(range:Scope):Scope + +Obtains the union set of this **Scope** and the given **Scope**. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | range | [Scope](#scope8) | Yes| **Scope** specified.| + +- Return value + | Type| Description| + | -------- | -------- | + | [Scope](#scope8) | Union set of this **Scope** and the given **Scope**.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var tempMiDF = new Temperature(35); + var tempMidS = new Temperature(39); + var range = new util.Scope(tempLower, tempUpper); + var rangeFir = new util.Scope(tempMiDF, tempMidS); + var result = range.expand(rangeFir); + ``` + + +### expand8+ + +expand(value:ScopeType):Scope + +Obtains the union set of this **Scope** and the given value. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | [ScopeType](#scopetype8) | Yes| Value specified.| + +- Return value + | Type| Description| + | -------- | -------- | + | [Scope](#scope8) | Union set of this **Scope** and the given value.| -constructor\(\) +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var tempMiDF = new Temperature(35); + var range = new util.Scope(tempLower, tempUpper); + var result = range.expand(tempMiDF); + ``` -A constructor used to create a **Base64** object. -- Example +### contains8+ - ``` - var base64 = new util.Base64(); - ``` +contains(value:ScopeType):boolean +Checks whether a value is within this **Scope**. -### encodeSync8+ +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | [ScopeType](#scopetype8) | Yes| Value specified.| -encodeSync\(src:Uint8Array\):Uint8Array +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the value is within this **Scope**; returns **false** otherwise.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var tempMiDF = new Temperature(35); + var range = new util.Scope(tempLower, tempUpper); + range.contains(tempMiDF); + ``` + + +### contains8+ + +contains(range:Scope):boolean + +Checks whether a range is within this **Scope**. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | range | [Scope](#scope8) | Yes| Range specified.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the range is within this **Scope**; returns **false** otherwise.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var range = new util.Scope(tempLower, tempUpper); + var tempLess = new Temperature(20); + var tempMore = new Temperature(45); + var rangeSec = new util.Scope(tempLess, tempMore); + var result = range.contains(rangeSec); + ``` + + +### clamp8+ + +clamp(value:ScopeType):ScopeType + +Limits a value to this **Scope**. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | [ScopeType](#scopetype8) | Yes| Value specified.| + +- Return value + | Type| Description| + | -------- | -------- | + | [ScopeType](#scopetype8) | Returns **lowerObj** if the specified value is less than the lower limit; returns **upperObj** if the specified value is greater than the upper limit; returns the specified value if it is within this **Scope**.| + +- Example + ``` + var tempLower = new Temperature(30); + var tempUpper = new Temperature(40); + var tempMiDF = new Temperature(35); + var range = new util.Scope(tempLower, tempUpper); + var result = range.clamp(tempMiDF); + ``` + + +## Base648+ + + +### constructor8+ + +constructor() + +A constructor used to create a **Base64** object. + +- Example + ``` + var base64 = new util.Base64(); + ``` + + +### encodeSync8+ + +encodeSync(src:Uint8Array):Uint8Array Encodes the input content. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

src

-

Uint8Array

-

Yes

-

Uint8Array to encode.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Uint8Array

-

Uint8Array encoded.

-
- -- Example - - ``` - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var result = that.encodeSync(array); - ``` - - -### encodeToStringSync8+ - -encodeToStringSync\(src:Uint8Array\):string - -Encodes the input content into a string. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

src

-

Uint8Array

-

Yes

-

Uint8Array to encode.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

String encoded from the Uint8Array.

-
- -- Example - - ``` - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var result = that.encodeToStringSync(array); - ``` - - -### decodeSync8+ - -decodeSync\(src:Uint8Array | string\):Uint8Array +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | src | Uint8Array | Yes| Uint8Array to encode.| + +- Return value + | Type| Description| + | -------- | -------- | + | Uint8Array | Uint8Array encoded.| + +- Example + ``` + var that = new util.Base64(); + var array = new Uint8Array([115,49,51]); + var result = that.encodeSync(array); + ``` + + +### encodeToStringSync8+ + +encodeToStringSync(src:Uint8Array):string + +Encodes the input content. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | src | Uint8Array | Yes| Uint8Array to encode.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | String encoded from the Uint8Array.| + +- Example + ``` + var that = new util.Base64(); + var array = new Uint8Array([115,49,51]); + var result = that.encodeToStringSync(array); + ``` + + +### decodeSync8+ + +decodeSync(src:Uint8Array | string):Uint8Array Decodes the input content. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

src

-

Uint8Array | string

-

Yes

-

Uint8Array or string to decode.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Uint8Array

-

Uint8Array decoded.

-
- -- Example - - ``` - var that = new util.Base64(); - var buff = 'czEz'; - var result = that.decodeSync(buff); - ``` - - -### encode8+ - -encode\(src:Uint8Array\):Promise +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | src | Uint8Array \| string | Yes| Uint8Array or string to decode.| + +- Return value + | Type| Description| + | -------- | -------- | + | Uint8Array | Uint8Array decoded.| + +- Example + ``` + var that = new util.Base64(); + var buff = 'czEz'; + var result = that.decodeSync(buff); + ``` + + +### encode8+ + +encode(src:Uint8Array):Promise<Uint8Array> Encodes the input content asynchronously. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

src

-

Uint8Array

-

Yes

-

Uint8Array to encode asynchronously.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<Uint8Array>

-

Uint8Array obtained after asynchronous encoding.

-
- -- Example - - ``` - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - var rarray = new Uint8Array([99,122,69,122]); - await that.encode(array).then(val=>{ - for (var i = 0; i < rarray.length; i++) { - console.log(val[i]) - } - }) - done(); - ``` - - -### encodeToString8+ - -encodeToString\(src:Uint8Array\):Promise - -Encodes the input content asynchronously into a string. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

src

-

Uint8Array

-

Yes

-

Uint8Array to encode asynchronously.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<string>

-

String obtained after asynchronous encoding.

-
- -- Example - - ``` - var that = new util.Base64(); - var array = new Uint8Array([115,49,51]); - await that.encodeToString(array).then(val=>{ - console.log(val) - }) - done(); - ``` - - -### decode8+ - -decode\(src:Uint8Array | string\):Promise +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | src | Uint8Array | Yes| Uint8Array to encode asynchronously.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<Uint8Array> | Uint8Array obtained after asynchronous encoding.| + +- Example + ``` + var that = new util.Base64(); + var array = new Uint8Array([115,49,51]); + var rarray = new Uint8Array([99,122,69,122]); + that.encode(array).then(val=>{ + for (var i = 0; i < rarray.length; i++) { + console.log(val[i]) + } + }) + ``` + + +### encodeToString8+ + +encodeToString(src:Uint8Array):Promise<string> + +Encodes the input content asynchronously. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | src | Uint8Array | Yes| Uint8Array to encode asynchronously.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<string> | String obtained after asynchronous encoding.| + +- Example + ``` + var that = new util.Base64(); + var array = new Uint8Array([115,49,51]); + that.encodeToString(array).then(val=>{ + console.log(val) + }) + ``` + + +### decode8+ + +decode(src:Uint8Array | string):Promise<Uint8Array> Decodes the input content asynchronously. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

src

-

Uint8Array | string

-

Yes

-

Uint8Array or string to decode asynchronously.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<Uint8Array>

-

Uint8Array obtained after asynchronous decoding.

-
- -- Example - - ``` - var that = new util.Base64(); - var array = new Uint8Array([99,122,69,122]); - var rarray = new Uint8Array([115,49,51]); - await that.decode(array).then(val=>{ - for (var i = 0; i < rarray.length; i++) { - console.log(val[i]) - } - }) - done(); - ``` - - -## Types8+ - -### constructor8+ - -constructor\(\) - -A constructor used to create a **Types** object. - -- Example - - ``` - var type = new util.Types(); - ``` - - -### isAnyArrayBuffer8+ - -isAnyArrayBuffer\(value: Object\):boolean - -Checks whether the input value is of the **ArrayBuffer** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the ArrayBuffer type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isAnyArrayBuffer(new ArrayBuffer([])); - ``` - - -### isArrayBufferView8+ - -isArrayBufferView\(value: Object\):boolean - -Checks whether the input value is of the **ArrayBufferView** type. - -**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- - Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the ArrayBufferView type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isArrayBufferView(new Int8Array([])); - ``` - - -### isArgumentsObject8+ - -isArgumentsObject\(value: Object\):boolean - -Checks whether the input value is of the **arguments** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the arguments type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - function foo() { - var result = that.isArgumentsObject(arguments); - } - var f = foo(); - ``` - - -### isArrayBuffer8+ - -isArrayBuffer\(value: Object\):boolean - -Checks whether the input value is of the **ArrayBuffer** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the ArrayBuffer type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isArrayBuffer(new ArrayBuffer([])); - ``` - - -### isAsyncFunction8+ - -isAsyncFunction\(value: Object\):boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<Uint8Array> | Uint8Array obtained after asynchronous decoding.| + +- Example + ``` + var that = new util.Base64(); + var array = new Uint8Array([99,122,69,122]); + var rarray = new Uint8Array([115,49,51]); + that.decode(array).then(val=>{ + for (var i = 0; i < rarray.length; i++) { + console.log(val[i]) + } + }) + ``` + + +## Types8+ + + +### constructor8+ + +constructor() + +A constructor used to create a **Types** object. + +- Example + ``` + var type = new util.Types(); + ``` + + +### isAnyArrayBuffer8+ + +isAnyArrayBuffer(value: Object):boolean + +Checks whether the input value is of the **ArrayBuffer** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isAnyArrayBuffer(new ArrayBuffer([])); + ``` + + +### isArrayBufferView8+ + +isArrayBufferView(value: Object):boolean + +Checks whether the input value is of the **ArrayBufferView** type. + +**ArrayBufferView** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **ArrayBufferView** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isArrayBufferView(new Int8Array([])); + ``` + + +### isArgumentsObject8+ + +isArgumentsObject(value: Object):boolean + +Checks whether the input value is of the **arguments** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **arguments** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + function foo() { + var result = that.isArgumentsObject(arguments); + } + var f = foo(); + ``` + + +### isArrayBuffer8+ + +isArrayBuffer(value: Object):boolean + +Checks whether the input value is of the **ArrayBuffer** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **ArrayBuffer** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isArrayBuffer(new ArrayBuffer([])); + ``` + + +### isAsyncFunction8+ + +isAsyncFunction(value: Object):boolean Checks whether the input value is an asynchronous function. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is an asynchronous function; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isAsyncFunction(async function foo() {}); - ``` - - -### isBooleanObject8+ - -isBooleanObject\(value: Object\):boolean - -Checks whether the input value is of the **Boolean** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Boolean type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isBooleanObject(new Boolean(true)); - ``` - - -### isBoxedPrimitive8+ - -isBoxedPrimitive\(value: Object\):boolean - -Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Boolean, Number, String, or Symbol type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isBoxedPrimitive(new Boolean(false)); - ``` - - -### isDataView8+ - -isDataView\(value: Object\):boolean - -Checks whether the input value is of the **DataView** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the DataView type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - const ab = new ArrayBuffer(20); - var result = that.isDataView(new DataView(ab)); - ``` - - -### isDate8+ - -isDate\(value: Object\):boolean - -Checks whether the input value is of the **Date** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Data type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isDate(new Date()); - ``` - - -### isExternal8+ - -isExternal\(value: Object\):boolean - -Checks whether the input value is of the **native external** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the native external type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - const data = util.createExternalType(); - var result = that.isExternal(data); - ``` - - -### isFloat32Array8+ - -isFloat32Array\(value: Object\):boolean - -Checks whether the input value is of the **Float32Array** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Float32Array type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isFloat32Array(new Float32Array()); - ``` - - -### isFloat64Array8+ - -isFloat64Array\(value: Object\):boolean - -Checks whether the input value is of the **Float64Array** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Float64Array type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isFloat64Array(new Float64Array()); - ``` - - -### isGeneratorFunction8+ - -isGeneratorFunction\(value: Object\):boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is an asynchronous function; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isAsyncFunction(async function foo() {}); + ``` + + +### isBooleanObject8+ + +isBooleanObject(value: Object):boolean + +Checks whether the input value is of the **Boolean** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Boolean** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isBooleanObject(new Boolean(true)); + ``` + + +### isBoxedPrimitive8+ + +isBoxedPrimitive(value: Object):boolean + +Checks whether the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Boolean**, **Number**, **String**, or **Symbol** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isBoxedPrimitive(new Boolean(false)); + ``` + + +### isDataView8+ + +isDataView(value: Object):boolean + +Checks whether the input value is of the **DataView** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **DataView** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + const ab = new ArrayBuffer(20); + var result = that.isDataView(new DataView(ab)); + ``` + + +### isDate8+ + +isDate(value: Object):boolean + +Checks whether the input value is of the **Date** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Date** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isDate(new Date()); + ``` + + +### isExternal8+ + +isExternal(value: Object):boolean + +Checks whether the input value is of the **native external** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **native external** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + const data = util.createExternalType(); + var result = that.isExternal(data); + ``` + + +### isFloat32Array8+ + +isFloat32Array(value: Object):boolean + +Checks whether the input value is of the **Float32Array** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Float32Array** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isFloat32Array(new Float32Array()); + ``` + + +### isFloat64Array8+ + +isFloat64Array(value: Object):boolean + +Checks whether the input value is of the **Float64Array** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Float64Array** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isFloat64Array(new Float64Array()); + ``` + + +### isGeneratorFunction8+ + +isGeneratorFunction(value: Object):boolean Checks whether the input value is a generator function. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is a generator function; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isGeneratorFunction(function* foo() {}); - ``` - - -### isGeneratorObject8+ - -isGeneratorObject\(value: Object\):boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is a generator function; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isGeneratorFunction(function* foo() {}); + ``` + + +### isGeneratorObject8+ + +isGeneratorObject(value: Object):boolean Checks whether the input value is a generator object. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is a generator object; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - function* foo() {} - const generator = foo(); - var result = that.isGeneratorObject(generator); - ``` - - -### isInt8Array8+ - -isInt8Array\(value: Object\):boolean - -Checks whether the input value is of the **Int8Array** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Int8Array type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isInt8Array(new Int8Array([])); - ``` - - -### isInt16Array8+ - -isInt16Array\(value: Object\):boolean - -Checks whether the input value is of the **Int16Array** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Int16Array type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isInt16Array(new Int16Array([])); - ``` - - -### isInt32Array8+ - -isInt32Array\(value: Object\):boolean - -Checks whether the input value is of the **Int32Array** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Int32Array type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isInt32Array(new Int32Array([])); - ``` - - -### isMap8+ - -isMap\(value: Object\):boolean - -Checks whether the input value is of the **Map** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Map type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isMap(new Map()); - ``` - - -### isMapIterator8+ - -isMapIterator\(value: Object\):boolean - -Checks whether the input value is of the **MapIterator** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the MapIterator type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - const map = new Map(); - var result = that.isMapIterator(map.keys()); - ``` - - -### isNativeError8+ - -isNativeError\(value: Object\):boolean - -Checks whether the input value is of the **Error** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Error type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isNativeError(new TypeError()); - ``` - - -### isNumberObject8+ - -isNumberObject\(value: Object\):boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is a generator object; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + function* foo() {} + const generator = foo(); + var result = that.isGeneratorObject(generator); + ``` + + +### isInt8Array8+ + +isInt8Array(value: Object):boolean + +Checks whether the input value is of the **Int8Array** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Int8Array** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isInt8Array(new Int8Array([])); + ``` + + +### isInt16Array8+ + +isInt16Array(value: Object):boolean + +Checks whether the input value is of the **Int16Array** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Int16Array** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isInt16Array(new Int16Array([])); + ``` + + +### isInt32Array8+ + +isInt32Array(value: Object):boolean + +Checks whether the input value is of the **Int32Array** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Int32Array** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isInt32Array(new Int32Array([])); + ``` + + +### isMap8+ + +isMap(value: Object):boolean + +Checks whether the input value is of the **Map** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Map** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isMap(new Map()); + ``` + + +### isMapIterator8+ + +isMapIterator(value: Object):boolean + +Checks whether the input value is of the **MapIterator** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **MapIterator** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + const map = new Map(); + var result = that.isMapIterator(map.keys()); + ``` + + +### isNativeError8+ + +isNativeError(value: Object):boolean + +Checks whether the input value is of the **Error** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Error** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isNativeError(new TypeError()); + ``` + + +### isNumberObject8+ + +isNumberObject(value: Object):boolean Checks whether the input value is a number object. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is a number object; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isNumberObject(new Number(0)); - ``` - - -### isPromise8+ - -isPromise\(value: Object\):boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is a number object; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isNumberObject(new Number(0)); + ``` + + +### isPromise8+ + +isPromise(value: Object):boolean Checks whether the input value is a promise. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is a promise; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isPromise(Promise.resolve(1)); - ``` - - -### isProxy8+ - -isProxy\(value: Object\):boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is a promise; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isPromise(Promise.resolve(1)); + ``` + + +### isProxy8+ + +isProxy(value: Object):boolean Checks whether the input value is a proxy. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is a proxy; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - const target = {}; - const proxy = new Proxy(target, {}); - var result = that.isProxy(proxy); - ``` - - -### isRegExp8+ - -isRegExp\(value: Object\):boolean - -Checks whether the input value is of the **RegExp** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the RegExp type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isRegExp(new RegExp('abc')); - ``` - - -### isSet8+ - -isSet\(value: Object\):boolean - -Checks whether the input value is of the **Set** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Set type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isSet(new Set()); - ``` - - -### isSetIterator8+ - -isSetIterator\(value: Object\):boolean - -Checks whether the input value is of the **SetIterator** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the SetIterator type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - const set = new Set(); - var result = that.isSetIterator(set.keys()); - ``` - - -### isStringObject8+ - -isStringObject\(value: Object\):boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is a proxy; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + const target = {}; + const proxy = new Proxy(target, {}); + var result = that.isProxy(proxy); + ``` + + +### isRegExp8+ + +isRegExp(value: Object):boolean + +Checks whether the input value is of the **RegExp** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **RegExp** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isRegExp(new RegExp('abc')); + ``` + + +### isSet8+ + +isSet(value: Object):boolean + +Checks whether the input value is of the **Set** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Set** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isSet(new Set()); + ``` + + +### isSetIterator8+ + +isSetIterator(value: Object):boolean + +Checks whether the input value is of the **SetIterator** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **SetIterator** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + const set = new Set(); + var result = that.isSetIterator(set.keys()); + ``` + + +### isStringObject8+ + +isStringObject(value: Object):boolean Checks whether the input value is a string object. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is a string object; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isStringObject(new String('foo')); - ``` - - -### isSymbolObjec8+ - -isSymbolObjec\(value: Object\):boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is a string object; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isStringObject(new String('foo')); + ``` + + +### isSymbolObjec8+ + +isSymbolObjec(value: Object):boolean Checks whether the input value is a symbol object. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is a symbol object; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - const symbols = Symbol('foo'); - var result = that.isSymbolObject(Object(symbols)); - ``` - - -### isTypedArray8+ - -isTypedArray\(value: Object\):boolean - -Checks whether the input value is of the **TypedArray** type. - -**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the TypedArray type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isTypedArray(new Float64Array([])); - ``` - - -### isUint8Array8+ - -isUint8Array\(value: Object\):boolean - -Checks whether the input value is of the **Uint8Array** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Uint8Array type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isUint8Array(new Uint8Array([])); - ``` - - -### isUint8ClampedArray8+ - -isUint8ClampedArray\(value: Object\):boolean - -Checks whether the input value is of the **Uint8ClampedArray** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Uint8ClampedArray type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isUint8ClampedArray(new Uint8ClampedArray([])); - ``` - - -### isUint16Array8+ - -isUint16Array\(value: Object\):boolean - -Checks whether the input value is of the **Uint16Array** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Uint16Array type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isUint16Array(new Uint16Array([])); - ``` - - -### isUint32Array8+ - -isUint32Array\(value: Object\):boolean - -Checks whether the input value is of the **Uint32Array** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the Uint32Array type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isUint32Array(new Uint32Array([])); - ``` - - -### isWeakMap8+ - -isWeakMap\(value: Object\):boolean - -Checks whether the input value is of the **WeakMap** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the WeakMap type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isWeakMap(new WeakMap()); - ``` - - -### isWeakSet8+ - -isWeakSet\(value: Object\):boolean - -Checks whether the input value is of the **WeakSet** type. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

Object

-

Yes

-

Object to check.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the input value is of the WeakSet type; returns false otherwise.

-
- -- Example - - ``` - var that = new util.Types(); - var result = that.isWeakSet(new WeakSet()); - ``` +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is a symbol object; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + const symbols = Symbol('foo'); + var result = that.isSymbolObject(Object(symbols)); + ``` + + +### isTypedArray8+ + +isTypedArray(value: Object):boolean + +Checks whether the input value is of the **TypedArray** type. + +**TypedArray** is a helper type representing any of the following: **Int8Array**, **Int16Array**, **Int32Array**, **Uint8Array**, **Uint8ClampedArray**, **Uint16Array**, **Uint32Array**, **Float32Array**, **Float64Array**, and **DataView**. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **TypedArray** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isTypedArray(new Float64Array([])); + ``` + + +### isUint8Array8+ + +isUint8Array(value: Object):boolean + +Checks whether the input value is of the **Uint8Array** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Uint8Array** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isUint8Array(new Uint8Array([])); + ``` + + +### isUint8ClampedArray8+ + +isUint8ClampedArray(value: Object):boolean + +Checks whether the input value is of the **Uint8ClampedArray** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Uint8ClampedArray** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isUint8ClampedArray(new Uint8ClampedArray([])); + ``` + + +### isUint16Array8+ + +isUint16Array(value: Object):boolean + +Checks whether the input value is of the **Uint16Array** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Uint16Array** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isUint16Array(new Uint16Array([])); + ``` + + +### isUint32Array8+ + +isUint32Array(value: Object):boolean + +Checks whether the input value is of the **Uint32Array** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **Uint32Array** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isUint32Array(new Uint32Array([])); + ``` + + +### isWeakMap8+ + +isWeakMap(value: Object):boolean + +Checks whether the input value is of the **WeakMap** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **WeakMap** type; returns **false** otherwise.| + +- Example + ``` + var that = new util.Types(); + var result = that.isWeakMap(new WeakMap()); + ``` + + +### isWeakSet8+ + +isWeakSet(value: Object):boolean + +Checks whether the input value is of the **WeakSet** type. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | Object | Yes| Object to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | Returns **true** if the input value is of the **WeakSet** type; returns **false** otherwise.| +- Example + ``` + var that = new util.Types(); + var result = that.isWeakSet(new WeakSet()); + ``` diff --git a/en/application-dev/reference/apis/js-apis-worker.md b/en/application-dev/reference/apis/js-apis-worker.md index 53879bb88fdee523a3f5fdbd0ebc61113c3cc367..ed6daf2f23f883bd6d166b24545624a61dea369b 100644 --- a/en/application-dev/reference/apis/js-apis-worker.md +++ b/en/application-dev/reference/apis/js-apis-worker.md @@ -1,1225 +1,578 @@ -# Worker Startup +# Worker Startup ->**NOTE:** ->The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Modules to Import + +## Modules to Import ``` import worker from '@ohos.worker'; ``` -## Required Permissions - -None - -## Attributes - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

parentPort

-

DedicatedWorkerGlobalScope

-

Yes

-

Yes

-

Object of the worker thread used to communicate with the host thread.

-
- -## WorkerOptions +## System Capabilities + +SystemCapability.Utils.Lang + +## Attributes + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| parentPort | [DedicatedWorkerGlobalScope](#dedicatedworkerglobalscope) | Yes| Yes| Object of the worker thread used to communicate with the host thread.| + + +## WorkerOptions Provides options that can be set for the worker to create. - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

type

-

"classic"

-

Yes

-

Yes

-

Mode in which the worker executes the script.

-

name

-

string

-

Yes

-

Yes

-

Name of the worker.

-
- -## Worker - -Before using the following methods, you must construct a worker instance. The **worker** class inherits from [EventTarget](#section256019311465). - -### constructor - -constructor\(scriptURL: string, options?: WorkerOptions\) - -A constructor used to create a worker instance. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

scriptURL

-

string

-

Yes

-

URL of the script to be executed by the worker. The script is stored in the workers directory, which is in the same directory as the pages directory of the new DevEco Studio project. If the workers directory does not exist, you need to create it.

-

options

-

WorkerOptions

-

No

-

Options that can be set for the worker.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Worker

-

Returns the worker instance created; returns undefined if the worker instance fails to be created.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js", {name:"first worker"}); - ``` - - -### postMessage - -postMessage\(message: Object, options?: PostMessageOptions\): void +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| type | "classic" | Yes| Yes| Mode in which the worker executes the script.| +| name | string | Yes| Yes| Name of the worker.| + + +## Worker + +Before using the following methods, you must construct a worker instance. The **Worker** class inherits from [EventTarget](#eventtarget). + + +### constructor + +constructor(scriptURL: string, options?: WorkerOptions) + +A constructor used to create a **Worker** instance. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| scriptURL | string | Yes| URL of the script to be executed by the worker. The script is stored in the **workers** directory, which is in the same directory as the **pages** directory of the new DevEco Studio project. If the **workers** directory does not exist, you need to create it.| +| options | [WorkerOptions](#workeroptions) | No| Options that can be set for the worker.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| worker | Returns the **Worker** instance created; returns **undefined** if the **Worker** instance fails to be created.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js", {name:"first worker"}); +``` + + +### postMessage + +postMessage(message: Object, options?: PostMessageOptions): void Sends a message to the worker thread. The data is transferred using the structured clone algorithm. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

message

-

Object

-

Yes

-

Data to be sent to the worker.

-

options

-

PostMessageOptions

-

No

-

ArrayBuffer instances that can be transferred. The transferList array cannot contain null.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - workerInstance.postMessage("hello world"); - ``` - - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - var buffer = new ArrayBuffer(8); - workerInstance.postMessage(buffer, [buffer]); - ``` - - -### on - -on\(type: string, listener: EventListener\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| message | Object | Yes| Data to be sent to the worker.| +| options | [PostMessageOptions](#postmessageoptions) | No| **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js"); +workerInstance.postMessage("hello world"); +``` +``` +const workerInstance= new worker.Worker("workers/worker.js"); +var buffer = new ArrayBuffer(8); +workerInstance.postMessage(buffer, [buffer]); +``` + + +### on + +on(type: string, listener: EventListener): void Adds an event listener to the worker. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Type of the event to listen for.

-

listener

-

EventListener

-

Yes

-

Callback to invoke when an event of the specified type occurs.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.on("alert", (e)=>{ - console.log("alert listener callback"); - }) - ``` - - -### once - -once\(type: string, listener: EventListener\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the event to listen for.| +| listener | [EventListener](#eventlistener) | Yes| Callback to invoke when an event of the specified type occurs.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.on("alert", (e)=>{ + console.log("alert listener callback"); +}) +``` + + +### once + +once(type: string, listener: EventListener): void Adds an event listener to the worker and removes the event listener automatically after it is invoked once. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Type of the event to listen for.

-

listener

-

EventListener

-

Yes

-

Callback to invoke when an event of the specified type occurs.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - workerInstance.once("alert", (e)=>{ - console.log("alert listener callback"); - }) - ``` - - -### off - -off\(type: string, listener?: EventListener\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the event to listen for.| +| listener | [EventListener](#eventlistener) | Yes| Callback to invoke when an event of the specified type occurs.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js"); +workerInstance.once("alert", (e)=>{ + console.log("alert listener callback"); +}) +``` + + +### off + +off(type: string, listener?: EventListener): void Removes an event listener for the worker. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Type of the event for which the event listener is removed.

-

listener

-

EventListener

-

No

-

Callback of the event listener to remove.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - workerInstance.off("alert"); - ``` - - -### terminate - -terminate\(\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the event for which the event listener is removed.| +| listener | [EventListener](#eventlistener) | No| Callback of the event listener to remove.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js"); +workerInstance.off("alert"); +``` + + +### terminate + +terminate(): void Terminates the worker thread to stop the worker from receiving messages. -- Example +**Example** - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.terminate() - ``` +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.terminate() +``` -### onexit +### onexit -onexit?: \(code: number\) =\> void +onexit?: (code: number) => void Defines the event handler to be called when the worker exits. The handler is executed in the host thread. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

code

-

number

-

No

-

Code indicating the worker exit state.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.onexit = function(e) { - console.log("onexit") - } - ``` - - -### onerror - -onerror?: \(err: ErrorEvent\) =\> void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| code | number | No| Code indicating the worker exit state.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.onexit = function(e) { + console.log("onexit") +} +``` + + +### onerror + +onerror?: (err: ErrorEvent) => void Defines the event handler to be called when an exception occurs during worker execution. The event handler is executed in the host thread. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

err

-

ErrorEvent

-

No

-

Error data.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.onerror = function(e) { - console.log("onerror") - } - ``` - - -### onmessage - -onmessage?: \(event: MessageEvent\) =\> void - -Defines the event handler to be called when the host thread receives a message created by itself and sent by the worker through the **parentPort.postMessage**. The event handler is executed in the host thread. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

event

-

MessageEvent

-

No

-

Message received.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.onmessage = function(e) { - console.log("onerror") - } - ``` - - -### onmessageerror - -onmessageerror?: \(event: MessageEvent\) =\> void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| err | [ErrorEvent](#errorevent) | No| Error data.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.onerror = function(e) { + console.log("onerror") +} +``` + + +### onmessage + +onmessage?: (event: MessageEvent) => void + +Defines the event handler to be called when the host thread receives a message created by itself and sent by the worker through the **parentPort.postMessage**. The event handler is executed in the host thread. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| event | [MessageEvent](#messageevent) | No| Message received.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.onmessage = function(e) { + console.log("onerror") +} +``` + + +### onmessageerror + +onmessageerror?: (event: MessageEvent) => void Defines the event handler to be called when the worker receives a message that cannot be serialized. The event handler is executed in the host thread. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

event

-

MessageEvent

-

No

-

Error data.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.onmessageerror= function(e) { - console.log("onmessageerror") - } - ``` - - -## EventTarget - -### addEventListener - -addEventListener\(type: string, listener: EventListener\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| event | [MessageEvent](#messageevent) | No| Error data.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.onmessageerror= function(e) { + console.log("onmessageerror") +} +``` + + +## EventTarget + + +### addEventListener + +addEventListener(type: string, listener: EventListener): void Adds an event listener to the worker. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Type of the event to listen for.

-

listener

-

EventListener

-

Yes

-

Callback to invoke when an event of the specified type occurs.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.addEventListener("alert", (e)=>{ - console.log("alert listener callback"); - }) - ``` - - -### removeEventListener - -removeEventListener\(type: string, callback?: EventListener\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the event to listen for.| +| listener | [EventListener](#eventlistener) | Yes| Callback to invoke when an event of the specified type occurs.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.addEventListener("alert", (e)=>{ + console.log("alert listener callback"); +}) +``` + + +### removeEventListener + +removeEventListener(type: string, callback?: EventListener): void Removes an event listener for the worker. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

string

-

Yes

-

Type of the event for which the event listener is removed.

-

callback

-

EventListener

-

No

-

Callback of the event listener to remove.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.removeEventListener("alert") - ``` - - -### dispatchEvent - -dispatchEvent\(event: Event\): boolean +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the event for which the event listener is removed.| +| callback | [EventListener](#eventlistener) | No| Callback of the event listener to remove.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.removeEventListener("alert") +``` + + +### dispatchEvent + +dispatchEvent(event: Event): boolean Dispatches the event defined for the worker. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

event

-

Event

-

Yes

-

Event to dispatch.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the event is dispatched successfully; returns false otherwise.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.dispatchEvent({type:"alert"}) - ``` - - -### removeAllListener - -removeAllListener\(\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| event | [Event](#event) | Yes| Event to dispatch.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the event is dispatched successfully; returns **false** otherwise.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.dispatchEvent({type:"alert"}) +``` + + +### removeAllListener + +removeAllListener(): void Removes all event listeners for the worker. -- Example +**Example** - ``` - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.removeAllListener({type:"alert"}) - ``` +``` +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.removeAllListener({type:"alert"}) +``` -## DedicatedWorkerGlobalScope +## DedicatedWorkerGlobalScope -Implements communication between the worker thread and the host thread. The **postMessage** API is used to send messages to the host thread, and the **close** API is used to terminate the worker thread. The **DedicatedWorkerGlobalScope** class inherits from [WorkerGlobalScope](#section12882825611). +Implements communication between the worker thread and the host thread. The **postMessage** API is used to send messages to the host thread, and the **close** API is used to terminate the worker thread. The **DedicatedWorkerGlobalScope** class inherits from [WorkerGlobalScope](#workerglobalscope). -### postMessage -postMessage\(message: Object, options?: PostMessageOptions\): void +### postMessage + +postMessage(message: Object, options?: PostMessageOptions): void Sends a message to the host thread from the worker. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

message

-

Object

-

Yes

-

Data to be sent to the worker.

-

options

-

PostMessageOptions

-

No

-

ArrayBuffer instances that can be transferred. The transferList array cannot contain null.

-
- -- Example - - ``` - // main.js - import worker from "@ohos.worker"; - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.postMessage("hello world") - workerInstance.onmessage = function(e) { - console.log("receive data from worker.js") - } - ``` - - ``` - // worker.js - import worker from "@ohos.worker"; - const parentPort = worker.parentPort; - parentPort.onmessage = function(e){ - parentPort.postMessage("receive data from main.js") - } - ``` - - -### close - -close\(\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| message | Object | Yes| Data to be sent to the worker.| +| options | [PostMessageOptions](#postmessageoptions) | No| **ArrayBuffer** instances that can be transferred. The **transferList** array cannot contain **null**.| + +**Example** + +``` +// main.js +import worker from '@ohos.worker'; +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.postMessage("hello world") +workerInstance.onmessage = function(e) { + console.log("receive data from worker.js") +} +``` +``` +// worker.js +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; +parentPort.onmessage = function(e){ + parentPort.postMessage("receive data from main.js") +} +``` + + +### close + +close(): void Closes the worker thread to stop the worker from receiving messages. -- Example - - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - ``` - - ``` - // worker.js - import worker from "@ohos.worker"; - const parentPort = worker.parentPort; - parentPort.onmessage = function(e) { - parentPort.close() - } - ``` - - -### onmessage - -onmessage?: \(event: MessageEvent\) =\> void - -Defines the event handler to be called when the worker thread receives a message sent by the host thread through **worker.postMessage**. The event handler is executed in the worker thread. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

event

-

MessageEvent

-

No

-

Message received.

-
- -- Example - - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - workerInstance.postMessage("hello world") - ``` - - ``` - // worker.js - import worker from "@ohos.worker"; - const parentPort = worker.parentPort; - parentPort.onmessage = function(e) { - console.log("receive main.js message") - } - ``` - - -### onmessageerror - -onmessageerror?: \(event: MessageEvent\) =\> void +**Example** + +``` +// main.js +import worker from '@ohos.worker'; +const workerInstance = new worker.Worker("workers/worker.js") +``` +``` +// worker.js +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; +parentPort.onmessage = function(e) { + parentPort.close() +} +``` + + +### onmessage + +onmessage?: (event: MessageEvent) => void + +Defines the event handler to be called when the worker thread receives a message sent by the host thread through **worker.postMessage**. The event handler is executed in the worker thread. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| event | [MessageEvent](#messageevent) | No| Message received.| + +**Example** + +``` +// main.js +import worker from '@ohos.worker'; +const workerInstance = new worker.Worker("workers/worker.js") +workerInstance.postMessage("hello world") +``` +``` +// worker.js +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; +parentPort.onmessage = function(e) { + console.log("receive main.js message") +} +``` + + +### onmessageerror + +onmessageerror?: (event: MessageEvent) => void Defines the event handler to be called when the worker receives a message that cannot be deserialized. The event handler is executed in the worker thread. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

event

-

MessageEvent

-

No

-

Error data.

-
- -- Example - - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - ``` - - ``` - // worker.js - import worker from "@ohos.worker"; - const parentPort = worker.parentPort; - parentPort.onmessageerror= function(e) { - console.log("worker.js onmessageerror") - } - ``` - - -## PostMessageOptions - -Specifies the object whose ownership needs to be transferred during data transfer. The object must be **ArrayBuffer**. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

transfer

-

Object[]

-

Yes

-

Yes

-

ArrayBuffer array used to transfer the ownership.

-
- -## Event +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| event | [MessageEvent](#messageevent) | No| Error data.| + +**Example** + +``` +// main.js +import worker from '@ohos.worker'; +const workerInstance = new worker.Worker("workers/worker.js") +``` +``` +// worker.js +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; +parentPort.onmessageerror= function(e) { + console.log("worker.js onmessageerror") +} +``` + + +## PostMessageOptions + +Specifies the object whose ownership needs to be transferred during data transfer. The object must be **ArrayBuffer**. + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| transfer | Object[] | Yes| Yes| **ArrayBuffer** array used to transfer the ownership.| + + +## Event Defines the event. - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

type

-

string

-

Yes

-

No

-

Type of the event.

-

timeStamp

-

number

-

Yes

-

No

-

Timestamp (accurate to millisecond) when the event is created.

-
- -## EventListener +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| type | string | Yes| No| Type of the event.| +| timeStamp | number | Yes| No| Timestamp (accurate to millisecond) when the event is created.| + + +## EventListener Implements event listening. -### \(evt: Event\): void | Promise + +### (evt: Event): void | Promise<void> Specifies the callback to invoke. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

evt

-

Event

-

Yes

-

Event class for the callback to invoke.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

void | Promise<void>

-

Returns no value or returns a Promise.

-
- -- Example - - ``` - const workerInstance = new worker.Worker("workers/worker.js"); - workerInstance.addEventListener("alert", (e)=>{ - console.log("alert listener callback"); - }) - ``` - - -## ErrorEvent - -Provides detailed information about the exception occurred during worker execution. The **ErrorEvent** class inherits from [Event](#section1674694018507). - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

message

-

string

-

Yes

-

No

-

Information about the exception.

-

filename

-

string

-

Yes

-

No

-

File where the exception is located.

-

lineno

-

number

-

Yes

-

No

-

Number of the line where the exception is located.

-

colno

-

number

-

Yes

-

No

-

Number of the column where the exception is located.

-

error

-

Object

-

Yes

-

No

-

Type of the exception.

-
- -## MessageEvent +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| evt | [Event](#event) | Yes| Event class for the callback to invoke.| + +**Return value** + +| Type| Description| +| -------- | -------- | +| void \| Promise<void> | Returns no value or returns a **Promise**.| + +**Example** + +``` +const workerInstance = new worker.Worker("workers/worker.js"); +workerInstance.addEventListener("alert", (e)=>{ + console.log("alert listener callback"); +}) +``` + + +## ErrorEvent + +Provides detailed information about the exception occurred during worker execution. The **ErrorEvent** class inherits from [Event](#event). + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| message | string | Yes| No| Information about the exception.| +| filename | string | Yes| No| File where the exception is located.| +| lineno | number | Yes| No| Number of the line where the exception is located.| +| colno | number | Yes| No| Number of the column where the exception is located.| +| error | Object | Yes| No| Type of the exception.| + + +## MessageEvent Holds the data transferred between worker threads. - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

data

-

T

-

Yes

-

No

-

Data transferred between threads.

-
- -## WorkerGlobalScope - -Defines the running environment of the worker thread. The **WorkerGlobalScope** class inherits from [EventTarget](#section256019311465). - -### Attributes - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

name

-

string

-

Yes

-

No

-

Worker name specified when there is a new worker.

-

self

-

WorkerGlobalScope & typeof globalThis

-

Yes

-

No

-

WorkerGlobalScope.

-
- -### onerror - -onerror?: \(ev: ErrorEvent\) =\> void +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| data | T | Yes| No| Data transferred between threads.| + + +## WorkerGlobalScope + +Defines the running environment of the worker thread. The **WorkerGlobalScope** class inherits from [EventTarget](#eventtarget). + + +### Attributes + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| name | string | Yes| No| Worker name specified when there is a new worker.| +| self | [WorkerGlobalScope](#workerglobalscope) & typeof globalThis | Yes| No| WorkerGlobalScope.| + + +### onerror + +onerror?: (ev: ErrorEvent) => void Defines the event handler to be called when an exception occurs during worker execution. The event handler is executed in the worker thread. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

ev

-

ErrorEvent

-

No

-

Error data.

-
- -- Example - - ``` - // main.js - import worker from '@ohos.worker'; - const workerInstance = new worker.Worker("workers/worker.js") - ``` - - ``` - // worker.js - import worker from "@ohos.worker"; - const parentPort = worker.parentPort - parentPort.onerror = function(e){ - console.log("worker.js onerror") - } - ``` +**Parameters** +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| ev | [ErrorEvent](#errorevent) | No| Error data.| +**Example** +``` +// main.js +import worker from '@ohos.worker'; +const workerInstance = new worker.Worker("workers/worker.js") +``` +``` +// worker.js +import worker from '@ohos.worker'; +const parentPort = worker.parentPort +parentPort.onerror = function(e){ + console.log("worker.js onerror") +} +``` diff --git a/en/application-dev/reference/apis/js-apis-xml.md b/en/application-dev/reference/apis/js-apis-xml.md index 98ff62e6a3926a15f049b6a18d98d8f9a463c2b4..5956204c4bb372753c84bfd4321df98fccae1fc2 100644 --- a/en/application-dev/reference/apis/js-apis-xml.md +++ b/en/application-dev/reference/apis/js-apis-xml.md @@ -1,976 +1,491 @@ -# XML Parsing and Generation +# XML Parsing and Generation ->![](../../public_sys-resources/icon-note.gif) **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. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **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 + +## Modules to Import ``` import xml from '@ohos.xml'; ``` -## Required Permissions +## System Capabilities -None +SystemCapability.Utils.Lang -## XmlSerializer +## XmlSerializer -### constructor -constructor\(buffer: ArrayBuffer | DataView, encoding?: string\) +### constructor -A constructor used to create an **XmlSerializer** instance. +constructor(buffer: ArrayBuffer | DataView, encoding?: string) -- Parameters +A constructor used to create an **XmlSerializer** instance. - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

buffer

-

ArrayBuffer | DataView

-

Yes

-

ArrayBuffer or DataView for storing the XML information to write.

-

encoding

-

string

-

No

-

Encoding format.

-
+**Parameters** +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| buffer | ArrayBuffer \| DataView | Yes| **ArrayBuffer** or **DataView** for storing the XML information to write.| +| encoding | string | No| Encoding format.| -- Example +**Example** - ``` - var arrayBuffer = new ArrayBuffer(1024); - var bufView = new DataView(arrayBuffer); - var thatSer = new xml.XmlSerializer(bufView); - ``` +``` +var arrayBuffer = new ArrayBuffer(1024); +var bufView = new DataView(arrayBuffer); +var thatSer = new xml.XmlSerializer(bufView); +``` -### setAttributes +### setAttributes -setAttributes\(name: string, value: string\): void +setAttributes(name: string, value: string): void Sets an attribute. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

name

-

string

-

Yes

-

Key of the attribute.

-

value

-

string

-

Yes

-

Value of the attribute.

-
- -- Example - - ``` - var thatSer = new xml.XmlSerializer(bufView); - thatSer.setAttributes("importance", "high"); - ``` - - -### addEmptyElement - -addEmptyElement\(name: string\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Key of the attribute.| +| value | string | Yes| Value of the attribute.| + +**Example** + +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setAttributes("importance", "high"); +``` -Adds an empty element. -- Parameters +### addEmptyElement + +addEmptyElement(name: string): void + +Adds an empty element. - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

name

-

string

-

Yes

-

Name of the empty element to add.

-
+**Parameters** +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Name of the empty element to add.| -- Example +**Example** - ``` - var thatSer = new xml.XmlSerializer(bufView); - thatSer.addEmptyElement("b"); // => - ``` +``` + var thatSer = new xml.XmlSerializer(bufView); +thatSer.addEmptyElement("b"); // => +``` -### setDeclaration +### setDeclaration -setDeclaration\(\): void +setDeclaration(): void Sets a declaration. -- Example +**Example** - ``` - var thatSer = new xml.XmlSerializer(bufView); - thatSer.setDeclaration() // => ; - ``` +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setDeclaration() // => ; +``` -### startElement +### startElement -startElement\(name: string\): void +startElement(name: string): void Writes the start tag based on the given element name. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

name

-

string

-

Yes

-

Name of the element.

-
- - -- Example - - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.startElement("notel"); - thatSer.endElement();// => ''; - ``` - - -### endElement - -endElement\(\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| name | string | Yes| Name of the element.| + +**Example** + +``` +var arrayBuffer = new ArrayBuffer(1024); +var thatSer = new xml.XmlSerializer(arrayBuffer); +thatSer.startElement("notel"); +thatSer.endElement();// => ''; +``` + + +### endElement + +endElement(): void Writes the end tag of the element. -- Example +**Example** - ``` - var thatSer = new xml.XmlSerializer(bufView); - thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); - thatSer.startElement("table"); - thatSer.setAttributes("importance", "high"); - thatSer.setText("Happy"); - endElement(); // => Happy - ``` +``` +var thatSer = new xml.XmlSerializer(bufView); +thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); +thatSer.startElement("table"); +thatSer.setAttributes("importance", "high"); +thatSer.setText("Happy"); +endElement(); // => Happy +``` -### setNamespace +### setNamespace -setNamespace\(prefix: string, namespace: string\): void +setNamespace(prefix: string, namespace: string): void Sets the namespace for an element tag. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

prefix

-

string

-

Yes

-

Prefix of the element and its child elements.

-

namespace

-

string

-

Yes

-

Namespace to set.

-
- - -- Example - - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.setDeclaration(); - thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); - thatSer.startElement("note"); - thatSer.endElement();// = >'\r\n'; - ``` - - -### setComment - -setComment\(text: string\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| prefix | string | Yes| Prefix of the element and its child elements.| +| namespace | string | Yes| Namespace to set.| + +**Example** + +``` +var arrayBuffer = new ArrayBuffer(1024); +var thatSer = new xml.XmlSerializer(arrayBuffer); +thatSer.setDeclaration(); +thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); +thatSer.startElement("note"); +thatSer.endElement();// = >'\r\n'; +``` + +### setComment + +setComment(text: string): void Sets the comment. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

text

-

string

-

Yes

-

Comment to set.

-
- - -- Example - - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.startElement("note"); - thatSer.setComment("Hi!"); - thatSer.endElement(); // => '\r\n \r\n'; - ``` - - -### setCDATA - -setCDATA\(text: string\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| text | string | Yes| Comment to set.| + +**Example** + +``` +var arrayBuffer = new ArrayBuffer(1024); +var thatSer = new xml.XmlSerializer(arrayBuffer); +thatSer.startElement("note"); +thatSer.setComment("Hi!"); +thatSer.endElement(); // => '\r\n \r\n'; +``` + + +### setCDATA + +setCDATA(text: string): void Sets CDATA attributes. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

text

-

string

-

Yes

-

CDATA attribute to set.

-
- - -- Example - - ``` - var arrayBuffer = new ArrayBuffer(1028); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.setCDATA('root SYSTEM') // => ''; - ``` - - -### setText - -setText\(text: string\): void - -Sets **Text**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

text

-

string

-

Yes

-

Content of the Text to set.

-
- - -- Example - - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.startElement("note"); - thatSer.setAttributes("importance", "high"); - thatSer.setText("Happy1"); - thatSer.endElement(); // => 'Happy1'; - ``` - - -### setDocType - -setDocType\(text: string\): void - -Sets **DocType**. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

text

-

string

-

Yes

-

Content of DocType to set.

-
- - -- Example - - ``` - var arrayBuffer = new ArrayBuffer(1024); - var thatSer = new xml.XmlSerializer(arrayBuffer); - thatSer.setDocType('root SYSTEM'); // => ''; - ``` - - -## XmlPullParser - -### XmlPullParser - -constructor\(buffer: ArrayBuffer | DataView, encoding?: string\) - -Creates and returns an **XmlPullParser** object. The **XmlPullParser** object passes two parameters. The first parameter is the memory of the **ArrayBuffer** or **DataView** type, and the second parameter is the file format \(UTF-8 by default\). - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

buffer

-

ArrayBuffer | DataView

-

Yes

-

ArrayBuffer or DataView that contains XML text information.

-

encoding

-

string

-

No

-

Encoding format. Only UTF-8 is supported.

-
- - -- Example - - ``` - var strXml = - '' + - '' + - ' Happy' + - ' Work' + - ' Play' + - ''; - var arrayBuffer = new ArrayBuffer(strXml.length*2); - var bufView = new Uint8Array(arrayBuffer); - var strLen = strXml.length; - for (var i = 0; i < strLen; ++i) { - bufView[i] = strXml.charCodeAt(i);// Set the ArrayBuffer mode. - } - var that = new xml.XmlPullParser(arrayBuffer); - ``` - - -### parse - -parse\(option: ParseOptions\): void +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| text | string | Yes| CDATA attribute to set.| + +**Example** + +``` +var arrayBuffer = new ArrayBuffer(1028); +var thatSer = new xml.XmlSerializer(arrayBuffer); +thatSer.setCDATA('root SYSTEM') // => ''; +``` + + +### setText + +setText(text: string): void + +Sets **Text**. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| text | string | Yes| Content of the **Text** to set.| + +**Example** + +``` +var arrayBuffer = new ArrayBuffer(1024); +var thatSer = new xml.XmlSerializer(arrayBuffer); +thatSer.startElement("note"); +thatSer.setAttributes("importance", "high"); +thatSer.setText("Happy1"); +thatSer.endElement(); // => 'Happy1'; +``` + + +### setDocType + +setDocType(text: string): void + +Sets **DocType**. + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| text | string | Yes| Content of **DocType** to set.| + +**Example** + +``` +var arrayBuffer = new ArrayBuffer(1024); +var thatSer = new xml.XmlSerializer(arrayBuffer); +thatSer.setDocType('root SYSTEM'); // => ''; +``` + + +## XmlPullParser + + +### XmlPullParser + +constructor(buffer: ArrayBuffer | DataView, encoding?: string) + +Creates and returns an **XmlPullParser** object. The **XmlPullParser** object passes two parameters. The first parameter is the memory of the **ArrayBuffer** or **DataView** type, and the second parameter is the file format (UTF-8 by default). + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| buffer | ArrayBuffer \| DataView | Yes| **ArrayBuffer** or **DataView** that contains XML text information.| +| encoding | string | No| Encoding format. Only UTF-8 is supported.| + +**Example** + +``` +var strXml = + '' + + '' + + ' Happy' + + ' Work' + + ' Play' + + ''; +var arrayBuffer = new ArrayBuffer(strXml.length*2); +var bufView = new Uint8Array(arrayBuffer); +var strLen = strXml.length; +for (var i = 0; i < strLen; ++i) { + bufView[i] = strXml.charCodeAt(i);// Set the ArrayBuffer mode. +} +var that = new xml.XmlPullParser(arrayBuffer); +``` + + +### parse + +parse(option: ParseOptions): void Parses XML information. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

option

-

ParseOptions

-

Yes

-

Options for controlling and obtaining the parsed information.

-
- - -- Example - - ``` - var strXml = - '' + - '' + - ' Happy' + - ' Work' + - ' Play' + - ''; - var arrayBuffer = new ArrayBuffer(strXml.length*2); - var bufView = new Uint8Array(arrayBuffer); - var strLen = strXml.length; - for (var i = 0; i < strLen; ++i) { - bufView[i] = strXml.charCodeAt(i); - } - var that = new xml.XmlPullParser(arrayBuffer); - var arrTag = {}; - arrTag[0] = '132'; - var i = 1; - function func(key, value){ - arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); - i++; - return true; - } - var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} - that.parse(options); - ``` - - -## ParseOptions +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| option | [ParseOptions](#parseoptions) | Yes| Options for controlling and obtaining the parsed information.| + +**Example** + +``` +var strXml = + '' + + '' + + ' Happy' + + ' Work' + + ' Play' + + ''; +var arrayBuffer = new ArrayBuffer(strXml.length*2); +var bufView = new Uint8Array(arrayBuffer); +var strLen = strXml.length; +for (var i = 0; i < strLen; ++i) { + bufView[i] = strXml.charCodeAt(i); +} +var that = new xml.XmlPullParser(arrayBuffer); +var arrTag = {}; +arrTag[0] = '132'; +var i = 1; +function func(key, value){ + arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); + i++; + return true; +} +var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} +that.parse(options); +``` + + +## ParseOptions Defines the XML parsing options. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

supportDoctype

-

boolean

-

No

-

Whether to ignore Doctype. The default value is false.

-

ignoreNameSpace

-

boolean

-

No

-

Whether to ignore Namespace. The default value is false.

-

tagValueCallbackFunction

-

(name: string, value: string)=> boolean

-

No

-

Callback used to return tagValue.

-

attributeValueCallbackFunction

-

(name: string, value: string)=> boolean

-

No

-

Callback used to return attributeValue.

-

tokenValueCallbackFunction

-

(eventType: EventType, value: ParseInfo)=> boolean

-

No

-

Callback used to return tokenValue.

-
- -## ParseInfo +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| supportDoctype | boolean | No| Whether to ignore **Doctype**. The default value is **false**.| +| ignoreNameSpace | boolean | No| Whether to ignore **Namespace**. The default value is **false**.| +| tagValueCallbackFunction | (name: string, value: string)=> boolean | No| Callback used to return **tagValue**.| +| attributeValueCallbackFunction | (name: string, value: string)=> boolean | No| Callback used to return **attributeValue**.| +| tokenValueCallbackFunction | (eventType: [EventType](#eventtype), value: [ParseInfo](#parseinfo))=> boolean | No| Callback used to return **tokenValue**.| + + +## ParseInfo Provides methods to manage the parsed XML information. -### getColumnNumber -getColumnNumber\(\): number +### getColumnNumber + +getColumnNumber(): number Obtains the column line number, which starts from 1. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

number

-

Column number obtained.

-
+| Type| Description| +| -------- | -------- | +| number | Column number obtained.| -### getDepth +### getDepth -getDepth\(\): number +getDepth(): number Obtains the depth of this element. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

number

-

Depth obtained.

-
+| Type| Description| +| -------- | -------- | +| number | Depth obtained.| -### getLineNumber +### getLineNumber -getLineNumber\(\): number +getLineNumber(): number Obtains the current line number, starting from 1. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

number

-

Line number obtained.

-
+| Type| Description| +| -------- | -------- | +| number | Line number obtained.| -### getName +### getName -getName\(\): string +getName(): string Obtains the name of this element. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

string

-

Element name obtained.

-
+| Type| Description| +| -------- | -------- | +| string | Element name obtained.| -### getNamespace +### getNamespace -getNamespace\(\): string +getNamespace(): string Obtains the namespace of this element. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

string

-

Namespace obtained.

-
+| Type| Description| +| -------- | -------- | +| string | Namespace obtained.| -### getPrefix +### getPrefix -getPrefix\(\): string +getPrefix(): string Obtains the prefix of this element. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

string

-

Element prefix obtained.

-
+| Type| Description| +| -------- | -------- | +| string | Element prefix obtained.| -### getText +### getText -getText\(\): string +getText(): string Obtains the text of the current event. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

string

-

Text content obtained.

-
+| Type| Description| +| -------- | -------- | +| string | Text content obtained.| -### isEmptyElementTag +### isEmptyElementTag -isEmptyElementTag\(\): boolean +isEmptyElementTag(): boolean Checks whether the current element is empty. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the element is empty; returns false otherwise.

-
+| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the element is empty; returns **false** otherwise.| -### isWhitespace +### isWhitespace -isWhitespace\(\): boolean +isWhitespace(): boolean Checks whether the current text event contains only whitespace characters. -- Return values +**Return value** - - - - - - - - - -

Type

-

Description

-

boolean

-

Returns true if the text event contains only whitespace characters; returns false otherwise.

-
+| Type| Description| +| -------- | -------- | +| boolean | Returns **true** if the text event contains only whitespace characters; returns **false** otherwise.| -### getAttributeCount +### getAttributeCount -getAttributeCount\(\): number +getAttributeCount(): number Obtains the number of attributes for the current start tag. -- Return values +**Return value** +| Type| Description| +| -------- | -------- | +| number | Number of attributes obtained.| - - - - - - - - - -

Type

-

Description

-

number

-

Number of attributes obtained.

-
- -## EventType +## EventType Enumerates the events. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Value

-

Description

-

START_DOCUMENT

-

0

-

Indicates a start document event.

-

END_DOCUMENT

-

1

-

Indicates an end document event.

-

START_TAG

-

2

-

Indicates a start tag event.

-

END_TAG

-

3

-

Indicates an end tag event.

-

TEXT

-

4

-

Indicates a text event.

-

CDSECT

-

5

-

Indicates a CDATA section event.

-

COMMENT

-

6

-

Indicates an XML comment event.

-

DOCDECL

-

7

-

Indicates an XML document type declaration event.

-

INSTRUCTION

-

8

-

Indicates an XML processing instruction event.

-

ENTITY_REFERENCE

-

9

-

Indicates an entity reference event.

-

WHITESPACE

-

10

-

Indicates a whitespace character event.

-
- +| Name| Value| Description| +| -------- | -------- | -------- | +| START_DOCUMENT | 0 | Indicates a start document event.| +| END_DOCUMENT | 1 | Indicates an end document event.| +| START_TAG | 2 | Indicates a start tag event.| +| END_TAG | 3 | Indicates an end tag event.| +| TEXT | 4 | Indicates a text event.| +| CDSECT | 5 | Indicates a CDATA section event.| +| COMMENT | 6 | Indicates an XML comment event.| +| DOCDECL | 7 | Indicates an XML document type declaration event.| +| INSTRUCTION | 8 | Indicates an XML processing instruction event.| +| ENTITY_REFERENCE | 9 | Indicates an entity reference event.| +| WHITESPACE | 10 | Indicates a whitespace character event.|