Skip to main content

tw5-typed / core / IUtilsBoot

Interface: IUtilsBoot

core.IUtilsBoot

Table of contents

Properties

Properties

Crypto

Crypto: typeof Crypto

Defined in

src/utils/index.d.ts:110


PasswordPrompt

PasswordPrompt: typeof PasswordPrompt

Defined in

src/utils/index.d.ts:111


checkVersions

checkVersions: (versionStringA: string, versionStringB: string) => boolean

En

Returns true if the version string A is greater than the version string B. Returns true if the versions are the same

Zh

如果版本字符串 A 大于版本字符串 B,返回 true;如果版本相同,返回 true。

Type declaration

▸ (versionStringA, versionStringB): boolean

Parameters
NameType
versionStringAstring
versionStringBstring
Returns

boolean

En

Returns true if the version string A is greater than the version string B. Returns true if the versions are the same

Zh

如果版本字符串 A 大于版本字符串 B,返回 true;如果版本相同,返回 true。

Defined in

src/utils/index.d.ts:119


compareVersions

compareVersions: (versionStringA: string, versionStringB: string) => -1 | 0 | 1

En

Returns +1 if the version string A is greater than the version string B, 0 if they are the same, and +1 if B is greater than A. Missing or malformed version strings are parsed as 0.0.0

Zh

如果版本字符串 A 大于版本字符串 B,则返回 +1;如果它们相同,则返回 0;如果 B 大于 A,则返回 +1; 缺失或畸形的版本字符串被解析为 0.0.0

Type declaration

▸ (versionStringA, versionStringB): -1 | 0 | 1

Parameters
NameType
versionStringAstring
versionStringBstring
Returns

-1 | 0 | 1

En

Returns +1 if the version string A is greater than the version string B, 0 if they are the same, and +1 if B is greater than A. Missing or malformed version strings are parsed as 0.0.0

Zh

如果版本字符串 A 大于版本字符串 B,则返回 +1;如果它们相同,则返回 0;如果 B 大于 A,则返回 +1; 缺失或畸形的版本字符串被解析为 0.0.0

Defined in

src/utils/index.d.ts:129


decodeURIComponentSafe

decodeURIComponentSafe: (uri: string) => string

En

Convert a URIComponent encoded string to a string safely

Zh

将一个 URIComponent 编码的字符串安全地转换为一个字符串。

Type declaration

▸ (uri): string

Parameters
NameType
uristring
Returns

string

En

Convert a URIComponent encoded string to a string safely

Zh

将一个 URIComponent 编码的字符串安全地转换为一个字符串。

Defined in

src/utils/index.d.ts:140


decodeURISafe

decodeURISafe: (uri: string) => string

En

Convert a URI encoded string to a string safely

Zh

将一个 URI 编码的字符串安全地转换为一个字符串

Type declaration

▸ (uri): string

Parameters
NameType
uristring
Returns

string

En

Convert a URI encoded string to a string safely

Zh

将一个 URI 编码的字符串安全地转换为一个字符串

Defined in

src/utils/index.d.ts:148


deepDefaults

deepDefaults: <O, S>(origin: O, ...sources: [...S[]]) => Spread<O, S>

En

Fill in any null or undefined properties of an object with the properties from a list of source objects. Each property that is an object is called recursively

Zh

用源对象列表中的属性来填充对象的任何空或未定义的属性。每个属于对象的属性都被递归地调用

Type declaration

▸ <O, S>(origin, ...sources): Spread<O, S>

Type parameters
NameType
Oextends object
Sextends object[]
Parameters
NameType
originO
...sources[...S[]]
Returns

Spread<O, S>

En

Fill in any null or undefined properties of an object with the properties from a list of source objects. Each property that is an object is called recursively

Zh

用源对象列表中的属性来填充对象的任何空或未定义的属性。每个属于对象的属性都被递归地调用

Defined in

src/utils/index.d.ts:156


domMaker

domMaker: <K>(tag: K, options: IDomMakerOptions) => K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : HTMLElement

En

Helper for making DOM elements

Zh

产生一个 DOM 元素

Param

tag name

Param

Type declaration

