Skip to main content

tw5-typed / modules/utils/utils

Module: modules/utils/utils

Table of contents

References

Type Aliases

Variables

Functions

References

copyDirectory

Re-exports copyDirectory


copyFile

Re-exports copyFile


createDirectory

Re-exports createDirectory


createFileDirectories

Re-exports createFileDirectories


deleteDirectory

Re-exports deleteDirectory


deleteEmptyDirectories

Re-exports deleteEmptyDirectories


generateTiddlerExtension

Re-exports generateTiddlerExtension


generateTiddlerFileInfo

Re-exports generateTiddlerFileInfo


generateTiddlerFilepath

Re-exports generateTiddlerFilepath


getSubdirectories

Re-exports getSubdirectories


isDirectory

Re-exports isDirectory


isDirectoryEmpty

Re-exports isDirectoryEmpty


removeTrailingSeparator

Re-exports removeTrailingSeparator

Type Aliases

TerminalColourName

Ƭ TerminalColourName: "black" | "red" | "green" | "brown/orange" | "blue" | "purple" | "cyan" | "light gray"

Defined in

src/modules/utils/utils.d.ts:2

Variables

terminalColourLookup

Const terminalColourLookup: Record<TerminalColourName, string>

Defined in

src/modules/utils/utils.d.ts:12

Functions

base64Decode

base64Decode(string64): string

Decodes a base64 string.

Parameters

NameTypeDescription
string64stringThe base64 string to decode.

Returns

string

The decoded string.

Description

解码 base64 字符串。

Defined in

src/modules/utils/utils.d.ts:489


base64Encode

base64Encode(string64): string

Encodes a string to base64.

Parameters

NameTypeDescription
string64stringThe string to encode.

Returns

string

The encoded base64 string.

Description

将字符串编码为 base64。

Defined in

src/modules/utils/utils.d.ts:497


checkDependencies

checkDependencies(dependencies, changes): boolean

Checks whether any members of a hashmap are present in another hashmap.

Parameters

NameTypeDescription
dependenciesobjectThe hashmap to check for dependencies.
changesobjectThe hashmap to check for changes.

Returns

boolean

True if any members of the hashmap are present in another hashmap, false otherwise.

Description

检查哈希映射的任何成员是否存在于另一个哈希映射中。

Defined in

src/modules/utils/utils.d.ts:191


count

count(object): number

Returns the number of keys in an object.

Parameters

NameTypeDescription
objectobjectThe object to count the keys of.

Returns

number

The number of keys in the object.

Description

返回对象中键的数量。

Defined in

src/modules/utils/utils.d.ts:164


deepCopy

deepCopy(object): any

Deep copy an object.

Parameters

NameTypeDescription
objectanyThe object to copy.

Returns

any

The copied object.

Description

深拷贝对象。

Defined in

src/modules/utils/utils.d.ts:220


deepFreeze

deepFreeze(object): void

Recursively freeze an object and its properties.

Parameters

NameTypeDescription
objectanyThe object to freeze.

Returns

void

Description

递归地冻结对象及其属性。

Defined in

src/modules/utils/utils.d.ts:236


encodeURIComponentExtended

encodeURIComponentExtended(s): string

An extended version of encodeURIComponent that encodes additional characters including those that are illegal within filepaths on various platforms including Windows.

Parameters

NameTypeDescription
sstringThe string to encode.

Returns

string

The encoded string.

Description

encodeURIComponent 的扩展版本,可编码包括在各种平台(包括 Windows)的文件路径中非法的其他字符。

Defined in

src/modules/utils/utils.d.ts:390


endsWith

endsWith(string_, search): boolean

Checks if a string ends with another string.

Parameters

NameTypeDescription
string_string-
searchstringThe string to search for.

Returns

boolean

True if the string ends with the search string, false otherwise.

Description

检查字符串是否以另一个字符串结尾。

Defined in

src/modules/utils/utils.d.ts:96


