Commonly shared utility functions between official FormKit packages.
You can add this package by using npm install @formkit/utils
or yarn add @formkit/utils
.
Performs a recursive Object.assign
-like operation.
a
— An object to be assigned.b
— An object to get values from.A & B
This converts kebab-case to camelCase. It ONLY converts from kebab to camel.
str
— String to be camel cased.string
Perform a recursive clone on a given object. Only intended to be used for simple objects like arrays and POJOs.
obj
— Object to be cloned.explicit
— Array of items to be explicity cloned.T
Clones anything. If the item is scalar, no worries, it passes it back. If it is an object, it performs a (fast/loose) clone operation.
obj
— The value to be cloned.T
Given 2 arrays, return them as a combined array with no duplicates.
arr1
— First array.arr2
— Second array.any[]
Determines if a value is empty or not.
value
— The value to check if it's empty.boolean
Compare two values for equality, optionally at depth.
valA
— First value.valB
— Second value.deep
— If it will compare deeply if it's an object.explicit
— An array of keys to explicity check.boolean
Escape a string for use in regular expressions.
string
— String to be escaped.string
Return a new (shallow) object with any desired props removed.
obj
— The starting object.toRemove
— The array of properties to remove. Accepts strings or regular expressions.Record<string, any>
Recursively merge data from additional into original returning a new object.
original
— The original array.additional
— The array to merge.extendArrays
— If it will extend/concatenate array values instead of replacing them.ignoreUndefined
— If it will preserve values from the original object even if the additional object has those values set to undefined.Record<string, any> | string | null
Get a specific value via dot notation.
obj
— An object to fetch data from.addr
— An "address" in dot notation.unknown
Checks if the given property exists on the given object.
obj
— An object to check.property
— The property to check.boolean
Defines an object as an initial value.
obj
— Object to be added an initial value.T & { __init?: true }
Checks if an object is a simple array or record.
o
— Value to be checked.boolean
Attempts to determine if an object is a POJO (Plain Old JavaScript Object). Mostly lifted from is-plain-object: https://github.com/jonschlinkert/is-plain-object Copyright (c) 2014-2017, Jon Schlinkert.
o
— The value to be checked.boolean
Determine if the given string is fully quoted.
str
— The string to check.boolean
Determines if an object is an object.
o
— The value to be checked.boolean
This converts camel-case to kebab case. It ONLY converts from camel to kebab.
str
— String to be kebabed.string
Filters out values from an object that should not be considered "props" of a core node, like "value" and "name".
sets
— The arrays to get values filtered out of.Record<string, any>
Given a FormKit input type, returns the correct lowerCased() type.
type
— String to return to check for correct type'list' | 'group' | 'input'
Extracts a set of keys from a given object. Importantly, this will extract values even if they are not set on the original object — they will just have an undefined value.
obj
— The object to get values from.include
— The array of items to get.Record<string, any>
Parse a string for comma-separated arguments.
str
— String to parse arguments from.string[]
Given a string date format, return a regex to match against.
format
— String to be transformed to RegExp.RegExp
Remove extra escape characters.
str
— String to remove extra escape characters from.string
Creates a new set of the specified type and uses the values from an Array or an existing Set.
items
— An array or a Set.Set<T>
Shallowly clones the given object.
obj
— Object to be shallowly cloned.explicit
— The array of keys to be explicity cloned.T
Turn any string into a URL/DOM-safe string.
str
— String to be slugified to a URL-safe string.
string
Spreads an object or an array, otherwise returns the same value.
obj
— The object to be spread.explicit
— The array of items to be explicity spread.T
Generates a random string.
string
Determines if the value of a prop that is either present (true) or not present (undefined). For example, the prop disabled should disable by just existing, but what if it is set to the string "false" — then it should not be disabled.
value
— Value to check for undefined.true | undefined
The date token strings that can be used for date formatting.