161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file Defines the utils for ArkTS 1861847f8eSopenharmony_ci * @kit ArkTS 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ciimport lang from './@arkts.lang'; 2261847f8eSopenharmony_ci 2361847f8eSopenharmony_ci/** 2461847f8eSopenharmony_ci * @namespace utils 2561847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 2661847f8eSopenharmony_ci * @atomicservice 2761847f8eSopenharmony_ci * @since 12 2861847f8eSopenharmony_ci */ 2961847f8eSopenharmony_cideclare namespace utils { 3061847f8eSopenharmony_ci /** 3161847f8eSopenharmony_ci * Asynchronous lock. 3261847f8eSopenharmony_ci * 3361847f8eSopenharmony_ci * @namespace locks 3461847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 3561847f8eSopenharmony_ci * @atomicservice 3661847f8eSopenharmony_ci * @since 12 3761847f8eSopenharmony_ci */ 3861847f8eSopenharmony_ci namespace locks { 3961847f8eSopenharmony_ci /** 4061847f8eSopenharmony_ci * Type of callback for asyncLock operation. 4161847f8eSopenharmony_ci * 4261847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 4361847f8eSopenharmony_ci * @atomicservice 4461847f8eSopenharmony_ci * @since 12 4561847f8eSopenharmony_ci */ 4661847f8eSopenharmony_ci type AsyncLockCallback<T> = () => T | Promise<T>; 4761847f8eSopenharmony_ci 4861847f8eSopenharmony_ci /** 4961847f8eSopenharmony_ci * Class to execute an asynchronous operation under lock. 5061847f8eSopenharmony_ci * 5161847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 5261847f8eSopenharmony_ci * @atomicservice 5361847f8eSopenharmony_ci * @since 12 5461847f8eSopenharmony_ci */ 5561847f8eSopenharmony_ci @Sendable 5661847f8eSopenharmony_ci class AsyncLock { 5761847f8eSopenharmony_ci /** 5861847f8eSopenharmony_ci * Default constructor. 5961847f8eSopenharmony_ci * 6061847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 6161847f8eSopenharmony_ci * @atomicservice 6261847f8eSopenharmony_ci * @since 12 6361847f8eSopenharmony_ci */ 6461847f8eSopenharmony_ci constructor(); 6561847f8eSopenharmony_ci /** 6661847f8eSopenharmony_ci * Find or create an instance of AsyncLock using the specified name. 6761847f8eSopenharmony_ci * 6861847f8eSopenharmony_ci * @param { string } name - name of the lock to find or create. 6961847f8eSopenharmony_ci * @returns { AsyncLock } Returns an instance of AsyncLock. 7061847f8eSopenharmony_ci * @static 7161847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 7261847f8eSopenharmony_ci * @atomicservice 7361847f8eSopenharmony_ci * @since 12 7461847f8eSopenharmony_ci */ 7561847f8eSopenharmony_ci static request(name: string): AsyncLock; 7661847f8eSopenharmony_ci 7761847f8eSopenharmony_ci /** 7861847f8eSopenharmony_ci * Query information about the specified lock. 7961847f8eSopenharmony_ci * 8061847f8eSopenharmony_ci * @param { string } name - name of the lock. 8161847f8eSopenharmony_ci * @returns { AsyncLockState } Returns an instance of AsyncLockState. 8261847f8eSopenharmony_ci * @throws { BusinessError } 401 - The input parameters are invalid. 8361847f8eSopenharmony_ci * @throws { BusinessError } 10200030 - The lock does not exist. 8461847f8eSopenharmony_ci * @static 8561847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 8661847f8eSopenharmony_ci * @atomicservice 8761847f8eSopenharmony_ci * @since 12 8861847f8eSopenharmony_ci */ 8961847f8eSopenharmony_ci static query(name: string): AsyncLockState; 9061847f8eSopenharmony_ci 9161847f8eSopenharmony_ci /** 9261847f8eSopenharmony_ci * Query information about all locks. 9361847f8eSopenharmony_ci * 9461847f8eSopenharmony_ci * @returns { AsyncLockState[] } Returns an array of AsyncLockState. 9561847f8eSopenharmony_ci * @static 9661847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 9761847f8eSopenharmony_ci * @atomicservice 9861847f8eSopenharmony_ci * @since 12 9961847f8eSopenharmony_ci */ 10061847f8eSopenharmony_ci static queryAll(): AsyncLockState[]; 10161847f8eSopenharmony_ci 10261847f8eSopenharmony_ci /** 10361847f8eSopenharmony_ci * Perform an operation with the acquired lock exclusively. 10461847f8eSopenharmony_ci * The method acquires the lock first, then calls the callback, and then releases the lock. 10561847f8eSopenharmony_ci * The callback is called asynchronously in the same thread where lockAsync was called. 10661847f8eSopenharmony_ci * 10761847f8eSopenharmony_ci * @param { AsyncLockCallback<T> } callback - function to call when the lock gets acquired. 10861847f8eSopenharmony_ci * @returns { Promise<T> } Promise that will be resolved after the callback gets executed. 10961847f8eSopenharmony_ci * @throws { BusinessError } 401 - The input parameters are invalid. 11061847f8eSopenharmony_ci * @throws { BusinessError } 10200030 - The lock does not exist. 11161847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 11261847f8eSopenharmony_ci * @atomicservice 11361847f8eSopenharmony_ci * @since 12 11461847f8eSopenharmony_ci */ 11561847f8eSopenharmony_ci lockAsync<T>(callback: AsyncLockCallback<T>): Promise<T>; 11661847f8eSopenharmony_ci 11761847f8eSopenharmony_ci /** 11861847f8eSopenharmony_ci * Perform an operation with the acquired lock. 11961847f8eSopenharmony_ci * The method acquires the lock first, then calls the callback, and then releases the lock. 12061847f8eSopenharmony_ci * The callback is called asynchronously in the same thread where lockAsync was called. 12161847f8eSopenharmony_ci * 12261847f8eSopenharmony_ci * @param { AsyncLockCallback<T> } callback - function to call when the lock gets acquired. 12361847f8eSopenharmony_ci * @param { AsyncLockMode } mode - mode of the lock operation. 12461847f8eSopenharmony_ci * @returns { Promise<T> } Promise that will be resolved after the callback gets executed or rejected. 12561847f8eSopenharmony_ci * @throws { BusinessError } 401 - The input parameters are invalid. 12661847f8eSopenharmony_ci * @throws { BusinessError } 10200030 - The lock does not exist. 12761847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 12861847f8eSopenharmony_ci * @atomicservice 12961847f8eSopenharmony_ci * @since 12 13061847f8eSopenharmony_ci */ 13161847f8eSopenharmony_ci lockAsync<T>(callback: AsyncLockCallback<T>, mode: AsyncLockMode): Promise<T>; 13261847f8eSopenharmony_ci 13361847f8eSopenharmony_ci /** 13461847f8eSopenharmony_ci * Perform an operation with the acquired lock. 13561847f8eSopenharmony_ci * The method acquires the lock first, then calls the callback, and then releases the lock. 13661847f8eSopenharmony_ci * The callback is called asynchronously in the same thread where lockAsync was called. 13761847f8eSopenharmony_ci * An optional timeout value can be provided in {@link AsyncLockOptions}. In this case, lockAsync will reject the 13861847f8eSopenharmony_ci * resulting promise with a BusinessError instance if the lock is not acquired before timeout exceeds. 13961847f8eSopenharmony_ci * The error message, in this case, will contain the held and waited locks information and possible deadlock 14061847f8eSopenharmony_ci * warnings. 14161847f8eSopenharmony_ci * 14261847f8eSopenharmony_ci * @param { AsyncLockCallback<T> } callback - function to call when the lock gets acquired. 14361847f8eSopenharmony_ci * @param { AsyncLockMode } mode - mode of the lock operation. 14461847f8eSopenharmony_ci * @param { AsyncLockOptions<U> } options - lock operation options. 14561847f8eSopenharmony_ci * @returns { Promise<T | U> } Promise that will be resolved after the callback gets executed or rejected in case 14661847f8eSopenharmony_ci * timeout exceeded. 14761847f8eSopenharmony_ci * @throws { BusinessError } 401 - The input parameters are invalid. 14861847f8eSopenharmony_ci * @throws { BusinessError } 10200030 - The lock does not exist. 14961847f8eSopenharmony_ci * @throws { BusinessError } 10200031 - Timeout exceeded. 15061847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 15161847f8eSopenharmony_ci * @atomicservice 15261847f8eSopenharmony_ci * @since 12 15361847f8eSopenharmony_ci */ 15461847f8eSopenharmony_ci lockAsync<T, U>(callback: AsyncLockCallback<T>, mode: AsyncLockMode, 15561847f8eSopenharmony_ci options: AsyncLockOptions<U>): Promise<T | U>; 15661847f8eSopenharmony_ci 15761847f8eSopenharmony_ci /** 15861847f8eSopenharmony_ci * Name of the lock. 15961847f8eSopenharmony_ci * 16061847f8eSopenharmony_ci * @type { string } 16161847f8eSopenharmony_ci * @readonly 16261847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 16361847f8eSopenharmony_ci * @atomicservice 16461847f8eSopenharmony_ci * @since 12 16561847f8eSopenharmony_ci */ 16661847f8eSopenharmony_ci readonly name: string; 16761847f8eSopenharmony_ci } 16861847f8eSopenharmony_ci 16961847f8eSopenharmony_ci /** 17061847f8eSopenharmony_ci * Mode of lock operations. 17161847f8eSopenharmony_ci * 17261847f8eSopenharmony_ci * @enum { number } AsyncLockMode 17361847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 17461847f8eSopenharmony_ci * @atomicservice 17561847f8eSopenharmony_ci * @since 12 17661847f8eSopenharmony_ci */ 17761847f8eSopenharmony_ci enum AsyncLockMode { 17861847f8eSopenharmony_ci /** 17961847f8eSopenharmony_ci * Shared lock operation. 18061847f8eSopenharmony_ci * The operation could reenter if this mode is specified. 18161847f8eSopenharmony_ci * 18261847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 18361847f8eSopenharmony_ci * @atomicservice 18461847f8eSopenharmony_ci * @since 12 18561847f8eSopenharmony_ci */ 18661847f8eSopenharmony_ci SHARED = 1, 18761847f8eSopenharmony_ci /** 18861847f8eSopenharmony_ci * Exclusive lock operation. 18961847f8eSopenharmony_ci * If this mode is specified, the operation is executed only when the lock is acquired exclusively. 19061847f8eSopenharmony_ci * 19161847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 19261847f8eSopenharmony_ci * @atomicservice 19361847f8eSopenharmony_ci * @since 12 19461847f8eSopenharmony_ci */ 19561847f8eSopenharmony_ci EXCLUSIVE = 2, 19661847f8eSopenharmony_ci } 19761847f8eSopenharmony_ci 19861847f8eSopenharmony_ci /** 19961847f8eSopenharmony_ci * Lock operation's options 20061847f8eSopenharmony_ci * 20161847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 20261847f8eSopenharmony_ci * @atomicservice 20361847f8eSopenharmony_ci * @since 12 20461847f8eSopenharmony_ci */ 20561847f8eSopenharmony_ci class AsyncLockOptions<T> { 20661847f8eSopenharmony_ci /** 20761847f8eSopenharmony_ci * Default constructor. 20861847f8eSopenharmony_ci * 20961847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 21061847f8eSopenharmony_ci * @atomicservice 21161847f8eSopenharmony_ci * @since 12 21261847f8eSopenharmony_ci */ 21361847f8eSopenharmony_ci constructor(); 21461847f8eSopenharmony_ci 21561847f8eSopenharmony_ci /** 21661847f8eSopenharmony_ci * If the value is true and lockAsync cannot acquire the lock immediately, the operation is canceled. 21761847f8eSopenharmony_ci * 21861847f8eSopenharmony_ci * @type { boolean } 21961847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 22061847f8eSopenharmony_ci * @atomicservice 22161847f8eSopenharmony_ci * @since 12 22261847f8eSopenharmony_ci */ 22361847f8eSopenharmony_ci isAvailable: boolean; 22461847f8eSopenharmony_ci /** 22561847f8eSopenharmony_ci * The object used to abort the async operation. If signal.aborted is true, the callback will not be called. 22661847f8eSopenharmony_ci * 22761847f8eSopenharmony_ci * @type { AbortSignal<T> | null } 22861847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 22961847f8eSopenharmony_ci * @atomicservice 23061847f8eSopenharmony_ci * @since 12 23161847f8eSopenharmony_ci */ 23261847f8eSopenharmony_ci signal: AbortSignal<T> | null; 23361847f8eSopenharmony_ci /** 23461847f8eSopenharmony_ci * Lock operation timeout in milliseconds. If it is greater than zero, lockAsync will reject the resulting promise 23561847f8eSopenharmony_ci * when the timeout is exceeded. 23661847f8eSopenharmony_ci * 23761847f8eSopenharmony_ci * @type { number } 23861847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 23961847f8eSopenharmony_ci * @atomicservice 24061847f8eSopenharmony_ci * @since 12 24161847f8eSopenharmony_ci */ 24261847f8eSopenharmony_ci timeout: number; 24361847f8eSopenharmony_ci } 24461847f8eSopenharmony_ci 24561847f8eSopenharmony_ci /** 24661847f8eSopenharmony_ci * Information about all lock operations on the AsyncLock instance. 24761847f8eSopenharmony_ci * 24861847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 24961847f8eSopenharmony_ci * @atomicservice 25061847f8eSopenharmony_ci * @since 12 25161847f8eSopenharmony_ci */ 25261847f8eSopenharmony_ci class AsyncLockState { 25361847f8eSopenharmony_ci /** 25461847f8eSopenharmony_ci * Held locks information. 25561847f8eSopenharmony_ci * 25661847f8eSopenharmony_ci * @type { AsyncLockInfo[] } 25761847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 25861847f8eSopenharmony_ci * @atomicservice 25961847f8eSopenharmony_ci * @since 12 26061847f8eSopenharmony_ci */ 26161847f8eSopenharmony_ci held: AsyncLockInfo[]; 26261847f8eSopenharmony_ci /** 26361847f8eSopenharmony_ci * Pending locks information. 26461847f8eSopenharmony_ci * 26561847f8eSopenharmony_ci * @type { AsyncLockInfo[] } 26661847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 26761847f8eSopenharmony_ci * @atomicservice 26861847f8eSopenharmony_ci * @since 12 26961847f8eSopenharmony_ci */ 27061847f8eSopenharmony_ci pending: AsyncLockInfo[]; 27161847f8eSopenharmony_ci } 27261847f8eSopenharmony_ci 27361847f8eSopenharmony_ci /** 27461847f8eSopenharmony_ci * Information about a lock. 27561847f8eSopenharmony_ci * 27661847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 27761847f8eSopenharmony_ci * @atomicservice 27861847f8eSopenharmony_ci * @since 12 27961847f8eSopenharmony_ci */ 28061847f8eSopenharmony_ci class AsyncLockInfo { 28161847f8eSopenharmony_ci /** 28261847f8eSopenharmony_ci * Name of the lock. 28361847f8eSopenharmony_ci * 28461847f8eSopenharmony_ci * @type { string } 28561847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 28661847f8eSopenharmony_ci * @atomicservice 28761847f8eSopenharmony_ci * @since 12 28861847f8eSopenharmony_ci */ 28961847f8eSopenharmony_ci name: string; 29061847f8eSopenharmony_ci /** 29161847f8eSopenharmony_ci * Lock operation mode. 29261847f8eSopenharmony_ci * 29361847f8eSopenharmony_ci * @type { AsyncLockMode } 29461847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 29561847f8eSopenharmony_ci * @atomicservice 29661847f8eSopenharmony_ci * @since 12 29761847f8eSopenharmony_ci */ 29861847f8eSopenharmony_ci mode: AsyncLockMode; 29961847f8eSopenharmony_ci /** 30061847f8eSopenharmony_ci * lockAsync caller's execution context identifier. 30161847f8eSopenharmony_ci * 30261847f8eSopenharmony_ci * @type { number } 30361847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 30461847f8eSopenharmony_ci * @atomicservice 30561847f8eSopenharmony_ci * @since 12 30661847f8eSopenharmony_ci */ 30761847f8eSopenharmony_ci contextId: number; 30861847f8eSopenharmony_ci } 30961847f8eSopenharmony_ci 31061847f8eSopenharmony_ci /** 31161847f8eSopenharmony_ci * Object used to abort an async operation. 31261847f8eSopenharmony_ci * An instance of this class must be accessed in the same thread where the instance is created. 31361847f8eSopenharmony_ci * Access to fields of this class from another thread is undefined behaviour. 31461847f8eSopenharmony_ci * 31561847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 31661847f8eSopenharmony_ci * @atomicservice 31761847f8eSopenharmony_ci * @since 12 31861847f8eSopenharmony_ci */ 31961847f8eSopenharmony_ci class AbortSignal<T> { 32061847f8eSopenharmony_ci /** 32161847f8eSopenharmony_ci * Set to true to abort an operation. 32261847f8eSopenharmony_ci * 32361847f8eSopenharmony_ci * @type { boolean } 32461847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 32561847f8eSopenharmony_ci * @atomicservice 32661847f8eSopenharmony_ci * @since 12 32761847f8eSopenharmony_ci */ 32861847f8eSopenharmony_ci aborted: boolean; 32961847f8eSopenharmony_ci 33061847f8eSopenharmony_ci /** 33161847f8eSopenharmony_ci * Reason for the abort. This value will be used to reject the promise returned from lockAsync. 33261847f8eSopenharmony_ci * 33361847f8eSopenharmony_ci * @type { T } 33461847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 33561847f8eSopenharmony_ci * @atomicservice 33661847f8eSopenharmony_ci * @since 12 33761847f8eSopenharmony_ci */ 33861847f8eSopenharmony_ci reason: T 33961847f8eSopenharmony_ci } 34061847f8eSopenharmony_ci } 34161847f8eSopenharmony_ci /** 34261847f8eSopenharmony_ci * ArkTS JSON utils. 34361847f8eSopenharmony_ci * 34461847f8eSopenharmony_ci * @namespace ASON 34561847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 34661847f8eSopenharmony_ci * @atomicservice 34761847f8eSopenharmony_ci * @since 12 34861847f8eSopenharmony_ci */ 34961847f8eSopenharmony_ci namespace ASON { 35061847f8eSopenharmony_ci /** 35161847f8eSopenharmony_ci * Redefines ISendable for convenience. 35261847f8eSopenharmony_ci * 35361847f8eSopenharmony_ci * @typedef { lang.ISendable } ISendable 35461847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 35561847f8eSopenharmony_ci * @atomicservice 35661847f8eSopenharmony_ci * @since 12 35761847f8eSopenharmony_ci */ 35861847f8eSopenharmony_ci type ISendable = lang.ISendable; 35961847f8eSopenharmony_ci /** 36061847f8eSopenharmony_ci * The type of conversion result function. 36161847f8eSopenharmony_ci * 36261847f8eSopenharmony_ci * @typedef { function } Transformer 36361847f8eSopenharmony_ci * @param { ISendable } this - The ISendable to which the parsed key value pair belongs. 36461847f8eSopenharmony_ci * @param { string } key - Attribute name. 36561847f8eSopenharmony_ci * @param { ISendable | undefined | null } value - The value of the parsed key value pair. 36661847f8eSopenharmony_ci * @returns { ISendable | undefined | null } Return the modified ISendable or undefined or null. 36761847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 36861847f8eSopenharmony_ci * @atomicservice 36961847f8eSopenharmony_ci * @since 12 37061847f8eSopenharmony_ci */ 37161847f8eSopenharmony_ci type Transformer = (this: ISendable, key: string, 37261847f8eSopenharmony_ci value: ISendable | undefined | null) => ISendable | undefined | null 37361847f8eSopenharmony_ci /** 37461847f8eSopenharmony_ci * Converts a JavaScript Object Notation (JSON) string into an ArkTS Value. 37561847f8eSopenharmony_ci * 37661847f8eSopenharmony_ci * @param { string } text - A valid JSON string. 37761847f8eSopenharmony_ci * @param { Transformer } [reviver] - A function that transforms the results. 37861847f8eSopenharmony_ci * @param {ParseOptions} [options] - The config of parse. 37961847f8eSopenharmony_ci * @returns { ISendable | null } Return an ArkTS Value. 38061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Invalid JSON string. 38161847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 38261847f8eSopenharmony_ci * @atomicservice 38361847f8eSopenharmony_ci * @since 12 38461847f8eSopenharmony_ci */ 38561847f8eSopenharmony_ci function parse(text: string, reviver?: Transformer, options?: ParseOptions): ISendable | null; 38661847f8eSopenharmony_ci /** 38761847f8eSopenharmony_ci * Converts an ArkTS value to a JavaScript Object Notation (JSON) string. 38861847f8eSopenharmony_ci * 38961847f8eSopenharmony_ci * @param { ISendable | null | undefined } value - The value to stringify. 39061847f8eSopenharmony_ci * @returns { string } The JSON string representation of the value. 39161847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Invalid ArkTS value. 39261847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 39361847f8eSopenharmony_ci * @atomicservice 39461847f8eSopenharmony_ci * @since 12 39561847f8eSopenharmony_ci */ 39661847f8eSopenharmony_ci function stringify(value: ISendable | null | undefined): string; 39761847f8eSopenharmony_ci 39861847f8eSopenharmony_ci /** 39961847f8eSopenharmony_ci * Enum defining modes for handling bigint. 40061847f8eSopenharmony_ci * 40161847f8eSopenharmony_ci * @enum { number } BigIntMode 40261847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 40361847f8eSopenharmony_ci * @atomicservice 40461847f8eSopenharmony_ci * @since 12 40561847f8eSopenharmony_ci */ 40661847f8eSopenharmony_ci const enum BigIntMode { 40761847f8eSopenharmony_ci /** 40861847f8eSopenharmony_ci * BigInt is not supported. 40961847f8eSopenharmony_ci * 41061847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 41161847f8eSopenharmony_ci * @atomicservice 41261847f8eSopenharmony_ci * @since 12 41361847f8eSopenharmony_ci */ 41461847f8eSopenharmony_ci DEFAULT = 0, 41561847f8eSopenharmony_ci /** 41661847f8eSopenharmony_ci * Parse as BigInt when number less than -(2^53 – 1) or greater than (2^53 – 1). 41761847f8eSopenharmony_ci * 41861847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 41961847f8eSopenharmony_ci * @atomicservice 42061847f8eSopenharmony_ci * @since 12 42161847f8eSopenharmony_ci */ 42261847f8eSopenharmony_ci PARSE_AS_BIGINT = 1, 42361847f8eSopenharmony_ci /** 42461847f8eSopenharmony_ci * All numbers parse as BigInt. 42561847f8eSopenharmony_ci * 42661847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 42761847f8eSopenharmony_ci * @atomicservice 42861847f8eSopenharmony_ci * @since 12 42961847f8eSopenharmony_ci */ 43061847f8eSopenharmony_ci ALWAYS_PARSE_AS_BIGINT = 2, 43161847f8eSopenharmony_ci } 43261847f8eSopenharmony_ci 43361847f8eSopenharmony_ci /** 43461847f8eSopenharmony_ci * The return types for parsing. 43561847f8eSopenharmony_ci * 43661847f8eSopenharmony_ci * @enum { number } ParseReturnType 43761847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 43861847f8eSopenharmony_ci * @atomicservice 43961847f8eSopenharmony_ci * @since 12 44061847f8eSopenharmony_ci */ 44161847f8eSopenharmony_ci const enum ParseReturnType { 44261847f8eSopenharmony_ci /** 44361847f8eSopenharmony_ci * Return type is object. 44461847f8eSopenharmony_ci * 44561847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 44661847f8eSopenharmony_ci * @atomicservice 44761847f8eSopenharmony_ci * @since 12 44861847f8eSopenharmony_ci */ 44961847f8eSopenharmony_ci OBJECT = 0, 45061847f8eSopenharmony_ci /** 45161847f8eSopenharmony_ci * Return type is map. 45261847f8eSopenharmony_ci * 45361847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 45461847f8eSopenharmony_ci * @atomicservice 45561847f8eSopenharmony_ci * @since 13 45661847f8eSopenharmony_ci */ 45761847f8eSopenharmony_ci MAP = 1, 45861847f8eSopenharmony_ci } 45961847f8eSopenharmony_ci /** 46061847f8eSopenharmony_ci * Parse's options 46161847f8eSopenharmony_ci * 46261847f8eSopenharmony_ci * @typedef ParseOptions 46361847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 46461847f8eSopenharmony_ci * @atomicservice 46561847f8eSopenharmony_ci * @since 12 46661847f8eSopenharmony_ci */ 46761847f8eSopenharmony_ci interface ParseOptions { 46861847f8eSopenharmony_ci /** 46961847f8eSopenharmony_ci * Enum defining modes for handling bigint. 47061847f8eSopenharmony_ci * 47161847f8eSopenharmony_ci * @type { BigIntMode } 47261847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 47361847f8eSopenharmony_ci * @atomicservice 47461847f8eSopenharmony_ci * @since 12 47561847f8eSopenharmony_ci */ 47661847f8eSopenharmony_ci bigIntMode: BigIntMode; 47761847f8eSopenharmony_ci /** 47861847f8eSopenharmony_ci * The return types for parsing. 47961847f8eSopenharmony_ci * 48061847f8eSopenharmony_ci * @type { ParseReturnType } 48161847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 48261847f8eSopenharmony_ci * @atomicservice 48361847f8eSopenharmony_ci * @since 12 48461847f8eSopenharmony_ci */ 48561847f8eSopenharmony_ci parseReturnType: ParseReturnType; 48661847f8eSopenharmony_ci } 48761847f8eSopenharmony_ci } 48861847f8eSopenharmony_ci 48961847f8eSopenharmony_ci /** 49061847f8eSopenharmony_ci * Checks whether an ArkTS value is sendable. 49161847f8eSopenharmony_ci * 49261847f8eSopenharmony_ci * @param { Object | null | undefined } value - The value to check. 49361847f8eSopenharmony_ci * @returns { boolean } True if the value is sendable, false otherwise. 49461847f8eSopenharmony_ci * @syscap SystemCapability.Utils.Lang 49561847f8eSopenharmony_ci * @stagemodelonly 49661847f8eSopenharmony_ci * @atomicservice 49761847f8eSopenharmony_ci * @since 12 49861847f8eSopenharmony_ci */ 49961847f8eSopenharmony_ci function isSendable(value: Object | null | undefined): boolean; 50061847f8eSopenharmony_ci} 50161847f8eSopenharmony_ciexport default utils; 502