entityDecode

entityDecode(s): string

Converts all HTML entities to their character equivalents.

Parameters

NameTypeDescription
sstringThe string to decode.

Returns

string

The decoded string.

Description

将所有 HTML 实体转换为它们的字符等价物。

Defined in

src/modules/utils/utils.d.ts:340


escape

escape(ch): string

Returns an escape sequence for given character. Uses \x for characters <= 0xFF to save space, \u for the rest.

Parameters

NameTypeDescription
chstringThe character to escape.

Returns

string

The escaped character.

Description

返回给定字符的转义序列。对于字符 <= 0xFF,使用 \x 以节省空间,对于其余字符使用 \u

Defined in

src/modules/utils/utils.d.ts:356


escapeRegExp

escapeRegExp(s): string

Escapes the RegExp special characters with a preceding backslash.

Parameters

NameTypeDescription
sstringThe string to escape.

Returns

string

The escaped string.

Description

使用反斜杠转义 RegExp 特殊字符。

Defined in

src/modules/utils/utils.d.ts:382


extend

extend(object, ...source): object

Extends an object with one or more sources.

Parameters

NameTypeDescription
objectobjectThe object to extend.
...sourceobject[]-

Returns

object

The extended object.

Description

使用一个或多个源扩展对象。

Defined in

src/modules/utils/utils.d.ts:203

extend(object, ...source): any

Extend an object with properties from one or more sources.

Parameters

NameTypeDescription
objectanyThe object to extend.
...sourceany[]-

Returns

any

The extended object.

Description

从一个或多个源中复制属性来扩展对象。

Defined in

src/modules/utils/utils.d.ts:212


extendDeepCopy

extendDeepCopy(object, extendedProperties): any

Extend an object with properties from one or more sources, and deep copy the extended properties.

Parameters

NameTypeDescription
objectanyThe object to extend.
extendedPropertiesanyThe properties to extend and deep copy.

Returns

any

The extended object.

Description

从一个或多个源中复制属性来扩展对象,并深拷贝扩展的属性。

Defined in

src/modules/utils/utils.d.ts:229


extractVersionInfo

extractVersionInfo(): string | null

Extracts the version number from the meta tag or from the boot file.

Returns

string | null

The version number.

Description

从 meta 标签或启动文件中提取版本号。

Defined in

src/modules/utils/utils.d.ts:466


findFollowingLineBreak

findFollowingLineBreak(text, pos): number

Finds the line break following a given position in a string.

Parameters

NameTypeDescription
textstringThe string to search in.
posnumberThe position to search for.

Returns

number

The position of the following line break, or the end of the string.

Description

查找字符串中给定位置之后的换行符。

Defined in

src/modules/utils/utils.d.ts:156


findPrecedingLineBreak

findPrecedingLineBreak(text, pos): number

Finds the line break preceding a given position in a string.

Parameters

NameTypeDescription
textstringThe string to search in.
posnumberThe position to search for.

Returns

number

The position immediately after that line break, or the start of the string.

Description

查找字符串中给定位置之前的换行符。

Defined in

src/modules/utils/utils.d.ts:147


formatDateString

formatDateString(date, template): string

Format a date string based on a template. Use "[UTC]YYYY0MM0DD0hh0mm0ss0XXX" to format a standard tiddlywiki date string. See document for more formats.

Parameters

NameTypeDescription
dateDateThe date object to format.
templatestringThe template string to use for formatting.

Returns

string

The formatted date string.

Url

https://tiddlywiki.com/#DateFormat

Defined in

src/modules/utils/utils.d.ts:268


formatTitleString

formatTitleString(template, options): string

Format a string template with options.

Parameters

NameTypeDescription
templatestringThe string template to format.
optionsObjectThe options to use for formatting.
options.base?string-
options.counter?number-
options.separator?string-

Returns

string

The formatted string.

Description

使用选项格式化字符串模板。

Defined in

src/modules/utils/utils.d.ts:253