▸ <K>(tag, options): K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : HTMLElement

Type parameters
NameType
Kextends keyof HTMLElementTagNameMap
Parameters
NameTypeDescription
tagKtag name
optionsIDomMakerOptions
Returns

K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : HTMLElement

En

Helper for making DOM elements

Zh

产生一个 DOM 元素

Defined in

src/utils/index.d.ts:171

src/utils/index.d.ts:176


each

each: <T, K>(object: T, callback: (element: T[K], index: K, object: T) => false | void) => void

En

Iterate through all the own properties of an object or array. Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated.

Zh

遍历一个对象或数组的所有自身属性。 callback 被遍历调用 (element, index, object),如果回调返回 false,那么每个循环将被终止。

Param

Param

Example

$tw.utils.each([1, 2, 3], element => console.log(element));
$tw.utils.each({ a: 1, b: 2 }, (value, key) => console.log(key, value));

Type declaration

▸ <T, K>(object, callback): void

Type parameters
NameType
TT
KT extends unknown[] ? number : keyof T
Parameters
NameType
objectT
callback(element: T[K], index: K, object: T) => false | void
Returns

void

En

Iterate through all the own properties of an object or array. Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated.

Zh

遍历一个对象或数组的所有自身属性。 callback 被遍历调用 (element, index, object),如果回调返回 false,那么每个循环将被终止。

Example

$tw.utils.each([1, 2, 3], element => console.log(element));
$tw.utils.each({ a: 1, b: 2 }, (value, key) => console.log(key, value));

Defined in

src/utils/index.d.ts:194


error

error: (error: string | Event | Error) => null

En

Display an error and exit

Zh

打印一个错误,如果在 Node 环境下,会退出进程

Type declaration

▸ (error): null

Parameters
NameType
errorstring | Event | Error
Returns

null

En

Display an error and exit

Zh

打印一个错误,如果在 Node 环境下,会退出进程

Defined in

src/utils/index.d.ts:205


evalGlobal

evalGlobal: (code: string, context: IEvalContent, filename: string) => unknown

En

Run code globally with specified context variables in scope

Zh

在全局范围内运行代码,范围内有指定的上下文变量

Type declaration

▸ (code, context, filename): unknown

Parameters
NameType
codestring
contextIEvalContent
filenamestring
Returns

unknown

En

Run code globally with specified context variables in scope

Zh

在全局范围内运行代码,范围内有指定的上下文变量

Defined in

src/utils/index.d.ts:213


evalSandboxed

evalSandboxed: (code: string, context: IEvalContent, filename: string) => unknown

En

Run code in a sandbox with only the specified context variables in scope

Zh

在沙盒中运行代码,范围内只有指定的上下文变量

Type declaration

▸ (code, context, filename): unknown

Parameters
NameType
codestring
contextIEvalContent
filenamestring
Returns

unknown

En

Run code in a sandbox with only the specified context variables in scope

Zh

在沙盒中运行代码,范围内只有指定的上下文变量

Defined in

src/utils/index.d.ts:225


extend

extend: <O, S>(origin: O, ...sources: [...S[]]) => Spread<O, S>

En

Extend an object with the properties from a list of source objects

Zh

用源对象列表中的属性扩展一个对象

Type declaration

▸ <O, S>(origin, ...sources): Spread<O, S>

Type parameters
NameType
Oextends object
Sextends object[]
Parameters
NameType
originO
...sources[...S[]]
Returns

Spread<O, S>

En

Extend an object with the properties from a list of source objects

Zh

用源对象列表中的属性扩展一个对象

Defined in

src/utils/index.d.ts:237


getFileExtensionInfo

getFileExtensionInfo: (extension: string) => IFileExtensionInfo

En

Given an extension, always access the $tw.config.fileExtensionInfo using a lowercase extension only.

Zh

给定一个扩展名,总是只使用小写的扩展名来访问$tw.config.fileExtensionInfo。

Type declaration

▸ (extension): IFileExtensionInfo

Parameters
NameType
extensionstring
Returns

IFileExtensionInfo

En

Given an extension, always access the $tw.config.fileExtensionInfo using a lowercase extension only.

