@supercat1337/utils
v1.0.1
Published
Utilities for binding reactive variables to DOM elements and other usefull functions
Downloads
1
Readme
- @supercat1337/utils
- Classes
- Functions
- Function: DOMReady()
- Function: bindToAttr()
- Function: bindToCheckboxChecked()
- Function: bindToClass()
- Function: bindToDisabled()
- Function: bindToHtml()
- Function: bindToInputValue()
- Function: bindToList()
- Function: bindToListLength()
- Function: bindToProperty()
- Function: bindToShow()
- Function: bindToText()
- Function: createSingletonFetch()
- Function: escapeHtml()
- Function: fetchRetry()
- Function: getDiffs()
- Function: getListItem()
- Function: getListItemIndex()
- Function: memoize()
- Function: selectRefs()
- Function: selectRefsExtended()
- Function: walkDomScope()
- Type Aliases
@supercat1337/utils • Docs
@supercat1337/utils
Classes
Type Aliases
Functions
- DOMReady
- bindToAttr
- bindToCheckboxChecked
- bindToClass
- bindToDisabled
- bindToHtml
- bindToInputValue
- bindToList
- bindToListLength
- bindToProperty
- bindToShow
- bindToText
- createSingletonFetch
- escapeHtml
- fetchRetry
- getDiffs
- getListItem
- getListItemIndex
- memoize
- selectRefs
- selectRefsExtended
- walkDomScope
Classes
@supercat1337/utils • Docs
@supercat1337/utils / Chain
Class: Chain
Creates a concurrency chain instance
Export
Chain
Constructors
new Chain()
new Chain():
Chain
Returns
Properties
#private
private
#private:any
completedSuccessfully
completedSuccessfully:
object
__#2@#private
__#2@#private:
any
name
readonly
name:string
store
readonly
store:Store
value
value:
any
clearSubscribers()
Returns
void
hasSubscribers()
Returns
boolean
setCompareFunction()
Parameters
• func_or_null
Returns
boolean
subscribe()
Parameters
• callback
• debounce_time?: number
Returns
Unsubscriber
isRunning
isRunning:
object
__#2@#private
__#2@#private:
any
name
readonly
name:string
store
readonly
store:Store
value
value:
any
clearSubscribers()
Returns
void
hasSubscribers()
Returns
boolean
setCompareFunction()
Parameters
• func_or_null
Returns
boolean
subscribe()
Parameters
• callback
• debounce_time?: number
Returns
Unsubscriber
returnValue
returnValue:
object
__#2@#private
__#2@#private:
any
name
readonly
name:string
store
readonly
store:Store
value
value:
any
clearSubscribers()
Returns
void
hasSubscribers()
Returns
boolean
setCompareFunction()
Parameters
• func_or_null
Returns
boolean
subscribe()
Parameters
• callback
• debounce_time?: number
Returns
Unsubscriber
Accessors
abortController
get
abortController():AbortController
Returns
AbortController
store
get
store():Store
Returns
Store
Methods
cancel()
cancel():
void
Returns
void
complete()
complete(
return_value
?):void
Parameters
• return_value?: any
Returns
void
getCtx()
getCtx():
void
Returns
void
run()
run(
ctx
?):Promise
<any
>
Parameters
• ctx?
Returns
Promise
<any
>
then()
then(
task
):this
Parameters
• task: Task
Returns
this
Functions
@supercat1337/utils • Docs
@supercat1337/utils / DOMReady
Function: DOMReady()
DOMReady(
callback
):void
Execute callback after the DOM is loaded
Parameters
• callback
Returns
void
@supercat1337/utils • Docs
@supercat1337/utils / bindToAttr
Function: bindToAttr()
bindToAttr(
reactive_item
,element
,attribute_name
,custom_value_converter
?,debounce_time
?):Unsubscriber
Binds the value of a reactive variable to the element's attribute
Parameters
• reactive_item: Atom
| Computed
• element: HTMLElement
• attribute_name: string
• custom_value_converter?
• debounce_time?: number
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToCheckboxChecked
Function: bindToCheckboxChecked()
bindToCheckboxChecked(
reactive_item
,element
,debounce_time
?):Unsubscriber
Synchronizes the value of a reactive variable to the checkbox's "checked" property and vice versa
Parameters
• reactive_item: Atom
• element: HTMLInputElement
• debounce_time?: number
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToClass
Function: bindToClass()
bindToClass(
reactive_item
,element
,custom_value_converter
?,debounce_time
?):Unsubscriber
Binds the value of a reactive variable to the element's "className" property
Parameters
• reactive_item: Atom
| Computed
• element: HTMLElement
• custom_value_converter?
• debounce_time?: number
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToDisabled
Function: bindToDisabled()
bindToDisabled(
reactive_item
,element
,custom_value_converter
?):Unsubscriber
Binds the value of a reactive variable to the element's "disabled" property
Parameters
• reactive_item: Atom
| Computed
• element: HTMLLinkElement
| HTMLInputElement
| HTMLButtonElement
| HTMLFieldSetElement
| HTMLOptGroupElement
| HTMLOptionElement
| HTMLSelectElement
| HTMLStyleElement
| HTMLTextAreaElement
| SVGStyleElement
• custom_value_converter?
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToHtml
Function: bindToHtml()
bindToHtml(
reactive_item
,element
,custom_value_converter
?,debounce_time
?):Unsubscriber
Binds the value of a reactive variable to the element's "innerHTML" property
Parameters
• reactive_item: Atom
| Computed
• element: HTMLElement
• custom_value_converter?
• debounce_time?: number
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToInputValue
Function: bindToInputValue()
bindToInputValue(
reactive_item
,element
,debounce_time
?,lazy
?):Unsubscriber
Synchronizes the value of a reactive variable to the input's "value" property and vice versa
Parameters
• reactive_item: Atom
• element: HTMLInputElement
| HTMLTextAreaElement
• debounce_time?: number
• lazy?: boolean
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToList
Function: bindToList()
bindToList(
reactive_item
,list_element
,item_value_setter
,element_item_creator
?):Unsubscriber
Binds the array-value of a reactive collection to the element
Parameters
• reactive_item: Collection
• list_element: HTMLElement
• item_value_setter: TypeItemValueSetter
• element_item_creator?: TypeItemCreator
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToListLength
Function: bindToListLength()
bindToListLength(
reactive_item
,element
,custom_value_converter
?,debounce_time
?):Unsubscriber
Binds the length of a reactive collection to the element's "innerText" property
Parameters
• reactive_item: Collection
• element: HTMLElement
• custom_value_converter?
• debounce_time?: number
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToProperty
Function: bindToProperty()
bindToProperty(
reactive_item
,element
,property_name
,custom_value_converter
?,debounce_time
?):Unsubscriber
Binds the value of a reactive variable to the element's property
Parameters
• reactive_item: Atom
| Computed
• element: HTMLElement
• property_name: string
• custom_value_converter?
• debounce_time?: number
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToShow
Function: bindToShow()
bindToShow(
reactive_item
,element
,custom_value_converter
?,debounce_time
?,hide_class_name
?):Unsubscriber
Binds the value of a reactive variable to the element's visibility
Parameters
• reactive_item: Atom
| Computed
• element: HTMLElement
• custom_value_converter?
• debounce_time?: number
• hide_class_name?: string
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / bindToText
Function: bindToText()
bindToText(
reactive_item
,element
,custom_value_converter
?,debounce_time
?):Unsubscriber
Binds the value of a reactive variable to the element's "innerText" property
Parameters
• reactive_item: Atom
| Computed
• element: HTMLElement
• custom_value_converter?
• debounce_time?: number
Returns
Unsubscriber
@supercat1337/utils • Docs
@supercat1337/utils / createSingletonFetch
Function: createSingletonFetch()
createSingletonFetch(): (
resource
,options
?) =>Promise
<Response
>
Returns singleton version of function fetch
Returns
Function
Parameters
• resource: RequestInfo
| URL
• options?: RequestInit
Returns
Promise
<Response
>
@supercat1337/utils • Docs
@supercat1337/utils / escapeHtml
Function: escapeHtml()
escapeHtml(
text
):string
Escape string for use in HTML
Parameters
• text: string
Returns
string
@supercat1337/utils • Docs
@supercat1337/utils / fetchRetry
Function: fetchRetry()
fetchRetry(
url
,fetchOptions
?,delay
?,tries
?):Promise
<Response
>
A version of the fetch function that allows you to specify the number of retries if the connection is lost
Parameters
• url: RequestInfo
| URL
• fetchOptions?: RequestInit
• delay?: number
• tries?: number
Returns
Promise
<Response
>
@supercat1337/utils • Docs
@supercat1337/utils / getDiffs
Function: getDiffs()
getDiffs<
T
>(new_object
,old_object
,custom_compare_function
?):{ [key in keyof T]: boolean }
Compares two objects and returns information about their differences
Type parameters
• T extends object
Parameters
• new_object: T
• old_object: any
• custom_compare_function?
Returns
{ [key in keyof T]: boolean }
@supercat1337/utils • Docs
@supercat1337/utils / getListItem
Function: getListItem()
getListItem(
element
,attr_name
?):Element
Returns the list item element by child node
Parameters
• element: HTMLElement
• attr_name?: string
Returns
Element
@supercat1337/utils • Docs
@supercat1337/utils / getListItemIndex
Function: getListItemIndex()
getListItemIndex(
element
):number
Returns the index of the list item element
Parameters
• element: HTMLElement
Returns
number
@supercat1337/utils • Docs
@supercat1337/utils / memoize
Function: memoize()
memoize<
T
>(func
):T
An optimization used to speed up consecutive function calls by caching the result of calls with identical input
Type parameters
• T extends (...args
) => any
Parameters
• func: T
Returns
T
@supercat1337/utils • Docs
@supercat1337/utils / selectRefs
Function: selectRefs()
selectRefs(
root_element
):object
Returns an object of child elements containing the ref attribute
Parameters
• root_element: Node
Returns
object
@supercat1337/utils • Docs
@supercat1337/utils / selectRefsExtended
Function: selectRefsExtended()
selectRefsExtended(
root_element
):object
Parameters
• root_element: Node
Returns
object
refs
refs:
object
Index signature
[key
: string
]: HTMLElement
scopes
scopes:
object
Index signature
[key
: string
]: HTMLElement
@supercat1337/utils • Docs
@supercat1337/utils / walkDomScope
Function: walkDomScope()
walkDomScope(
root_element
,callback
):void
Parameters
• root_element: Node
• callback
Returns
void
Type Aliases
@supercat1337/utils • Docs
@supercat1337/utils / Task
Type alias: Task()
Task: (
previous_result
,ctx
,chain
) =>any
Parameters
• previous_result: any
• ctx
• chain: Chain
Returns
any
@supercat1337/utils • Docs
@supercat1337/utils / TypeItemCreator
Type alias: TypeItemCreator()
TypeItemCreator: (
item_element
?) =>HTMLElement
Parameters
• item_element?: HTMLElement
Returns
HTMLElement
@supercat1337/utils • Docs
@supercat1337/utils / TypeItemValueSetter
Type alias: TypeItemValueSetter()
TypeItemValueSetter: (
item_element
,index
,value
,old_value
,length
) =>void
Parameters
• item_element: HTMLElement
• index: number
• value: any
• old_value: any
• length: number
Returns
void