getAmPm

getAmPm(date): string

Get the AM/PM period of a date.

Parameters

NameTypeDescription
dateDateThe date object to get the period from.

Returns

string

The period string (either "am" or "pm").

Defined in

src/modules/utils/utils.d.ts:275


getAnimationDuration

getAnimationDuration(): number

Gets the animation duration in milliseconds.

Returns

number

The animation duration.

Description

获取动画持续时间(以毫秒为单位)。

Defined in

src/modules/utils/utils.d.ts:473


getDaySuffix

getDaySuffix(date): string

Get the suffix for the day of a date.

Parameters

NameTypeDescription
dateDateThe date object to get the day suffix from.

Returns

string

The day suffix string.

Defined in

src/modules/utils/utils.d.ts:282


getHours12

getHours12(date): number

Get the 12-hour format of the hour of a date.

Parameters

NameTypeDescription
dateDateThe date object to get the hour from.

Returns

number

The 12-hour format of the hour.

Defined in

src/modules/utils/utils.d.ts:303


getInt

getInt(string_, deflt): number

Return the integer represented by the str (string). Return the dflt (default) parameter if str is not a base-10 number.

Parameters

NameTypeDescription
string_string-
defltnumberThe default value to return if the string is not a base-10 number.

Returns

number

The integer represented by the string or the default value if the string is not a base-10 number.

Description

返回由 str(字符串)表示的整数。如果 str 不是十进制数字,则返回 dflt(默认)参数。

Defined in

src/modules/utils/utils.d.ts:55


getRelativeDate

getRelativeDate(delta): Object

Convert a date delta in milliseconds into a string representation of "23 seconds ago", "27 minutes ago" etc.

Parameters

NameTypeDescription
deltanumberdelta in milliseconds

Returns

Object

An object with these members:

  • description: string describing the delta period
  • updatePeriod: time in millisecond until the string will be inaccurate
NameType
descriptionstring
updatePeriodnumber

Description

将以毫秒为单位的日期差转换为“23秒前”、“27分钟前”等字符串表示形式。

Defined in

src/modules/utils/utils.d.ts:313


getSystemInfo

getSystemInfo(): string

Returns system information useful for debugging.

Returns

string

A string with system information.

Description

返回有用于调试的系统信息字符串。

Defined in

src/modules/utils/utils.d.ts:564


getWeek

getWeek(date): number

Get the week number of a date.

Parameters

NameTypeDescription
dateDateThe date object to get the week number from.

Returns

number

The week number.

Defined in

src/modules/utils/utils.d.ts:289


getYearForWeekNo

getYearForWeekNo(date): number

Get the year for a week number of a date.

Parameters

NameTypeDescription
dateDateThe date object to get the year from.

Returns

number

The year for the week number.

Defined in

src/modules/utils/utils.d.ts:296


hashString

hashString(string_): number

Hashes a string to a number. the function behind <<now "format">>

Parameters

NameType
string_string

Returns

number

The hashed number.

Description

将字符串哈希为数字。

Defined in

src/modules/utils/utils.d.ts:481


hopArray

hopArray(object, array): boolean

Determines whether an array item is an object property.

Parameters

NameTypeDescription
objectobjectThe object to check.
arrayany[]The array to check.

Returns

boolean

True if the array item is an object property, false otherwise.

Description

确定数组项是否为对象属性。

Defined in

src/modules/utils/utils.d.ts:173


htmlEncode

htmlEncode(s): string

Convert & to "&", < to "<", > to ">", " to """

Parameters

NameTypeDescription
sstringThe string to encode.

Returns

string

The encoded string.

Description

将 & 转换为 "&",< 转换为 "<",> 转换为 ">"," 转换为 """。

Defined in

src/modules/utils/utils.d.ts:324


htmlTextEncode

htmlTextEncode(s): string

Converts like htmlEncode, but forgets the double quote for brevity

Parameters

