Skip to content

@vttforge/types / FoundryUtils

Interface: FoundryUtils ​

The foundry.utils namespace.

Grouped the way the API reference groups it: objects, strings and HTML, documents and UUIDs, classes, geometry, timing.

Properties ​

BitMask ​

readonly BitMask: AnyClass


Collection ​

readonly Collection: AnyClass

The classes the namespace carries. Typed as constructors rather than described member by member: a consumer that subclasses one of these is past what this package covers.


Color ​

readonly Color: AnyClass


EventEmitterMixin ​

readonly EventEmitterMixin: (base) => AnyClass

Parameters ​

base ​

AnyClass

Returns ​

AnyClass


HttpError ​

readonly HttpError: AnyClass


IterableWeakMap ​

readonly IterableWeakMap: AnyClass


IterableWeakSet ​

readonly IterableWeakSet: AnyClass


Semaphore ​

readonly Semaphore: AnyClass


StringNode ​

readonly StringNode: AnyClass


StringTree ​

readonly StringTree: AnyClass


WordTree ​

readonly WordTree: AnyClass

Methods ​

applyDataOperators() ​

applyDataOperators<T>(obj): T

Resolve ForcedDeletion and ForcedReplacement values inside an object.

Type Parameters ​

T ​

T

Parameters ​

obj ​

T

Returns ​

T


benchmark() ​

benchmark(func, iterations, ...args): Promise<void>

Parameters ​

func ​

(...args) => unknown

iterations ​

number

args ​

...readonly unknown[]

Returns ​

Promise<void>


buildRelativeUuid() ​

buildRelativeUuid(target, origin): string

Parameters ​

target ​

unknown

origin ​

unknown

Returns ​

string


buildUuid() ​

buildUuid(context): string | null

Parameters ​

context ​
documentName? ​

string

id ​

string

pack? ​

string | null

parent? ​

unknown

Returns ​

string | null


circleCircleIntersects() ​

circleCircleIntersects(x0, y0, r0, x1, y1, r1): boolean

Parameters ​

x0 ​

number

y0 ​

number

r0 ​

number

x1 ​

number

y1 ​

number

r1 ​

number

Returns ​

boolean


cleanHTML() ​

cleanHTML(raw): string

Close unbalanced tags and strip what a sheet should not carry.

Parameters ​

raw ​

string

Returns ​

string


closestPointToPath() ​

closestPointToPath(c, points, close): Point

Parameters ​

c ​

Point

points ​

readonly number[] | readonly Point[]

close ​

boolean

Returns ​

Point


closestPointToSegment() ​

closestPointToSegment(c, a, b): Point

Parameters ​

c ​

Point

a ​

Point

b ​

Point

Returns ​

Point


debounce() ​

debounce<A>(callback, delay): (...args) => void & object

Type Parameters ​

A ​

A extends readonly unknown[]

Parameters ​

callback ​

(...args) => unknown

delay ​

number

Returns ​

(...args) => void & object


debouncedReload() ​

debouncedReload(): void

Returns ​

void


deepClone() ​

deepClone<T>(original, options?): T

Type Parameters ​

T ​

T

Parameters ​

original ​

T

options? ​
prune? ​

boolean

strict? ​

boolean

Returns ​

T


deepFreeze() ​

deepFreeze<T>(obj, options?): Readonly<T>

Type Parameters ​

T ​

T

Parameters ​

obj ​

T

options? ​
strict? ​

boolean

Returns ​

Readonly<T>


deepSeal() ​

deepSeal<T>(obj, options?): T

Type Parameters ​

T ​

T

Parameters ​

obj ​

T

options? ​
strict? ​

boolean

Returns ​

T


deleteProperty() ​

deleteProperty(object, key): boolean

Parameters ​

object ​

object

key ​

string

Returns ​

boolean


diffObject() ​

diffObject(original, other, options?): Record<string, unknown>

Parameters ​

original ​

object

other ​

object

options? ​

DiffObjectOptions

Returns ​

Record<string, unknown>


duplicate() ​

duplicate<T>(original): T

deepClone is faster where it applies.

Type Parameters ​

T ​

T

Parameters ​

original ​

T

Returns ​

T


encodeURL() ​

encodeURL(path): string

Parameters ​

path ​

string

Returns ​

string


equals() ​

equals(a, b): boolean

Replaces objectsEqual, which is deprecated.

Parameters ​

a ​

unknown

b ​

unknown

Returns ​

boolean


escapeHTML() ​

escapeHTML(value): string

Parameters ​

value ​

unknown

Returns ​

string


expandObject() ​

expandObject(obj): Record<string, unknown>

Parameters ​

