type

Etc

@Js
const class Etc : Obj

Etc is the utility methods for Haystack.

methods

addArg
compareDis

Given two display strings, return 1, 0, or -1 if a is less than, equal to, or greater than b.

dict0

Empty dict singleton

dict1

Create a Dict with one name/value pair

dict2

Create a Dict with two name/value pairs

dict3

Create a Dict with three name/value pairs

dict4

Create a Dict with four name/value pairs

dict5

Create a Dict with five name/value pairs

dict6

Create a Dict with six name/value pairs

dictAll

Return if all of the tag name/value pairs match the given function.

dictAny

Return if any of the tag name/value pairs match the given function.

dictEq

Return if two dicts are equal with same name/value pairs.

dictFindAll

Return a new Dict containing the name/value pairs for which f returns true.

dictHashKey

Construct an object which wraps a dict and is suitable to use for a hash key in a Map.

dictMap

Apply the given map function to each name/value pair to construct a new Dict.

dictMerge

Add/set all the name/value pairs in a with those defined in b.

dictNames

Get a read/write list of the dict's name keys.

dictRemove

Remove a name/val pair from an exisiting dict, or if the name isn't found then return original dict.

dictRemoveAll

Remove all names from the given dict.

dictRename

Rename given name if its defined in the dict, otherwise return original.

dictSet

Set a name/val pair in an existing dict or d is null then create a new dict with given name/val pair.

dictToDis

Given a dict, attempt to find the best display string

dictToMap

Convert a Dict to a read/write map.

dictVals

Get all the non-null values mapped by a dictionary.

dictsNames

Given a list of dictionaries, find all the common names used.

discretePeriods

Iterate a discrete period string formatted in base64.

emptyDict

Get the emtpy Dict instance.

gridFlatten

Flatten a list of grids into a single grid.

isKindName

Return if the given string is a legal kind name

isTagName

Return if the given string is a legal tag name

macro

Process macro pattern with given scope of variable name/value pairs.

macroVars

Return the list of variable tag names used in the given macro pattern.

makeDict

Make a Dict instance where val is one of the following

makeDict1

Make a Dict with one name/value pair.

makeDict2

Make a Dict with two name/value pairs.

makeDict3

Make a Dict with three name/value pairs.

makeDict4

Make a Dict with four name/value pairs.

makeDict5

Make a Dict with five name/value pairs.

makeDict6

Make a Dict with six name/value pairs.

makeDictGrid

Construct a grid for a Dict row.

makeDicts

Make a list of Dict instances using makeDict.

makeDictsGrid

Construct a grid for a list of Dict rows.

makeEmptyGrid

Construct an empty grid with just the given grid level meta-data.

makeErrGrid

Construct a grid for an error response.

makeListGrid

Construct a grid with one column for a list.

makeListsGrid

Construct a grid for a list of rows, where each row is a list of cells.

makeMapGrid

Convenience for makeDictGrid

makeMapsGrid

Convenience for makeDictsGrid

relDis

Get a relative display name.

tagToLocale

Get the localized string for the given tag name for the current locale.

toDateSpan

Coerce an object to a DateSpan

toErrMeta

Map an exception to its standard tags

toGrid

Coerce a value to a Grid

toId

Coerce a value to a Ref identifier

toIds

Coerce a value to a list of Ref identifiers

toRec

Coerce a value to a record Dict

toRecs

Coerce a value to a list of record Dicts

toSpan

Coerce an object to a Span with optional timezone

toTagName

Take an arbitrary string and convert into a safe tag name.

Slot Details

addArg

static Void addArg(StrBuf b, Str name, Obj? arg)

compareDis

static Int compareDis(Str a, Str b)

Given two display strings, return 1, 0, or -1 if a is less than, equal to, or greater than b. The comparison is case insensitive and takes into account trailing digits so that a dis str such as "Foo-10" is greater than "Foo-2".

dict0

static Dict dict0()

Empty dict singleton

dict1

static Dict dict1(Str n, Obj v)

Create a Dict with one name/value pair

dict2

