diff --git a/en/application-dev/reference/apis/js-apis-url.md b/en/application-dev/reference/apis/js-apis-url.md index 384dfa9e330de1793f8a2ebb6515c79e0096615a..bf7b0aca1a140b669759b1df81fff9b41cd26125 100644 --- a/en/application-dev/reference/apis/js-apis-url.md +++ b/en/application-dev/reference/apis/js-apis-url.md @@ -1,934 +1,421 @@ -# URL String Parsing +# URL String Parsing ->![](../../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. +> ![](../../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 Url from '@ohos.url' ``` -## Required Permissions + +## Required Permissions None -## URLSearchParams -### constructor +## URLSearchParams -constructor\(init?: string\[\]\[\] | Record | string | URLSearchParams\) -Creates a **URLSearchParams** instance. +### constructor -- Parameters +constructor(init?: string[][] | Record<string, string> | string | URLSearchParams) - - - - - - - - - - - - - -

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
-
+Creates a **URLSearchParams** instance. -- Example +- 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| - ``` - 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); - ``` +- 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); + ``` -### append +### append -append\(name: string, value: string\): void +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.

-
- -- Example - - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsObject = new URLSearchParams(urlObject.search.slice(1)); - paramsObject.append('fod', 3); - ``` - - -### delete - -delete\(name: string\): void +- 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 + ``` + let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); + let paramsObject = new URLSearchParams(urlObject.search.slice(1)); + paramsObject.append('fod', 3); + ``` + + +### delete + +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.

-
- - -- Example - - ``` - let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); - let paramsobject = new URLSearchParams(urlObject.search.slice(1)); - paramsobject.delete('foo'); - ``` - - -### getAll - -getAll\(name: string\): string\[\] +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | name | string | Yes| Key of the key-value pairs to delete.| + +- Example + ``` + let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); + let paramsobject = new URLSearchParams(urlObject.search.slice(1)); + paramsobject.delete('foo'); + ``` + + +### getAll + +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.

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

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"]. - ``` - - -### entries - -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.

-
- - -- 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 - -forEach\(callbackfn: \(value: string, key: string, searchParams: Object\) =\> void, thisArg?: Object\): void - -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); - }); - ``` - - -### get - -get\(name: string\): string | null +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | name | string | Yes| Key specified to obtain all key-value pairs.| + +- Return values + | 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"]. + ``` + + +### entries + +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.| + +- 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 + +forEach(callbackfn: (value: string, key: string, searchParams: Object) => void, thisArg?: Object): void + +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); + }); + ``` + + +### get + +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.

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

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 - ``` - - -### has - -has\(name: string\): boolean +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | name | string | Yes| Key specified to obtain the 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.| + +- 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 + +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.| + +- 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 -- 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.

-
- -- 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 - -set\(name: string, value: string\): void +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.

-
- - -- 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 - -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 - - ``` - 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 - -keys\(\): IterableIterator +- 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. + ``` + + +### sort + +sort(): void -Obtains an ES6 iterator that contains the keys of all the key-value pairs. -- Return values +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. - - - - - - - - - -

Type

-

Description

-

IterableIterator<string>

-

ES6 iterator that contains the keys of all the key-value pairs.

-
+- 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 + ``` -- 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); - } - ``` +### keys +keys(): IterableIterator<string> -### values -values\(\): IterableIterator +Obtains an ES6 iterator that contains the keys of all the key-value pairs. + + +- Return values + | Type| Description| + | -------- | -------- | + | IterableIterator<string> | ES6 iterator that contains the keys of all the key-value pairs.| + + +- 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); + } + ``` + + +### values + +values(): IterableIterator<string> Obtains an ES6 iterator that contains the values of all the key-value pairs. -- Return values +- Return values + | 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); + } + ``` + + +### [Symbol.iterator] + +[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 values + | Type| Description| + | -------- | -------- | + | IterableIterator<[string, string]> | An ES6 iterator.| + + +- Example + ``` + const paramsObject = new URLSearchParams('fod=bay&edg=bap'); + for (const [name, value] of paramsObject) { + console.log(name, value); + } + ``` + + +### tostring + +toString(): string + + +Obtains search parameters that are serialized as a string and, if necessary, percent-encodes the characters in the string. + + +- Return values + | Type| Description| + | -------- | -------- | + | string | String of serialized search parameters, which is percent-encoded if necessary.| + + +- 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()); + ``` + + +## URL + + +### Attributes + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| hash | string | Yes| Yes| String that contains a harsh mark (#) followed by the fragment identifier of a URL.| +| host | string | Yes| Yes| Host information in a URL.| +| hostname | string | Yes| Yes| Hostname (without the port) in a URL.| +| href | string | Yes| Yes| String that contains the whole URL.| +| origin | string | Yes| No| Read-only string that contains the Unicode serialization of the origin of the represented URL.| +| password | string | Yes| Yes| Password in a URL.| +| pathname | string | Yes| Yes| Path in a URL.| +| port | string | Yes| Yes| Port in a URL.| +| protocol | string | Yes| Yes| Protocol in a URL.| +| search | string | Yes| Yes| Serialized query string in a URL.| +| searchParams | URLsearchParams | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.| +| username | string | Yes| Yes| Username in a URL.| + + +### constructor + +constructor(url: string, base?: string | URL) - - - - - - - - - -

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); - } - ``` - - -### \[Symbol.iterator\] - -\[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 values - - - - - - - - - - -

Type

-

Description

-

IterableIterator<[string, string]>

-

An ES6 iterator.

-
- - -- Example - - ``` - const paramsObject = new URLSearchParams('fod=bay&edg=bap'); - for (const [name, value] of paramsObject) { - console.log(name, value); - } - ``` - - -### tostring - -toString\(\): string - -Returns search parameters that are serialized as a string and, if necessary, percent-encodes the characters in the string. - -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

String of serialized search parameters, which is percent-encoded if necessary.

-
- - -- 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()); - ``` - - -## URL - -### Attributes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