obj ​

object

Returns ​

Record<string, unknown>


expandObjectInPlace() ​

expandObjectInPlace(data, options?): boolean

Expands dot keys in place. Returns whether anything expanded.

Parameters ​

data ​

object

options? ​
shallow? ​

boolean

Returns ​

boolean


fetchResource() ​

fetchResource(src, options?): Promise<Blob>

Parameters ​

src ​

string

options? ​
bustCache? ​

boolean

Returns ​

Promise<Blob>


filterObject() ​

filterObject(source, template, options?): Record<string, unknown>

Parameters ​

source ​

object

template ​

object

options? ​
templateValues? ​

boolean

Returns ​

Record<string, unknown>


flattenObject() ​

flattenObject(obj): Record<string, unknown>

Parameters ​

obj ​

object

Returns ​

Record<string, unknown>


formatFileSize() ​

formatFileSize(size, options?): string

Parameters ​

size ​

number

options? ​
base? ​

2 | 10

decimalPlaces? ​

number

Returns ​

string


fromUuid() ​

fromUuid<T>(uuid, options?): Promise<T | null>

Type Parameters ​

T ​

T = unknown

Parameters ​

uuid ​

string

options? ​
invalid? ​

boolean

relative? ​

unknown

Returns ​

Promise<T | null>


fromUuidSync() ​

fromUuidSync<T>(uuid, options?): T | null

Type Parameters ​

T ​

T = unknown

Parameters ​

uuid ​

string

options? ​
invalid? ​

boolean

relative? ​

unknown

strict? ​

boolean

Returns ​

T | null


getCacheBustURL() ​

getCacheBustURL(src): string | false

Parameters ​

src ​

string

Returns ​

string | false


getDefiningClass() ​

getDefiningClass(obj, property): AnyClass

Parameters ​

obj ​

object | AnyClass

property ​

string

Returns ​

AnyClass


getDocumentClass() ​

getDocumentClass(documentName): AnyClass | undefined

Parameters ​

documentName ​

string

Returns ​

AnyClass | undefined


getParentClasses() ​

getParentClasses(cls): AnyClass[]

Parameters ​

cls ​

AnyClass

Returns ​

AnyClass[]


getPlaceableObjectClass() ​

getPlaceableObjectClass(documentName): AnyClass | undefined

Parameters ​

documentName ​

string

Returns ​

AnyClass | undefined


getProperty() ​

getProperty<T>(object, key): T | undefined

Type Parameters ​

T ​

T = unknown

Parameters ​

object ​

object

key ​

string

Returns ​

T | undefined


getRoute() ​

getRoute(path, options?): string

Parameters ​

path ​

string

options? ​
prefix? ​

string | null

Returns ​

string


getType() ​

getType(variable): string

Parameters ​

variable ​

unknown

Returns ​

string


hasProperty() ​

hasProperty(object, key): boolean

Parameters ​

object ​

object

key ​

string

Returns ​

boolean


invertObject() ​

invertObject(obj): Record<string, unknown>

Parameters ​

obj ​

object

Returns ​

Record<string, unknown>


isElementInstanceOf() ​

isElementInstanceOf(element, tagOrClass): boolean

Parameters ​

element ​

HTMLElement

tagOrClass ​

string | AnyClass

Returns ​

boolean


isEmpty() ​

isEmpty(value): boolean

Parameters ​

value ​

unknown

Returns ​

boolean


isNewerVersion() ​

isNewerVersion(v1, v0, options?): boolean

Parameters ​

v1 ​

string | number | null | undefined

v0 ​

string | number | null | undefined

options? ​
majorOnly? ​

boolean

Returns ​

boolean


isPlainObject() ​

isPlainObject(value): boolean

Parameters ​

value ​

unknown

Returns ​

boolean


isSubclass() ​

isSubclass(cls, parent): boolean

Parameters ​

cls ​

AnyClass

parent ​

AnyClass

Returns ​

boolean


iterateEntries() ​

iterateEntries(obj): IterableIterator<[string, unknown]>

Parameters ​

obj ​

object

Returns ​

IterableIterator<[string, unknown]>


iterateKeys() ​

iterateKeys(obj): IterableIterator<string>

Parameters ​

obj ​

object

Returns ​

IterableIterator<string>


iterateValues() ​

iterateValues(obj): IterableIterator<unknown>

Parameters ​

obj ​

object

Returns ​

IterableIterator<unknown>


lineCircleIntersection() ​

lineCircleIntersection(a, b, center, radius, epsilon?): LineCircleIntersection

Parameters ​

a ​

Point

b ​

Point

center ​

Point

radius ​

number

epsilon? ​