NameTypeDescription
sstringThe string to encode.

Returns

string

The encoded string.

Description

类似于 htmlEncode,但为了简洁起见忽略了双引号。

Defined in

src/modules/utils/utils.d.ts:332


hyphenateCss

hyphenateCss(propertyName): string

Converts a camelcase CSS property name into a dashed one ("backgroundColor" --> "background-color").

Parameters

NameType
propertyNamestring

Returns

string

The converted CSS property name.

Description

将驼峰式的 CSS 属性名称转换为连字符分隔的。

Defined in

src/modules/utils/utils.d.ts:421


isLinkExternal

isLinkExternal(to): boolean

Checks whether a link target is external, i.e. not a tiddler title.

Parameters

NameTypeDescription
tostringThe link target to check.

Returns

boolean

True if the link target is external, false otherwise.

Description

检查链接目标是否为外部链接,即不是 tiddler 标题。

Defined in

src/modules/utils/utils.d.ts:398


isValidFieldName

isValidFieldName(name): boolean

Checks whether a string is a valid field name.

Parameters

NameTypeDescription
namestringThe string to check.

Returns

boolean

True if the string is a valid field name, false otherwise.

Description

检查字符串是否为有效的字段名称。

Defined in

src/modules/utils/utils.d.ts:459


jsonStringify

jsonStringify(s, rawUnicode?): string

Turns a string into a legal JSON string.

Parameters

NameTypeDescription
sstringThe string to stringify.
rawUnicode?booleanWhether to escape non-ASCII characters.

Returns

string

The stringified JSON string.

Description

将字符串转换为合法的 JSON 字符串。

Defined in

src/modules/utils/utils.d.ts:374


log

log(text, colour?): void

Displays a message, in color if we're on a terminal.

Parameters

NameTypeDescription
textstringThe text to display.
colour?stringThe color to display the text in.

Returns

void

Description

在终端上显示消息,如果在终端上则以颜色显示。

Defined in

src/modules/utils/utils.d.ts:23


logTable

logTable(data): void

Log a table of name: value pairs.

Parameters

NameTypeDescription
dataobjectThe data to log.

Returns

void

Description

记录名称:值对的表格。

Defined in

src/modules/utils/utils.d.ts:45


makeCompareFunction

makeCompareFunction(type, options?): (a: any, b: any) => number

Creates a comparison function for a given type.

Parameters

NameTypeDescription
typestringThe type of comparison function to create.
options?ObjectThe options for the comparison function.
options.defaultType?string-
options.invert?boolean-
options.isCaseSensitive?boolean-

Returns

fn

The comparison function.

▸ (a, b): number

Parameters
NameType
aany
bany
Returns

number

Description

创建给定类型的比较函数。

Defined in

src/modules/utils/utils.d.ts:597


makeDataUri

makeDataUri(text, type?, _canonical_uri?): string

Converts text and content type to a data URI.

Parameters

NameTypeDescription
textstringThe text to convert.
type?stringThe content type of the text.
_canonical_uri?stringThe canonical URI of the text.

Returns

string

The data URI.

Description

将文本和内容类型转换为数据 URI。

Defined in

src/modules/utils/utils.d.ts:523


makeTiddlerDictionary

makeTiddlerDictionary(data): string

Converts a hashmap into a tiddler dictionary format sequence of name:value pairs.

Parameters

NameTypeDescription
dataRecord<string, any>The hashmap to convert.

Returns

string

The tiddler dictionary format sequence of name:value pairs.

Description

将 hashmap 转换为 tiddler 字典格式的 name:value 对序列。

Defined in

src/modules/utils/utils.d.ts:505


nextTick

nextTick(function_): void

Executes a function on the next tick of the event loop.

Parameters

NameType
function_() => void

Returns

void

Description

在事件循环的下一个时刻执行函数。

Defined in

src/modules/utils/utils.d.ts:405


parseInt

parseInt(string_): number

Parses a string into an integer.

Parameters