Zh

给定一个扩展名,总是只使用小写的扩展名来访问$tw.config.fileExtensionInfo。

Defined in

src/utils/index.d.ts:248


getLocationHash

getLocationHash: () => string

En

Get the browser location.hash. We don't use location.hash because of the way that Firefox auto-urldecodes it (see http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash)

Zh

获取浏览器的 location.hash。我们不使用 location.hash,因为 Firefox 的自动解码方式(见 http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash)。

Type declaration

▸ (): string

Returns

string

En

Get the browser location.hash. We don't use location.hash because of the way that Firefox auto-urldecodes it (see http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash)

Zh

获取浏览器的 location.hash。我们不使用 location.hash,因为 Firefox 的自动解码方式(见 http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash)。

Defined in

src/utils/index.d.ts:256


getTypeEncoding

getTypeEncoding: (extension: string) => string

En

Given an extension, get the correct encoding for that file. defaults to utf8

Zh

给定一个扩展名,获得该文件的正确编码。默认为 utf8

Type declaration

▸ (extension): string

Parameters
NameType
extensionstring
Returns

string

En

Given an extension, get the correct encoding for that file. defaults to utf8

Zh

给定一个扩展名,获得该文件的正确编码。默认为 utf8

Defined in

src/utils/index.d.ts:264


hop

hop: (object: Record<string, unknown>, property: string | symbol) => boolean

En

Check if an object has a property.

Zh

检查一个对象是否有一个属性。

Type declaration

▸ (object, property): boolean

Parameters
NameType
objectRecord<string, unknown>
propertystring | symbol
Returns

boolean

En

Check if an object has a property.

Zh

检查一个对象是否有一个属性。

Defined in

src/utils/index.d.ts:272


htmlDecode

htmlDecode: (text: string) => string

En

Convert &amp; to &, &nbsp; to , &lt; to <, &gt; to > and &quot; to "

Zh

&amp;转换成&&nbsp;转换成 &lt;转换成<&gt;转换成>&quot;转换成"

Type declaration

▸ (text): string

Parameters
NameType
textstring
Returns

string

En

Convert &amp; to &, &nbsp; to , &lt; to <, &gt; to > and &quot; to "

Zh

&amp;转换成&&nbsp;转换成 &lt;转换成<&gt;转换成>&quot;转换成"

Defined in

src/utils/index.d.ts:280


insertSortedArray

insertSortedArray: <T>(array: T, value: unknown) => T

En

Add an entry to a sorted array if it doesn't already exist, while maintaining the sort order

Zh

如果一个已排序的数组中不存在一个条目,则添加该条目,同时保持排序顺序

Type declaration

▸ <T>(array, value): T

Type parameters
NameType
Textends unknown[]
Parameters
NameType
arrayT
valueunknown
Returns

T

En

Add an entry to a sorted array if it doesn't already exist, while maintaining the sort order

Zh

如果一个已排序的数组中不存在一个条目,则添加该条目,同时保持排序顺序

Defined in

src/utils/index.d.ts:288


isArray

isArray: (value: unknown) => boolean

En

Determine if a value is an array.

Zh

判断对象是否是一个数组。

Type declaration

▸ (value): boolean

Parameters
NameType
valueunknown
Returns

boolean

En

Determine if a value is an array.

Zh

判断对象是否是一个数组。

Defined in

src/utils/index.d.ts:299


isArrayEqual

isArrayEqual: (array1: unknown[], array2: unknown[]) => boolean

En

Check if an array is equal by value and by reference.

Zh

检查一个数组的值和引用是否相等。

Type declaration

▸ (array1, array2): boolean

Parameters
NameType
array1unknown[]
array2unknown[]
Returns

boolean

En

Check if an array is equal by value and by reference.

Zh

检查一个数组的值和引用是否相等。

Defined in

src/utils/index.d.ts:307


isDate

isDate: (value: unknown) => void

En

Determine if a value is a date

Zh

确定一个值是否是一个日期

Type declaration

▸ (value): void

Parameters
NameType
valueunknown
Returns

void

En

Determine if a value is a date

Zh

确定一个值是否是一个日期

