Interface: IUtilsBoot
core.IUtilsBoot
Table of contents
Properties
- Crypto
- PasswordPrompt
- checkVersions
- compareVersions
- decodeURIComponentSafe
- decodeURISafe
- deepDefaults
- domMaker
- each
- error
- evalGlobal
- evalSandboxed
- extend
- getFileExtensionInfo
- getLocationHash
- getTypeEncoding
- hop
- htmlDecode
- insertSortedArray
- isArray
- isArrayEqual
- isDate
- pad
- parseDate
- parseFields
- parseJSONSafe
- parseStringArray
- parseVersion
- pushTop
- registerFileType
- resolvePath
- stringifyDate
- stringifyList
- transliterate
- transliterateToSafeASCII
- transliterationPairs
Properties
Crypto
• Crypto: typeof Crypto
Defined in
PasswordPrompt
• PasswordPrompt: typeof PasswordPrompt
Defined in
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
Name | Type |
---|---|
versionStringA | string |
versionStringB | string |
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
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
Name | Type |
---|---|
versionStringA | string |
versionStringB | string |
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
decodeURIComponentSafe
• decodeURIComponentSafe: (uri
: string
) => string
En
Convert a URIComponent encoded string to a string safely
Zh
将一个 URIComponent 编码的字符串安全地转换为一个字符串。
Type declaration
▸ (uri
): string
Parameters
Name | Type |
---|---|
uri | string |
Returns
string
En
Convert a URIComponent encoded string to a string safely
Zh
将一个 URIComponent 编码的字符串安全地转换为一个字符串。
Defined in
decodeURISafe
• decodeURISafe: (uri
: string
) => string
En
Convert a URI encoded string to a string safely
Zh
将一个 URI 编码的字符串安全地转换为一个字符串
Type declaration
▸ (uri
): string
Parameters
Name | Type |
---|---|
uri | string |
Returns
string
En
Convert a URI encoded string to a string safely
Zh
将一个 URI 编码的字符串安全地转换为一个字符串
Defined in
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
Name | Type |
---|---|
O | extends object |
S | extends object [] |
Parameters
Name | Type |
---|---|
origin | O |
...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
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
Name | Type |
---|---|
K | extends keyof HTMLElementTagNameMap |
Parameters
Name | Type | Description |
---|---|---|
tag | K | tag name |
options | IDomMakerOptions |
Returns
K
extends keyof HTMLElementTagNameMap
? HTMLElementTagNameMap
[K
] : HTMLElement
En
Helper for making DOM elements
Zh
产生一个 DOM 元素
Defined in
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
Name | Type |
---|---|
T | T |
K | T extends unknown [] ? number : keyof T |
Parameters
Name | Type |
---|---|
object | T |
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
error
• error: (error
: string
| Event
| Error
) => null
En
Display an error and exit
Zh
打印一个错误,如果在 Node 环境下,会退出进程
Type declaration
▸ (error
): null
Parameters
Name | Type |
---|---|
error | string | Event | Error |
Returns
null
En
Display an error and exit
Zh
打印一个错误,如果在 Node 环境下,会退出进程
Defined in
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
Name | Type |
---|---|
code | string |
context | IEvalContent |
filename | string |
Returns
unknown
En
Run code globally with specified context variables in scope
Zh
在全局范围内运行代码,范围内有指定的上下文变量
Defined in
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
Name | Type |
---|---|
code | string |
context | IEvalContent |
filename | string |
Returns
unknown
En
Run code in a sandbox with only the specified context variables in scope
Zh
在沙盒中运行代码,范围内只有指定的上下文变量
Defined in
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
Name | Type |
---|---|
O | extends object |
S | extends object [] |
Parameters
Name | Type |
---|---|
origin | O |
...sources | [...S[]] |
Returns
Spread
<O
, S
>
En
Extend an object with the properties from a list of source objects
Zh
用源对象列表中的属性扩展一个对象
Defined in
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
Name | Type |
---|---|
extension | string |
Returns
En
Given an extension, always access the $tw.config.fileExtensionInfo using a lowercase extension only.
Zh
给定一个扩展名,总是只使用小写的扩展名来访问$tw.config.fileExtensionInfo。
Defined in
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
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
Name | Type |
---|---|
extension | string |
Returns
string
En
Given an extension, get the correct encoding for that file. defaults to utf8
Zh
给定一个扩展名,获得该文件的正确编码。默认为 utf8
Defined in
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
Name | Type |
---|---|
object | Record <string , unknown > |
property | string | symbol |
Returns
boolean
En
Check if an object has a property.
Zh
检查一个对象是否有一个属性。
Defined in
htmlDecode
• htmlDecode: (text
: string
) => string
En
Convert &
to &
,
to
, <
to <
, >
to >
and "
to "
Zh
将&
转换成&
,
转换成
,<
转换成<
,>
转换成>
,"
转换成"
Type declaration
▸ (text
): string
Parameters
Name | Type |
---|---|
text | string |
Returns
string
En
Convert &
to &
,
to
, <
to <
, >
to >
and "
to "
Zh
将&
转换成&
,
转换成
,<
转换成<
,>
转换成>
,"
转换成"
Defined in
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
Name | Type |
---|---|
T | extends unknown [] |
Parameters
Name | Type |
---|---|
array | T |
value | unknown |
Returns
T
En
Add an entry to a sorted array if it doesn't already exist, while maintaining the sort order
Zh
如果一个已排序的数组中不存在一个条目,则添加该条目,同时保持排序顺序
Defined in
isArray
• isArray: (value
: unknown
) => boolean
En
Determine if a value is an array.
Zh
判断对象是否是一个数组。
Type declaration
▸ (value
): boolean
Parameters
Name | Type |
---|---|
value | unknown |
Returns
boolean
En
Determine if a value is an array.
Zh
判断对象是否是一个数组。
Defined in
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
Name | Type |
---|---|
array1 | unknown [] |
array2 | unknown [] |
Returns
boolean
En
Check if an array is equal by value and by reference.
Zh
检查一个数组的值和引用是否相等。
Defined in
isDate
• isDate: (value
: unknown
) => void
En
Determine if a value is a date
Zh
确定一个值是否是一个日期
Type declaration
▸ (value
): void
Parameters
Name | Type |
---|---|
value | unknown |
Returns
void
En
Determine if a value is a date
Zh
确定一个值是否是一个日期
Defined in
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
Name | Type |
---|---|
value | number |
length? | number |
Returns
string
En
Pad a string to a given length with "0"s. Length defaults to 2
Zh
用 "0 "将一个字符串填充到指定的长度。长度默认为 2
Defined in
parseDate
• parseDate: (value
: string
| Date
) => Date
En
Parse a date from a UTC YYYYMMDDHHMMSSmmm
format string
Zh
从 UTC YYYYMMDDHHMMSSmmm
格式字符串中解析一个日期
Type declaration
▸ (value
): Date
Parameters
Name | Type |
---|---|
value | string | Date |
Returns
Date
En
Parse a date from a UTC YYYYMMDDHHMMSSmmm
format string
Zh
从 UTC YYYYMMDDHHMMSSmmm
格式字符串中解析一个日期
Defined in
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
Name | Type |
---|---|
text | string |
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
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
Name | Type |
---|---|
T | unknown |
Parameters
Name | Type |
---|---|
input | string |
defaultJSON? | (error : Error ) => T |
Returns
T
En
Safely parse a string as JSON
Zh
安全地解析一个字符串为 JSON 对象
Defined in
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
Name | Type |
---|---|
value | string | 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
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
Name | Type |
---|---|
version | string |
Returns
Object
Name | Type |
---|---|
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
Defined in
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
Name | Type |
---|---|
T | extends unknown [] |
Parameters
Name | Type | Description |
---|---|---|
array | T | array to modify (assumed to be free of duplicates) |
value | unknown | a 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
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
Name | Type | Description |
---|---|---|
contentType | string | |
encoding | string | |
extension | string | string [] | |
options? | Object | Options 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
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
Name | Type |
---|---|
sourcepath | string |
rootpath | string |
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
stringifyDate
• stringifyDate: (value
: Date
) => string
En
Convert a date into UTC YYYYMMDDHHMMSSmmm
format
Zh
将日期转换成 UTC YYYYMMDDHMMSSmmm
格式
Type declaration
▸ (value
): string
Parameters
Name | Type |
---|---|
value | Date |
Returns
string
En
Convert a date into UTC YYYYMMDDHHMMSSmmm
format
Zh
将日期转换成 UTC YYYYMMDDHMMSSmmm
格式
Defined in
stringifyList
• stringifyList: (value
: string
[]) => string
En
Stringify an array of tiddler titles into a list string
Zh
将一个数组的 tiddler 标题字符串化为一个列表字符串
Type declaration
▸ (value
): string
Parameters
Name | Type |
---|---|
value | string [] |
Returns
string
En
Stringify an array of tiddler titles into a list string
Zh
将一个数组的 tiddler 标题字符串化为一个列表字符串
Defined in
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
Name | Type |
---|---|
string_ | string |
Returns
string
Defined in
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
Name | Type |
---|---|
string_ | string |
Returns
string
Defined in
transliterationPairs
• transliterationPairs: Record
<string
, string
>
Transliterate string to ASCII (Some pairs taken from http://semplicewebsites.com/ removing-accents-javascript)