Skip to main content

IUtilitiesBoot

tw5-typed


tw5-typed / utils / IUtilitiesBoot

Interface: IUtilitiesBoot

Defined in: src/utils/index.d.ts:106

Properties​

checkVersions()​

checkVersions: (versionStringA, versionStringB) => boolean

Defined in: src/utils/index.d.ts:116

Parameters​

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。


cleanupTiddlerFiles()​

cleanupTiddlerFiles: (fileInfo, callback?) => void

Defined in: src/utils/index.d.ts:488

Cleanup tiddler files (delete old files when tiddler is moved)

Parameters​

fileInfo​

Record<string, unknown> | IFileInfo

callback?​

(error, cleanedFileInfo?) => void

Returns​

void


compareVersions()​

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

Defined in: src/utils/index.d.ts:126

Parameters​

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


createDirectory()​

createDirectory: (directoryPath) => void

Defined in: src/utils/index.d.ts:467

Create directory recursively

Parameters​

directoryPath​

string

Returns​

void


Crypto​

Crypto: typeof Crypto

Defined in: src/utils/index.d.ts:107


decodeURIComponentSafe()​

decodeURIComponentSafe: (uri) => string

Defined in: src/utils/index.d.ts:137

Parameters​

uri​

string

Returns​

string

En​

Convert a URIComponent encoded string to a string safely

Zh​

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


decodeURISafe()​

decodeURISafe: (uri) => string

Defined in: src/utils/index.d.ts:145

Parameters​

uri​

string

Returns​

string

En​

Convert a URI encoded string to a string safely

Zh​

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


deepDefaults()​

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

Defined in: src/utils/index.d.ts:153

Type Parameters​

O​

O extends object

S​

S extends object[]

Parameters​

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​

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


deleteTiddlerFile()​

deleteTiddlerFile: (fileInfo, callback?) => void

Defined in: src/utils/index.d.ts:495

Delete tiddler file

Parameters​

fileInfo​

IFileInfo

callback?​

(error, deletedFileInfo?) => void

Returns​

void


domMaker()​

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

Defined in: src/utils/index.d.ts:168

Type Parameters​

K​

K extends keyof HTMLElementTagNameMap

Parameters​

tag​

K

tag name

options​

IDomMakerOptions

Returns​

K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K<K>] : HTMLElement

En​

Helper for making DOM elements

Zh​

产生一个 DOM 元素


each()​

each: <T, K>(object, callback) => void

Defined in: src/utils/index.d.ts:191

Type Parameters​

T​

T

K​

K = T extends unknown[] ? number : keyof T

Parameters​

object​

T

callback​

(element, index, object) => false

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));

error()​

error: (error) => null

Defined in: src/utils/index.d.ts:202

Parameters​

error​

string | Event | Error

Returns​

null

En​

Display an error and exit

Zh​

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


evalGlobal()​

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

Defined in: src/utils/index.d.ts:210

Parameters​

code​

string

context​

IEvalContent

filename​

string

Returns​

unknown

En​

Run code globally with specified context variables in scope

Zh​

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


evalSandboxed()​

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

Defined in: src/utils/index.d.ts:222

Parameters​

code​

string

context​

IEvalContent

filename​

string

Returns​

unknown

En​

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

Zh​

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


extend()​

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

Defined in: src/utils/index.d.ts:234

Type Parameters​

O​

O extends object

S​

S extends object[]

Parameters​

origin​

O

sources​

...[...S[]]

Returns​

Spread<O, S>

En​

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

Zh​

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


formatDateString()​

formatDateString: (date, template) => string

Defined in: src/utils/index.d.ts:499

Format date string

Parameters​

date​

Date

template​

string

Returns​

string


generateTiddlerFileInfo()​

generateTiddlerFileInfo: (tiddler, options) => IFileInfo

Defined in: src/utils/index.d.ts:471

Generate tiddler file info for saving

Parameters​

tiddler​

Tiddler

options​
directory​

string

extFilters?​

string[]

fileInfo?​

Partial<IFileInfo>

pathFilters?​

string[]

wiki​

Wiki

Returns​

IFileInfo


getFileExtensionInfo()​

getFileExtensionInfo: (extension) => IFileExtensionInfo

Defined in: src/utils/index.d.ts:245

Parameters​

extension​

string

Returns​

IFileExtensionInfo

En​

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

Zh​

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


getLocationHash()​

getLocationHash: () => string

Defined in: src/utils/index.d.ts:253

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)。


getTypeEncoding()​

getTypeEncoding: (extension) => string

Defined in: src/utils/index.d.ts:261

Parameters​

extension​

string

Returns​

string

En​

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

Zh​

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


hop()​

hop: (object, property) => boolean