Defined in

src/utils/index.d.ts:315


pad

pad: (value: number, length?: number) => string

En

Pad a string to a given length with "0"s. Length defaults to 2

Zh

用 "0 "将一个字符串填充到指定的长度。长度默认为 2

Type declaration

▸ (value, length?): string

Parameters
NameType
valuenumber
length?number
Returns

string

En

Pad a string to a given length with "0"s. Length defaults to 2

Zh

用 "0 "将一个字符串填充到指定的长度。长度默认为 2

Defined in

src/utils/index.d.ts:323


parseDate

parseDate: (value: string | Date) => Date

En

Parse a date from a UTC YYYYMMDDHHMMSSmmm format string

Zh

从 UTC YYYYMMDDHHMMSSmmm 格式字符串中解析一个日期

Type declaration

▸ (value): Date

Parameters
NameType
valuestring | Date
Returns

Date

En

Parse a date from a UTC YYYYMMDDHHMMSSmmm format string

Zh

从 UTC YYYYMMDDHHMMSSmmm 格式字符串中解析一个日期

Defined in

src/utils/index.d.ts:331


parseFields

parseFields: (text: string, fields?: object) => Record<string, string>

En

Parse a block of name:value fields. The fields object is used as the basis for the return value

Zh

解析一个 name:value 字段的块。fields对象被用作返回值的基础。

Type declaration

▸ (text, fields?): Record<string, string>

Parameters
NameType
textstring
fields?object
Returns

Record<string, string>

En

Parse a block of name:value fields. The fields object is used as the basis for the return value

Zh

解析一个 name:value 字段的块。fields对象被用作返回值的基础。

Defined in

src/utils/index.d.ts:339


parseJSONSafe

parseJSONSafe: <T>(input: string, defaultJSON?: (error: Error) => T) => T

En

Safely parse a string as JSON

Zh

安全地解析一个字符串为 JSON 对象

Type declaration

▸ <T>(input, defaultJSON?): T

Type parameters
NameType
Tunknown
Parameters
NameType
inputstring
defaultJSON?(error: Error) => T
Returns

T

En

Safely parse a string as JSON

Zh

安全地解析一个字符串为 JSON 对象

Defined in

src/utils/index.d.ts:347


parseStringArray

parseStringArray: (value: string | string[], allowDuplicate?: boolean) => string[]

En

Parse a string array from a bracketted list. For example OneTiddler [[Another Tiddler]] LastOne

Zh

从一个带括号的列表中解析一个字符串数组。例如,OneTiddler [[Another Tiddler]] LastOne

Type declaration

▸ (value, allowDuplicate?): string[]

Parameters
NameType
valuestring | string[]
allowDuplicate?boolean
Returns

string[]

An array of tiddler titles. null if input is not string or string array. This won't happened in TS.

En

Parse a string array from a bracketted list. For example OneTiddler [[Another Tiddler]] LastOne

Zh

从一个带括号的列表中解析一个字符串数组。例如,OneTiddler [[Another Tiddler]] LastOne

Defined in

src/utils/index.d.ts:360


parseVersion

parseVersion: (version: string) => { build?: string ; major: number ; minor: number ; patch: number ; prerelease?: string ; version: string }

En

Parse a semantic version string into its constituent parts -- see https://semver.org

Zh

将一个语义版本字符串解析为其构成部分 -- 见 https://semver.org

Type declaration

▸ (version): Object

Parameters
NameType
versionstring
Returns

Object

NameType
build?string
majornumber
minornumber
patchnumber
prerelease?string
versionstring

En

Parse a semantic version string into its constituent parts -- see https://semver.org

Zh

将一个语义版本字符串解析为其构成部分 -- 见 https://semver.org

Defined in

src/utils/index.d.ts:371


pushTop

pushTop: <T>(array: T, value: unknown) => T

En

Push entries onto an array, removing them first if they already exist in the array

Zh

将条目推送到一个数组中,如果它们已经存在于数组中,则先将其删除。

Param

array to modify (assumed to be free of duplicates)

Param

a single value to push or an array of values to push

Type declaration

▸ <T>(array, value): T