static Dict dict2(Str n0, Obj v0, Str n1, Obj v1)

Create a Dict with two name/value pairs

dict3

static Dict dict3(Str n0, Obj v0, Str n1, Obj v1, Str n2, Obj v2)

Create a Dict with three name/value pairs

dict4

static Dict dict4(Str n0, Obj v0, Str n1, Obj v1, Str n2, Obj v2, Str n3, Obj v3)

Create a Dict with four name/value pairs

dict5

static Dict dict5(Str n0, Obj v0, Str n1, Obj v1, Str n2, Obj v2, Str n3, Obj v3, Str n4, Obj v4)

Create a Dict with five name/value pairs

dict6

static Dict dict6(Str n0, Obj v0, Str n1, Obj v1, Str n2, Obj v2, Str n3, Obj v3, Str n4, Obj v4, Str n5, Obj v5)

Create a Dict with six name/value pairs

dictAll

static Bool dictAll(Dict d, |Obj?,Str->Bool| f)

Return if all of the tag name/value pairs match the given function.

dictAny

static Bool dictAny(Dict d, |Obj?,Str->Bool| f)

Return if any of the tag name/value pairs match the given function.

dictEq

static Bool dictEq(Dict a, Dict b)

Return if two dicts are equal with same name/value pairs. Value are compared via the Obj.equals method. Ordering of the dict tags is not considered.

dictFindAll

static Dict dictFindAll(Dict d, |Obj?,Str->Bool| f)

Return a new Dict containing the name/value pairs for which f returns true. If f returns false for every pair, then return an empty Dict.

dictHashKey

static Obj dictHashKey(Dict d)

Construct an object which wraps a dict and is suitable to use for a hash key in a Map. The key provides implementations of Obj.hash and Obj.equals based on the the name/value pairs in the dict. Hash keys do not support Dicts which contain anything but scalar values (nested lists, dicts, and grids are silently ignored for hash/equality purposes).

dictMap

static Dict dictMap(Dict d, |Obj?,Str->Obj?| f)

Apply the given map function to each name/value pair to construct a new Dict.

dictMerge

static Dict dictMerge(Dict a, Obj? b)

Add/set all the name/value pairs in a with those defined in b. If b defines a remove value then that name/value is removed from a. The b parameter may be any value accepted by makeDict

dictNames

static Str[] dictNames(Dict d)

Get a read/write list of the dict's name keys.

dictRemove

static Dict dictRemove(Dict d, Str name)

Remove a name/val pair from an exisiting dict, or if the name isn't found then return original dict.

dictRemoveAll

static Dict dictRemoveAll(Dict d, Str[] names)

Remove all names from the given dict. Ignore any name not defined as a tag.

dictRename

static Dict dictRename(Dict d, Str oldName, Str newName)

Rename given name if its defined in the dict, otherwise return original.

dictSet

static Dict dictSet(Dict? d, Str name, Obj? val)

Set a name/val pair in an existing dict or d is null then create a new dict with given name/val pair.

dictToDis

static Str? dictToDis(Dict dict, Str? def := "")

Given a dict, attempt to find the best display string:

  1. dis tag
  2. disMacro tag returns macro using dict as scope
  3. disKey maps to qname locale key
  4. name tag
  5. tag tag
  6. id tag
  7. default

dictToMap

static Str:Obj? dictToMap(Dict? d)

Convert a Dict to a read/write map. This method is expensive, when possible you should instead use Dict.each.

dictVals

static Obj[] dictVals(Dict d)

Get all the non-null values mapped by a dictionary.

dictsNames

static Str[] dictsNames(Dict?[] dicts)

Given a list of dictionaries, find all the common names used. Return the names in standard sorted order. Any null dicts are skipped.

discretePeriods

static Void discretePeriods(Str str, |Int,Int| f)

Iterate a discrete period string formatted in base64. Call the iterator function for each period where time is offset in minutes from base timestamp and dur is duration of period in minutes (assuming a minutely interval). This method may also be used discreteEnumPeriods() in which case the dur parameter will be the enum ordinal.

emptyDict