Defined in: src/utils/index.d.ts:269

Parameters​

object​

Record<string, unknown>

property​

string | symbol

Returns​

boolean

En​

Check if an object has a property.

Zh​

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


htmlDecode()​

htmlDecode: (text) => string

Defined in: src/utils/index.d.ts:277

Parameters​

text​

string

Returns​

string

En​

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

Zh​

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


insertSortedArray()​

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

Defined in: src/utils/index.d.ts:285

Type Parameters​

T​

T extends unknown[]

Parameters​

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​

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


isArray()​

isArray: (value) => boolean

Defined in: src/utils/index.d.ts:296

Parameters​

value​

unknown

Returns​

boolean

En​

Determine if a value is an array.

Zh​

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


isArrayEqual()​

isArrayEqual: (array1, array2) => boolean

Defined in: src/utils/index.d.ts:304

Parameters​

array1​

unknown[]

array2​

unknown[]

Returns​

boolean

En​

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

Zh​

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


isDate()​

isDate: (value) => void

Defined in: src/utils/index.d.ts:312

Parameters​

value​

unknown

Returns​

void

En​

Determine if a value is a date

Zh​

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


Logger​

Logger: typeof Logger

Defined in: src/utils/index.d.ts:459

Logger class constructor


pad()​

pad: (value, length?) => string

Defined in: src/utils/index.d.ts:320

Parameters​

value​

number

length?​

number

Returns​

string

En​

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

Zh​

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


parseDate()​

parseDate: (value) => Date

Defined in: src/utils/index.d.ts:328

Parameters​

value​

string | Date

Returns​

Date

En​

Parse a date from a UTC YYYYMMDDHHMMSSmmm format string

Zh​

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


parseFields()​

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

Defined in: src/utils/index.d.ts:336

Parameters​

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对象被用作返回值的基础。


parseFilterVariable()​

parseFilterVariable: (source) => unknown

Defined in: src/utils/index.d.ts:463

Parse a filter variable

Parameters​

source​

string

Returns​

unknown


parseJSONSafe()​

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

Defined in: src/utils/index.d.ts:344

Type Parameters​

T​

T = unknown

Parameters​

input​

string

defaultJSON?​

(error) => T

Returns​

T

En​

Safely parse a string as JSON

Zh​

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


parseStringArray()​

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

Defined in: src/utils/index.d.ts:357

Parameters​

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


parseVersion()​

parseVersion: (version) => object

Defined in: src/utils/index.d.ts:368

Parameters​

version​

string

Returns​

object

build?​

optional build: string

major​

major: number

minor​

minor: number

patch​

patch: number

prerelease?​

optional prerelease: string

version​

version: string

En​

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

Zh​

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


PasswordPrompt​

PasswordPrompt: typeof PasswordPrompt

Defined in: src/utils/index.d.ts:108


pushTop()​

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

Defined in: src/utils/index.d.ts:387

Type Parameters​

T​

T extends unknown[]

Parameters​

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​

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


registerFileType()​

registerFileType: (contentType, encoding, extension, options?) => void

Defined in: src/utils/index.d.ts:405

Parameters​

contentType​

string

encoding​

string

extension​

string | string[]

options?​

Options includes:

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

string

flags?​

string[]

Returns​

void

En​

Register file type information

Zh​

注册文件类型信息


resolvePath()​

resolvePath: (sourcepath, rootpath) => string

Defined in: src/utils/index.d.ts:424

Parameters​

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​

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


saveTiddlerToFile()​

saveTiddlerToFile: (tiddler, fileInfo, callback?) => void

Defined in: src/utils/index.d.ts:484

Save tiddler to file

Parameters​

tiddler​

Tiddler

fileInfo​

IFileInfo

callback?​

(error) => void

Returns​

void


stringifyDate()​

stringifyDate: (value) => string

Defined in: src/utils/index.d.ts:432

Parameters​

value​

Date

Returns​

string

En​

Convert a date into UTC YYYYMMDDHHMMSSmmm format

Zh​

将日期转换成 UTC YYYYMMDDHMMSSmmm 格式


stringifyList()​

stringifyList: (value) => string

Defined in: src/utils/index.d.ts:440

Parameters​

value​

string[]

Returns​

string

En​

Stringify an array of tiddler titles into a list string

Zh​

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


transliterate()​

transliterate: (string_) => string

Defined in: src/utils/index.d.ts:445

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

Parameters​

string_​

string

Returns​

string


transliterateToSafeASCII()​

transliterateToSafeASCII: (string_) => string

Defined in: src/utils/index.d.ts:450

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

Parameters​

string_​

string

Returns​

string


transliterationPairs​

transliterationPairs: Record<string, string>

Defined in: src/utils/index.d.ts:455

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