Type parameters
NameType
Textends unknown[]
Parameters
NameTypeDescription
arrayTarray to modify (assumed to be free of duplicates)
valueunknowna single value to push or an array of values to push
Returns

T

En

Push entries onto an array, removing them first if they already exist in the array

Zh

将条目推送到一个数组中,如果它们已经存在于数组中,则先将其删除。

Defined in

src/utils/index.d.ts:390


registerFileType

registerFileType: (contentType: string, encoding: string, extension: string | string[], options?: { deserializerType?: string ; flags?: string[] }) => void

En

Register file type information

Zh

注册文件类型信息

Param

Param

Param

Param

Options includes:

  • flags:"image" for image types
  • deserializerType: defaults to type if not specified

Type declaration

▸ (contentType, encoding, extension, options?): void

Parameters
NameTypeDescription
contentTypestring
encodingstring
extensionstring | string[]
options?ObjectOptions includes: * flags:"image" for image types * deserializerType: defaults to type if not specified
options.deserializerType?string-
options.flags?string[]-
Returns

void

En

Register file type information

Zh

注册文件类型信息

Defined in

src/utils/index.d.ts:408


resolvePath

resolvePath: (sourcepath: string, rootpath: string) => string

En

Resolves a source filepath delimited with / relative to a specified absolute root filepath. In relative paths, the special folder name .. refers to immediate parent directory, and the name . refers to the current directory

Zh

将以/为界的源文件路径相对于指定的绝对根文件路径进行解析。 在相对路径中,特殊的文件夹名称...指的是直接的父目录,而名称.指的是当前目录。

Type declaration

▸ (sourcepath, rootpath): string

Parameters
NameType
sourcepathstring
rootpathstring
Returns

string

En

Resolves a source filepath delimited with / relative to a specified absolute root filepath. In relative paths, the special folder name .. refers to immediate parent directory, and the name . refers to the current directory

Zh

将以/为界的源文件路径相对于指定的绝对根文件路径进行解析。 在相对路径中,特殊的文件夹名称...指的是直接的父目录,而名称.指的是当前目录。

Defined in

src/utils/index.d.ts:427


stringifyDate

stringifyDate: (value: Date) => string

En

Convert a date into UTC YYYYMMDDHHMMSSmmm format

Zh

将日期转换成 UTC YYYYMMDDHMMSSmmm 格式

Type declaration

▸ (value): string

Parameters
NameType
valueDate
Returns

string

En

Convert a date into UTC YYYYMMDDHHMMSSmmm format

Zh

将日期转换成 UTC YYYYMMDDHMMSSmmm 格式

Defined in

src/utils/index.d.ts:435


stringifyList

stringifyList: (value: string[]) => string

En

Stringify an array of tiddler titles into a list string

Zh

将一个数组的 tiddler 标题字符串化为一个列表字符串

Type declaration

▸ (value): string

Parameters
NameType
valuestring[]
Returns

string

En

Stringify an array of tiddler titles into a list string

Zh

将一个数组的 tiddler 标题字符串化为一个列表字符串

Defined in

src/utils/index.d.ts:443


transliterate

transliterate: (string_: string) => string

Remove any of the characters that are illegal in Windows filenames See $tw.utils.transliterationPairs for the list of replacements

Type declaration

▸ (string_): string

Remove any of the characters that are illegal in Windows filenames See $tw.utils.transliterationPairs for the list of replacements

Parameters
NameType
string_string
Returns

string

Defined in

src/utils/index.d.ts:448


transliterateToSafeASCII

transliterateToSafeASCII: (string_: string) => string

Remove any of the characters that are illegal in Windows filenames See $tw.utils.transliterationPairs for the list of replacements

Type declaration

▸ (string_): string

Remove any of the characters that are illegal in Windows filenames See $tw.utils.transliterationPairs for the list of replacements

Parameters
NameType
string_string
Returns

string

Defined in

src/utils/index.d.ts:453


transliterationPairs

transliterationPairs: Record<string, string>

Transliterate string to ASCII (Some pairs taken from http://semplicewebsites.com/ removing-accents-javascript)

Defined in

src/utils/index.d.ts:458