SkySpark by SkyFoundry

const class haystack::Etc

sys::Obj
  haystack::Etc

@Js

Etc provides folio related utility methods.

compareDis

const 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".

dictAll

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

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

dictAny

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

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

dictFindAll

const 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

const 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.

dictMap

const 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

const 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

const static Str[] dictNames(Dict d)

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

dictRemove

const 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.

dictSet

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

Set a name/val pair in an existing dict.

dictToDis

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

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

  1. dis tag
  2. disMacro tag returns macro using dict as scope
  3. name tag
  4. tag tag
  5. id tag
  6. default
dictToMap

const 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

const static Obj?[] dictVals(Dict d)

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

dictsNames

const 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

const 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

const static Dict emptyDict()

Get the emtpy Dict instance.

isDictVal

const static Bool isDictVal(Obj? val)

Return if the given value is one of the scalar values supported by dicts and grids.

isTagName

const 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

const 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, 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

const 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

const static Dict makeDict(Obj? val)

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

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

const static Grid makeDictGrid(Obj? meta, Dict row)

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

makeDicts

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

Make a list of Dict instances using makeDict.

makeDictsGrid

const 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

const 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

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

Construct a grid for an error response.

makeListGrid

const 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

const 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

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

Convenience for makeDictGrid

makeMapsGrid

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

Convenience for makeDictsGrid

relDis

const 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

const static Str tagToLocale(Str name)

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

toErrMeta

const 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

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

Given an arbitrary object, translate it to a Grid suitable for serizliation with Zinc:

  • 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
toTagName

const static Str toTagName(Str n)

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