number

Returns ​

LineCircleIntersection


lineLineIntersection() ​

lineLineIntersection(a, b, c, d, options?): LineIntersection | null

Parameters ​

a ​

Point

b ​

Point

c ​

Point

d ​

Point

options? ​
t1? ​

boolean

Returns ​

LineIntersection | null


lineSegmentIntersection() ​

lineSegmentIntersection(a, b, c, d, epsilon?): LineIntersection | null

Parameters ​

a ​

Point

b ​

Point

c ​

Point

d ​

Point

epsilon? ​

number

Returns ​

LineIntersection | null


lineSegmentIntersects() ​

lineSegmentIntersects(a, b, c, d): boolean

Parameters ​

a ​

Point

b ​

Point

c ​

Point

d ​

Point

Returns ​

boolean


logCompatibilityWarning() ​

logCompatibilityWarning(message, options?): void

Parameters ​

message ​

string

options? ​
once? ​

boolean

since? ​

string | number

until? ​

string | number

Returns ​

void


mergeObject() ​

mergeObject<T>(original, other?, options?): T & Record<string, unknown>

Type Parameters ​

T ​

T extends object

Parameters ​

original ​

T

other? ​

object

options? ​

MergeObjectOptions

Returns ​

T & Record<string, unknown>


objectEntries() ​

objectEntries(obj): IterableIterator<[string, unknown]>

Parameters ​

obj ​

object

Returns ​

IterableIterator<[string, unknown]>


objectKeys() ​

objectKeys(obj): IterableIterator<string>

Parameters ​

obj ​

object

Returns ​

IterableIterator<string>


objectValues() ​

objectValues(obj): IterableIterator<unknown>

Parameters ​

obj ​

object

Returns ​

IterableIterator<unknown>


orient2dFast() ​

orient2dFast(a, b, c): number

Parameters ​

a ​

Point

b ​

Point

c ​

Point

Returns ​

number


parseHTML() ​

parseHTML(htmlString): HTMLElement | HTMLCollection | null

Parameters ​

htmlString ​

string

Returns ​

HTMLElement | HTMLCollection | null


parseS3URL() ​

parseS3URL(key): ParsedS3URL

Parameters ​

key ​

string

Returns ​

ParsedS3URL


parseUuid() ​

parseUuid(uuid, options?): ResolvedUUID | null

Parameters ​

uuid ​

string

options? ​
relative? ​

unknown

Returns ​

ResolvedUUID | null


pathCircleIntersects() ​

pathCircleIntersects(points, close, center, radius): boolean

Parameters ​

points ​

readonly number[] | readonly Point[]

close ​

boolean

center ​

Point

radius ​

number

Returns ​

boolean


performIntegerSort() ​

performIntegerSort<T>(source, options?): SortUpdate<T>[]

Type Parameters ​

T ​

T extends object

Parameters ​

source ​

T

options? ​

SortOptions<T>

Returns ​

SortUpdate<T>[]


polygonCentroid() ​

polygonCentroid(points): Point

Parameters ​

points ​

readonly number[] | readonly Point[]

Returns ​

Point


quadraticIntersection() ​

quadraticIntersection(p0, p1, center, radius, epsilon?): LineIntersection[]

Parameters ​

p0 ​

Point

p1 ​

Point

center ​

Point

radius ​

number

epsilon? ​

number

Returns ​

LineIntersection[]


randomID() ​

randomID(length?): string

Parameters ​

length? ​

number

Returns ​

string


readTextFromFile() ​

readTextFromFile(file): Promise<string>

Parameters ​

file ​

File

Returns ​

Promise<string>


saveDataToFile() ​

saveDataToFile(data, type, filename): void

Parameters ​

data ​

string

type ​

string

filename ​

string

Returns ​

void


setProperty() ​

setProperty(object, key, value): boolean

Parameters ​

object ​

object

key ​

string

value ​

unknown

Returns ​

boolean


threadLock() ​

threadLock(ms, debug?): Promise<void>

Locks the thread. A debugging aid, never something to ship.

Parameters ​

ms ​

number

debug? ​

boolean

Returns ​

Promise<void>


throttle() ​

throttle<A>(callback, delay): (...args) => void

Type Parameters ​

A ​

A extends readonly unknown[]

Parameters ​

callback ​

(...args) => unknown

delay ​

number

Returns ​

(...args) => void


timeSince() ​

timeSince(timeStamp): string

Relative to now, in words.

Parameters ​

timeStamp ​

string | Date

Returns ​

string


unescapeHTML() ​

unescapeHTML(value): string

Parameters ​

value ​

string

Returns ​

string

MIT licensed.