static Dict emptyDict()

Get the emtpy Dict instance.

gridFlatten

static Grid gridFlatten(Grid[] grids)

Flatten a list of grids into a single grid. Each grid's rows are appended to a single grid in the order passed. The resulting grid columns will be the intersection of all the individual grid columns. Grid meta and column merged together.

isKindName

static Bool isKindName(Str n)

Return if the given string is a legal kind name:

  • first char must be ASCII upper case letter: a - z
  • rest of chars must be ASCII letter or digit: a - z, A - Z, 0 - 9, or _

isTagName

static Bool isTagName(Str n)

Return if the given string is a legal tag name:

  • first char must be ASCII lower case letter: a - z
  • rest of chars must be ASCII letter or digit: a - z, A - Z, 0 - 9, or _

macro

static Str macro(Str pattern, Dict scope)

Process macro pattern with given scope of variable name/value pairs. The pattern is a Unicode string with embedded expressions:

  • $tag: resolve tag name from scope, variable name ends with first non-tag character, see Etc.isTagName
  • ${tag}: resolve tag name from scope
  • $<pod::key>: localization key

Any variables which cannot be resolved in the scope are returned as-is (such $name) in the result string.

If a tag resolves to Ref, then we use Ref.dis for string.

macroVars

static Str[] macroVars(Str pattern)

Return the list of variable tag names used in the given macro pattern. This includes "$tag" and "${tag}" variables, but does not include "$<pod::key>" localization keys.

makeDict

static Dict makeDict(Obj? val)

Make a Dict instance where val is one of the following:

  • Dict: return val
  • null: return emptyDict
  • Str:Obj?: wrap map as Dict
  • Str[]: dictionary of key/Marker value pairs

makeDict1

static Dict makeDict1(Str n, Obj? v)

Make a Dict with one name/value pair. Backward compatibility only for nullable values, use dict1 now.

makeDict2

static Dict makeDict2(Str n0, Obj? v0, Str n1, Obj? v1)

Make a Dict with two name/value pairs. Backward compatibility only for nullable values, use dict2 now.

makeDict3

static Dict makeDict3(Str n0, Obj? v0, Str n1, Obj? v1, Str n2, Obj? v2)

Make a Dict with three name/value pairs. Backward compatibility only for nullable values, use dict3 now.

makeDict4

static Dict makeDict4(Str n0, Obj? v0, Str n1, Obj? v1, Str n2, Obj? v2, Str n3, Obj? v3)

Make a Dict with four name/value pairs. Backward compatibility only for nullable values, use dict4 now.

makeDict5

static Dict makeDict5(Str n0, Obj? v0, Str n1, Obj? v1, Str n2, Obj? v2, Str n3, Obj? v3, Str n4, Obj? v4)

Make a Dict with five name/value pairs. Backward compatibility only for nullable values, use dict5 now.

makeDict6

static Dict makeDict6(Str n0, Obj? v0, Str n1, Obj? v1, Str n2, Obj? v2, Str n3, Obj? v3, Str n4, Obj? v4, Str n5, Obj? v5)

Make a Dict with six name/value pairs. Backward compatibility only for nullable values, use dict6 now.

makeDictGrid

static Grid makeDictGrid(Obj? meta, Dict row)

Construct a grid for a Dict row. The meta parameter can be any makeDict value.

makeDicts

static Dict[] makeDicts(Obj?[] maps)

Make a list of Dict instances using makeDict.

makeDictsGrid

static Grid makeDictsGrid(Obj? meta, Dict?[] rows)

Construct a grid for a list of Dict rows. The meta parameter can be any makeDict value. Any null dicts result in an empty row of all nulls. If no non-null rows, then return makeEmptyGrid.

makeEmptyGrid

static Grid makeEmptyGrid(Obj? meta := null)

Construct an empty grid with just the given grid level meta-data. The meta parameter can be any makeDict value.

makeErrGrid

static Grid makeErrGrid(Err e, Obj? meta := null)

Construct a grid for an error response.

makeListGrid