hash

-

string

-

Yes

-

Yes

-

Gets and sets a string that contains a harsh mark (#) followed by the fragment identifier of a URL.

-

host

-

string

-

Yes

-

Yes

-

Gets and sets the host information in a URL.

-

hostname

-

string

-

Yes

-

Yes

-

Gets and sets the hostname (without the port) in a URL.

-

href

-

string

-

Yes

-

Yes

-

Gets and sets a string that contains the whole URL.

-

origin

-

string

-

Yes

-

No

-

Gets a read-only string that contains the Unicode serialization of the origin of the represented URL.

-

password

-

string

-

Yes

-

Yes

-

Gets and sets the password in a URL.

-

pathname

-

string

-

Yes

-

Yes

-

Gets and sets the path in a URL.

-

port

-

string

-

Yes

-

Yes

-

Gets and sets the port in a URL.

-

protocol

-

string

-

Yes

-

Yes

-

Gets and sets the protocol in a URL.

-

search

-

string

-

Yes

-

Yes

-

Gets and sets the serialized query string in a URL.

-

searchParams

-

URLsearchParams

-

Yes

-

No

-

Gets a URLSearchParams object allowing access to the query parameters in a URL.

-

username

-

string

-

Yes

-

Yes

-

Gets and sets the username in a URL.

-
- -### constructor - -constructor\(url: string, base?: string | URL\) Creates a URL. -- 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
-
- - -- 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/ - ``` - - -### tostring - -toString\(\): string -Converts the parsed URL into a string. +- 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| + -- Return values +- 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/ + ``` - - - - - - - - - -

Type

-

Description

-

string

-

Website address in a serialized string.

-
+### tostring -- Example +toString(): string - ``` - const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - url.toString() - ``` +Converts the parsed URL into a string. -### toJSON +- Return values + | Type| Description| + | -------- | -------- | + | string | Website address in a serialized string.| -toJSON\(\): string -Converts the parsed URL into a JSON string. +- Example + ``` + const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); + url.toString() + ``` + -- Return values +### toJSON - - - - - - - - - -

Type

-

Description

-

string

-

Website address in a serialized JSON string.

-
+toJSON(): string -- Example +Converts the parsed URL into a JSON string. + - ``` - const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); - url.toString() - ``` +- Return values + | 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() + ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-Context.md b/zh-cn/application-dev/reference/apis/js-apis-Context.md index 5a166a8f30ea168e0425013abf4698c34b4c6c96..0d5354ff143584d81d9cb26bad6ae725724f36aa 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-Context.md +++ b/zh-cn/application-dev/reference/apis/js-apis-Context.md @@ -108,7 +108,7 @@ context.getOrCreateLocalDir().then((void) => { | 名称 | 读写属性 | 类型 | 必填 | 描述 | | ---------- | -------- | ----------------------------------------------- | ---- | ----------------------------------- | | permission | 只读 | string | 是 | 指定权限的名称 | -| options | 只读 | [PermissionOptions](#PermissionOptions类型说明) | 是 | 进程id | +| options | 只读 | [PermissionOptions](#PermissionOptions类型说明) | 是 | 权限选项 | | callback | 只读 | AsyncCallback\ | 是 | 返回权限验证结果,0有权限,-1无权限 | - 返回值 @@ -132,7 +132,7 @@ context.verifyPermission("com.example.permission",datainfo.uid) - 接口说明 - 验证系统中运行的特定pid和uid是否具有指定的权限(callback形式) + 验证系统中运行的当前pid和uid是否具有指定的权限(callback形式) - 参数描述 @@ -167,13 +167,13 @@ context.verifyPermission("com.example.permission") | 名称 | 读写属性 | 类型 | 必填 | 描述 | | ---------- | -------- | ----------------------------------------------- | ---- | -------------- | | permission | 只读 | string | 是 | 指定权限的名称 | -| options | 只读 | [PermissionOptions](#PermissionOptions类型说明) | 否 | 进程id | +| options | 只读 | [PermissionOptions](#PermissionOptions类型说明) | 否 | 权限选项 | - 返回值 | 类型 | 说明 | | --------------- | ------------------------------------------------------------ | - | Promise | 如果pid和uid具有权限,则使用{@code 0}进行异步回调;否则使用{@code-1}回调。 | + | Promise | 如果pid和uid具有权限,则使用**0**进行异步回调;否则使用**-1**回调。 | - 示例 @@ -503,13 +503,13 @@ context.getProcessName().then((void) => { - 接口说明 - 获取调用当前ability捆绑包名称(callback形式) + 获取调用ability的包名称(callback形式) - 参数描述 | 名称 | 读写属性 | 类型 | 必填 | 描述 | | -------- | -------- | ---------------------- | ---- | ------------------------- | - | callback | 只读 | AsyncCallback\ | 是 | 返回当前ability捆绑包名称 | + | callback | 只读 | AsyncCallback\ | 是 | 返回调用ability的包名称 | - 返回值 @@ -529,7 +529,7 @@ context.getCallingBundle() - 接口说明 - 获取调用当前ability捆绑包名称(Promise形式) + 获取调用ability的包名称(Promise形式) - 参数描述 @@ -539,7 +539,7 @@ context.getCallingBundle() | 类型 | 说明 | | --------------- | ------------------------- | - | Promise | 调用当前ability捆绑包名称 | + | Promise | 调用ability的包名称 |