breeze-client / core
Variable: core
constcore:object
Defined in: src/core/core.ts:673
Utility functions that Breeze 2.x exposed as breeze.core, kept for code written against 2.x. Several now just call a JavaScript built-in; those are marked deprecated and name it.
Type Declaration
arrayAddItemUnique
arrayAddItemUnique: <
T>(array,item) =>void
Pushes item onto array unless the array already holds it.
Add item if not already in array
Type Parameters
T
T
Parameters
array
T[]
item
T
Returns
void
arrayEquals
arrayEquals: (
a1,a2,equalsFn?) =>boolean
Whether two arrays have the same length and equal elements, compared with === or with equalsFn if given. An element that is itself an array is compared element by element, with ===. False if either array is null or undefined.
Parameters
a1
any[]
a2
any[]
equalsFn?
(x1, x2) => boolean
Returns
boolean
arrayFirst
arrayFirst: <
T>(array,predicate) =>T
The first element for which predicate is true, or null. Like Array.prototype.find, except for returning null rather than undefined.
Return first element matching predicate
Type Parameters
T
T
Parameters
array
T[]
predicate
Predicate<any>
Returns
T
arrayFlatMap
arrayFlatMap:
object
Deprecated
Use arr.flatMap(fn), which this now calls.
arrayIndexOf
arrayIndexOf: <
T>(array,predicate) =>number
The index of the first element for which predicate is true, or -1. The same as Array.prototype.findIndex.
Return index of first element matching predicate
Type Parameters
T
T
Parameters
array
T[]
predicate
Predicate<any>
Returns
number
arrayRemoveItem
arrayRemoveItem: <
T>(array,predicateOrItem,shouldRemoveMultiple?) =>boolean
Removes from array, in place, either predicateOrItem itself or the elements that predicateOrItem, a function, matches. Removes only the last match unless shouldRemoveMultiple is true. Returns whether anything was removed.
Remove items from the array
Type Parameters
T
T
Parameters
array
T[]
predicateOrItem
T | Predicate<T>
item to remove, or function to determine matching item
shouldRemoveMultiple?
boolean
true to keep removing after first match, false otherwise
Returns
boolean
arraySlice
arraySlice:
object
Deprecated
Use arr.slice(start, end), or Array.prototype.slice.call(arrayLike) for an arguments object. That is what this now does.
arrayZip
arrayZip: (
a1,a2,callback) =>any[]
Combines the elements of two arrays pairwise with callback. The result is as long as the shorter array.
Combine array elements using the callback. Returns array with length == min(a1.length, a2.length)
Parameters
a1
any[]
a2
any[]
callback
(x1, x2) => any
Returns
any[]
durationToSeconds
durationToSeconds: (
duration) =>number
Converts an ISO 8601 duration such as PT1H30M to seconds, counting a year as 360 days and a month as 30. Throws for a string that is not a duration.
Parameters
duration
string
Returns
number
extend
extend: (
target,source?,propNames?) =>Object
Copies properties from source onto target and returns target: all of source's own enumerable properties, or only propNames when given. A shallow copy, like Object.assign.
Copy properties from source to target. Returns target.
Parameters
target
Object
source?
Object
propNames?
string[]
Returns
Object
formatString
formatString:
object
Replaces %1, %2, ... in str with the arguments that follow it: formatString('a %1 and a %2', 'cat', 'dog') is 'a cat and a dog'.
getMapArray
getMapArray: <
K,V>(map,key) =>V[]
The array stored in map under key, after storing an empty one there if there was none.
Returns the array stored under key, creating it if absent.
Type Parameters
K
K
V
V
Parameters
map
Map<K, V[]>
key
K
Returns
V[]
getOwnPropertyValues
getOwnPropertyValues: (
source) =>any[]
The values of an object's own enumerable properties. Object.values(obj), except that null or undefined gives [].
Return an array of property values from source
Parameters
source
Object
Returns
any[]
getPropertyDescriptor
getPropertyDescriptor: (
obj,propertyName) =>PropertyDescriptor|undefined=getPropDescriptor
The descriptor of propertyName on obj or, failing that, on the nearest prototype that has it; undefined if none does. Unlike Object.getOwnPropertyDescriptor, it searches the prototype chain.
Parameters
obj
Object
propertyName
string
Returns
PropertyDescriptor | undefined
getUuid
getUuid:
object
Deprecated
Use crypto.randomUUID(). This calls it where it exists and falls back to a Math.random() implementation in a browser outside a secure context, where it does not.
hasOwnProperty
hasOwnProperty:
object
Deprecated
Use Object.hasOwn(obj, key), which this now calls.
identity
identity: (
x) =>any
Returns its argument.
Parameters
x
any
Returns
any
isDate
isDate: (
o) =>boolean
Whether o is a Date holding a valid time - not an Invalid Date.
Parameters
o
any
Returns
boolean
isDateString
isDateString: (
s) =>boolean
Whether s is an ISO 8601 date-time with a time zone, such as 2024-05-01T10:30:00Z or 2024-05-01T10:30:00.5+02:00. A string with no time zone, or a date with no time, is not.
Parameters
s
string
Returns
boolean
isDuration
isDuration: (
value) =>boolean
Whether value is a string that looks like an ISO 8601 duration, such as PT1H. A quick check of its shape, not a full parse - see core.durationToSeconds.
Parameters
value
any
Returns
boolean
isEmpty
isEmpty: (
obj) =>boolean
Whether obj is null, undefined, or has no own enumerable properties.
Parameters
obj
any
Returns
boolean
isFunction
isFunction: (
o) =>boolean
Whether o is an ordinary function. False for async and generator functions: it checks Object.prototype.toString, which names those differently.
Parameters
o
any
Returns
boolean
isGuid
isGuid: (
value) =>boolean
Whether value is a string in GUID form: 8-4-4-4-12 hexadecimal digits.
Parameters
value
any
Returns
boolean
isSettable
isSettable: (
obj,propertyName) =>boolean
Whether obj[propertyName] can be assigned: true if no object on the prototype chain defines it, or if its descriptor is writable or has a setter.
Parameters
obj
Object
propertyName
string
Returns
boolean
map
map: <
T>(items,fn,includeNull?) =>any
Array.prototype.map that also takes a single value, which it passes to fn and returns the result of. Null or undefined is returned as is. With includeNull false, an element whose result is null or undefined is left as a hole in the returned array.
a version of Array.map that doesn't require an array, i.e. works on arrays and scalars.
Type Parameters
T
T
Parameters
items
T | T[]
fn
(v, ix?) => any
includeNull?
boolean
Returns
any
memoize
memoize: (
fn) =>any
Wraps fn so that it runs once for each distinct set of arguments and afterwards returns the stored result. Arguments are keyed by value, objects by their JSON.stringify. The results are stored on fn itself and never released.
Remember & return the value of fn() when it was called with its current args
Parameters
fn
any
Returns
any
noop
noop: () =>
void
Does nothing.
Returns
void
objectFirst
objectFirst: (
obj,kvPredicate) => {key:string;value:any; } |null
The first of an object's own enumerable properties for which kvPredicate(key, value) is true, as { key, value }; null if there is none.
Parameters
obj
Object
kvPredicate
(key, val) => boolean
Returns
Type Literal
{ key: string; value: any; }
key
key:
string
The property's name.
value
value:
any
The property's value.
null
objectForEach
objectForEach: (
obj,kvFn) =>void
Calls kvFn(key, value) for each of an object's own enumerable properties. Does nothing for null or undefined.
Parameters
obj
Object
kvFn
(key, val) => any
Returns
void
objectMap
objectMap: (
obj,kvFn?) =>any[]
Calls kvFn(key, value) for each of an object's own enumerable properties and returns the results, leaving out any that are undefined. Without kvFn, returns the values.
Parameters
obj
Object
kvFn?
(key, val) => any
Returns
any[]
pluck
pluck: (
propertyName) => (obj) =>any
A function that returns an object's propertyName: people.map(core.pluck('firstName')).
can be used like persons.map(pluck("firstName"))
Parameters
propertyName
any
Returns
(obj) => any
propEq
propEq: (
propertyName,value) => (obj) =>boolean
A predicate that is true for an object whose propertyName is === value: people.filter(core.propEq('firstName', 'John')).
can be used like: persons.filter(propEq("firstName", "John"))
Parameters
propertyName
string
value
any
Returns
(obj) => boolean
propsEq
propsEq: (
property1Name,property2Name,value) => (obj) =>boolean
A predicate that is true for an object whose property1Name or property2Name is === value.
can be used like: persons.filter(propEq("firstName", "FirstName", "John"))
Parameters
property1Name
string
property2Name
string
value
any
Returns
(obj) => boolean
resolveProperties
resolveProperties: (
sources,propertyNames) =>any
An object with each of propertyNames taken from the first of sources in which it is not undefined. Breeze uses it to combine a query's settings with its manager's and the defaults, in QueryOptions.resolve and DataService.resolve.
Resolves the values of a list of properties by checking each property in multiple sources until a value is found.
Parameters
sources
Object[]
propertyNames
string[]
Returns
any
setAsDefault
setAsDefault: (
target,ctor) =>any
Creates an instance of ctor from target, fills in whatever it leaves unset from the current ctor.defaultInstance, and makes that the new ctor.defaultInstance. Returns target. The setAsDefault() methods of QueryOptions, SaveOptions, NamingConvention and LocalQueryComparisonOptions are built on it.
Set ctor.defaultInstance to an instance of ctor with properties from target. We want to insure that the object returned by ctor.defaultInstance is always immutable Use 'target' as the primary template for the ctor.defaultInstance; Use current 'ctor.defaultInstance' as the template for any missing properties creates a new instance for ctor.defaultInstance returns target unchanged
Parameters
target
Object
ctor
{(...args): any; defaultInstance?: any; }
defaultInstance?
any
Returns
any
stringEndsWith
stringEndsWith:
object
Deprecated
Use str.endsWith(suffix), with the same caveat about nulls as core.stringStartsWith.
strings
strings:
object
Text that Breeze uses in its error messages.
strings.TO_TYPE
TO_TYPE:
string="Add 'EntityQuery.toType()' to your query, or call 'MetadataStore.setEntityTypeForResourceName()' to register an EntityType for this resourceName."
Advice appended to errors about a query whose entity type Breeze cannot determine.
stringStartsWith
stringStartsWith:
object
Deprecated
Use str.startsWith(prefix). Not quite the same: this answers false for a null string and true for a null prefix, where the built-in throws and compares against the text "null" respectively. Guard the null yourself.
toArray
toArray: (
item) =>any[]
[] for null or undefined, the array itself for an array, and [item] for anything else.
Parameters
item
any
Returns
any[]
toJson
toJson: (
source,template,target) =>Object
Copies properties of source to target, a new object by default, as template directs, and returns target. Each key of template names a property to copy; a key such as 'a,b' also accepts b as another name for a. The template's value is the property's default: a property equal to it (by ==), undefined, or an empty array is left out. If the template's value is a function, it converts the property's value instead, and a BreezeEnum is written as its name. Breeze's metadata classes build their toJSON output with it.
'source' is an object that will be transformed into another 'template' is a map where the keys: are the keys to return if a key contains ','s then the key is treated as a delimited string with first of the keys being the key to return and the others all valid aliases for this key 'values' are either 1) the 'default' value of the key 2) a function that takes in the source value and should return the value to set The value from the source is then set on the target, after first passing thru the fn, if provided, UNLESS: 1) it is the default value 2) it is undefined ( nulls WILL be set) 'target' is optional
- if it exists then properties of the target will be set ( overwritten if the exist)
- if it does not exist then a new object will be created as filled. 'target is returned.
Parameters
source
Object
template
Object
target?
Object = {}
Returns
Object
toJSONSafe
toJSONSafe: (
obj,replacer?) =>any
A copy of obj that JSON.stringify can serialize even when the object graph has cycles: a reference back to an object already being copied is left out. Uses an object's own toJSON when it has one, leaves out functions, and passes each property through replacer when given, leaving out any it returns undefined for.
Safely perform toJSON logic on objects with cycles.
Parameters
obj
any
replacer?
(prop, value) => any
Returns
any
toJSONSafeReplacer
toJSONSafeReplacer: (
prop,val) =>any
A replacer for core.toJSONSafe that leaves out an entity's Breeze members - entityAspect, complexAspect, entityType, complexType, getProperty, setProperty and constructor - and any property whose name starts with _ or $. Breeze serializes unmapped property values with it.
Replacer function for toJSONSafe, when serializing entities. Excludes entityAspect and other internal properties.
Parameters
prop
string
val
any
Returns
any
updateWithDefaults
updateWithDefaults: (
target,defaults) =>any
Copies each property of defaults onto target where target's is undefined, and returns target.
Copy properties from defaults iff undefined on target. Returns target.
Parameters
target
Object
defaults
Object
Returns
any
using
using: (
obj,property,tempValue,fn) =>any
Sets obj[property] to tempValue, calls fn, then restores the original value, deleting the property if it had none, whether or not fn throws. Returns what fn returns.
Execute fn while obj has tempValue for property
Parameters
obj
Object
property
string
tempValue
any
fn
() => any
Returns
any
wrapExecution
wrapExecution: (
startFn,endFn,fn) =>any
Calls startFn(), then fn(), then endFn(state) with what startFn returned, whether or not fn throws. If it throws and the state is an object, the error is set on state.error first. Returns what fn returns.
Call state = startFn(), call fn(), call endFn(state)
Parameters
startFn
() => any
endFn
(state) => any
fn
() => any
Returns
any