NameType
string_string

Returns

number

The parsed integer or 0 if the string is not a valid integer.

Description

将字符串解析为整数。

Defined in

src/modules/utils/utils.d.ts:580


parseNumber

parseNumber(string_): number

Parses a string into a number.

Parameters

NameType
string_string

Returns

number

The parsed number or 0 if the string is not a valid number.

Description

将字符串解析为数字。

Defined in

src/modules/utils/utils.d.ts:572


parseTextReference

parseTextReference(textReference): Object

Parses a text reference of one of these forms:

  • title
  • !!field
  • title!!field
  • title##index
  • etc Returns an object with the following fields, all optional:
  • title: tiddler title
  • field: tiddler field name
  • index: JSON property index

Parameters

NameType
textReferencestring

Returns

Object

An object with the parsed fields.

NameType
field?string
index?string
title?string

Description

解析文本引用,支持以下格式:

  • title
  • !!field
  • title!!field
  • title##index
  • 等等 返回一个包含以下字段的对象,所有字段都是可选的:
  • title:tiddler 标题
  • field:tiddler 字段名称
  • index:JSON 属性索引

Defined in

src/modules/utils/utils.d.ts:447


removeArrayEntries

removeArrayEntries<T>(array, value): T[]

Removes entries from an array.

Type parameters

Name
T

Parameters

NameTypeDescription
arrayT[]The array to modify.
valueT | T[]A single value or an array of values to remove.

Returns

T[]

The modified array.

Description

从数组中删除条目。

Defined in

src/modules/utils/utils.d.ts:182


repeat

repeat(string_, count): string

Repeats a string.

Parameters

NameTypeDescription
string_string-
countnumberThe number of times to repeat the string.

Returns

string

The repeated string.

Description

重复一个字符串。

Defined in

src/modules/utils/utils.d.ts:78


replaceString

replaceString(text, search, replace): string

Repeatedly replaces a substring within a string. Like String.prototype.replace, but without any of the default special handling of $ sequences in the replace string.

Parameters

NameTypeDescription
textstringThe text to search and replace.
searchstring | RegExpThe substring to search for.
replacestringThe replacement string.

Returns

string

The modified string.

Description

反复替换字符串中的子字符串。类似于 String.prototype.replace,但不使用替换字符串中的 $ 序列的默认特殊处理。

Defined in

src/modules/utils/utils.d.ts:65


sign

sign(x): number

Returns the sign of a number.

Parameters

NameTypeDescription
xnumberThe number to check.

Returns

number

1 if the number is positive, -1 if it is negative, and 0 if it is zero or NaN.

Description

返回数字的符号。如果数字为正,则返回 1,如果数字为负,则返回 -1,如果数字为零或 NaN,则返回 0。

Defined in

src/modules/utils/utils.d.ts:543


slowInSlowOut

slowInSlowOut(t): number

A slow-in, slow-out easing function.

Parameters

NameTypeDescription
tnumberThe time value, between 0 and 1.

Returns

number

The eased value.

Description

缓入缓出的缓动函数。

Defined in

src/modules/utils/utils.d.ts:244


startsWith

startsWith(string_, search): boolean

Checks if a string starts with another string.

Parameters

NameTypeDescription
string_string-
searchstringThe string to search for.

Returns

boolean

True if the string starts with the search string, false otherwise.

Description

检查字符串是否以另一个字符串开头。

Defined in

src/modules/utils/utils.d.ts:87


stringEndsWith

stringEndsWith(string_, ending, position?): boolean

Checks whether a string ends with a given substring.

Parameters

NameTypeDescription
string_string-
endingstringThe substring to check for.
position?numberThe position to start checking from.

Returns

boolean

True if the string ends with the substring, false otherwise.

Description

检查字符串是否以给定的子字符串结尾。

Defined in

src/modules/utils/utils.d.ts:553


stringify

stringify(s, rawUnicode?): string

Turns a string into a legal JavaScript string.