static Grid makeListGrid(Obj? meta, Str colName, Obj? colMeta, Obj?[] rows)

Construct a grid with one column for a list. The meta and colMeta parameters can be any makeDict value.

makeListsGrid

static Grid makeListsGrid(Obj? meta, Str[] colNames, Obj?[]? colMetas, Obj?[][] rows)

Construct a grid for a list of rows, where each row is a list of cells. The meta and colMetas parameters can be any makeDict value.

makeMapGrid

static Grid makeMapGrid(Obj? meta, Str:Obj? row)

Convenience for makeDictGrid

makeMapsGrid

static Grid makeMapsGrid(Obj? meta, Str:Obj?[] rows)

Convenience for makeDictsGrid

relDis

static Str relDis(Str parent, Str child)

Get a relative display name. If the child display name starts with the parent, then we can strip that as the common suffix.

tagToLocale

static Str tagToLocale(Str name)

Get the localized string for the given tag name for the current locale. See Localization.

toDateSpan

static DateSpan toDateSpan(Obj? val, HaystackContext? cx := null)

Coerce an object to a DateSpan:

  • Func: function which evaluates to date range (must be run in a context)
  • DateSpan: return itself
  • Date: one day range
  • Span: return Span.toDateSpan
  • Str: evaluates to DateSpan.fromStr
  • Date..Date: starting and ending date (inclusive)
  • Date..Number: starting date and num of days (day unit required)
  • DateTime..DateTime: use starting/ending dates; if end is midnight, then use previous date
  • Number: convert as year

toErrMeta

static Dict toErrMeta(Err e)

Map an exception to its standard tags:

  • dis: error display string
  • err: marker
  • errTrace: Str stack dump
  • axonTrace: Axon stack dump (if applicable)
  • errType: exception type qname

toGrid

static Grid toGrid(Obj? val, Dict? meta := null)

Coerce a value to a Grid:

  • if grid just return it
  • if row in grid of size, return row.grid
  • if scalar return 1x1 grid
  • if dict return grid where dict is only
  • if list of dict return grid where each dict is row
  • if list of non-dicts, return one col grid with rows for each item
  • if non-zinc type return grid with cols val, type

toId

static Ref toId(Obj? val)

Coerce a value to a Ref identifier:

  • Ref returns itself
  • Row or Dict, return id tag
  • Grid return first row id

toIds

static Ref[] toIds(Obj? val)

Coerce a value to a list of Ref identifiers:

  • Ref returns itself as list of one
  • Ref[] returns itself
  • Dict return id tag
  • Dict[] return id tags
  • Grid return id column

toRec

static Dict toRec(Obj? val, HaystackContext? cx := null)

Coerce a value to a record Dict:

  • Row or Dict returns itself
  • Grid returns first row (must have at least one row)
  • List returns first item (must have at least one item which is Ref or Dict)
  • Ref will make a call to read database (must be run in a context)

toRecs

static Dict[] toRecs(Obj? val, HaystackContext? cx := null)

Coerce a value to a list of record Dicts:

  • null return empty list
  • Ref or Ref[] will read database (must be run in a context)
  • Row or Row[] returns itself
  • Dict or Dict[] returns itself
  • Grid is mapped to list of rows

toSpan

static Span toSpan(Obj? val, TimeZone? tz := null, HaystackContext? cx := null)

Coerce an object to a Span with optional timezone:

  • Span: return itself
  • Span+tz: update timezone using same dates only if aligned to midnight
  • Str: return Span.fromStr using current timezone
  • Str+tz: return Span.fromStr using given timezone
  • DateTime..DateTime: range of two DateTimes
  • Date..DateTime: start day for date until the end timestamp
  • DateTime..Date: start timestamp to end of day for end date
  • DateTime: span of a single timestamp
  • DateSpan: anything accepted by toDateSpan in current timezone
  • DateSpan+tz: anything accepted by toDateSpan using given timezone

toTagName

static Str toTagName(Str n)

Take an arbitrary string and convert into a safe tag name. Do not assume any specific conversion algorithm as it might change in the future. The empty string is not supported.