Parameters

NameTypeDescription
sstringThe string to stringify.
rawUnicode?booleanWhether to escape non-ASCII characters.

Returns

string

The stringified string.

Description

将字符串转换为合法的 JavaScript 字符串。

Defined in

src/modules/utils/utils.d.ts:365


stringifyNumber

stringifyNumber(number_): string

Converts a number to a string.

Parameters

NameType
number_number

Returns

string

The converted string.

Description

将数字转换为字符串。

Defined in

src/modules/utils/utils.d.ts:588


tagToCssSelector

tagToCssSelector(tagName): string

Converts a tag name to its fully escaped CSS selector equivalent.

Parameters

NameTypeDescription
tagNamestringThe tag name to convert.

Returns

string

The fully escaped CSS selector equivalent.

Description

将标签名称转换为其完全转义的 CSS 选择器等效项。

Defined in

src/modules/utils/utils.d.ts:535


terminalColour

terminalColour(colour?): string

Returns the terminal color code for a given color.

Parameters

NameTypeDescription
colour?stringThe color to get the code for.

Returns

string

The terminal color code for the given color.

Description

返回给定颜色的终端颜色代码。

Defined in

src/modules/utils/utils.d.ts:31


timer

timer(base?): number

High resolution microsecond timer for profiling.

Parameters

NameTypeDescription
base?numberThe base time to subtract from the current time.

Returns

number

The current time in microseconds.

Description

用于分析的高分辨率微秒计时器。

Defined in

src/modules/utils/utils.d.ts:513


toSentenceCase

toSentenceCase(string_): string

Converts a string to sentence case (i.e. capitalizes the first letter).

Parameters

NameType
string_string

Returns

string

The converted string.

Description

将字符串转换为句子格式(即将第一个字母大写)。

Defined in

src/modules/utils/utils.d.ts:130


toTitleCase

toTitleCase(string_): string

Converts a string to title case (i.e. capitalizes each initial letter).

Parameters

NameType
string_string

Returns

string

The converted string.

Description

将字符串转换为标题格式(即将每个单词的第一个字母大写)。

Defined in

src/modules/utils/utils.d.ts:138


trim

trim(string_): string

Trims whitespace from the start and end of a string.

Parameters

NameType
string_string

Returns

string

The trimmed string.

Description

从字符串的开头和结尾修剪空格。

Defined in

src/modules/utils/utils.d.ts:104


trimPrefix

trimPrefix(string_, unwanted): string

Trims a prefix from a string.

Parameters

NameTypeDescription
string_string-
unwantedstringThe prefix to remove.

Returns

string

The trimmed string.

Description

从字符串中修剪前缀。

Defined in

src/modules/utils/utils.d.ts:113


trimSuffix

trimSuffix(string_, unwanted): string

Trims a suffix from a string.

Parameters

NameTypeDescription
string_string-
unwantedstringThe suffix to remove.

Returns

string

The trimmed string.

Description

从字符串中修剪后缀。

Defined in

src/modules/utils/utils.d.ts:122


unHyphenateCss

unHyphenateCss(propertyName): string

Converts a hyphenated CSS property name into a camel case one.

Parameters

NameType
propertyNamestring

Returns

string

The converted CSS property name.

Description

将连字符分隔的 CSS 属性名称转换为驼峰式。

Defined in

src/modules/utils/utils.d.ts:413


unescapeLineBreaks

unescapeLineBreaks(s): string

Unescapes line breaks.

Parameters

NameTypeDescription
sstringThe string to unescape.

Returns

string

The unescaped string.

Description

取消转义换行符。

Defined in

src/modules/utils/utils.d.ts:348


warning

warning(text): void

Display a warning, in colour if we're on a terminal.

Parameters

NameTypeDescription
textstringThe text to display.

Returns

void

Description

在终端上显示警告,如果在终端上则以颜色显示。

Defined in

src/modules/utils/utils.d.ts:38