Options
All
  • Public
  • Public/Protected
  • All
Menu

def

Create a new definition bound to the given symbol. See [Defs chapter]docHaystack::Defs.

Hierarchy

Index

Properties

Optional doc

doc: HStr

Optional enum

enum: HStr

Optional is

is: HList<OptionalHVal<null | HVal>>

Optional mandatory

mandatory: HMarker

Optional maxVal

maxVal: HNum

Optional minVal

minVal: HNum

Optional notInherited

notInherited: HMarker

Optional of

of: HSymbol

Optional tagOn

tagOn: HList<OptionalHVal<null | HVal>>

Optional transient

transient: HMarker

Optional wikipedia

wikipedia: HUri

Accessors

defName

  • get defName(): string
  • If this dict is for a def then return its name otherwise return an empty string.

    Returns string

    The def name or an empty string.

keys

  • get keys(): string[]
  • for (let key of dict.keys) {
      console.log(key)
    }
    

    Returns string[]

    All keys used in the dict.

length

  • get length(): number
  • console.log('Size: ' + dict.length)
    

    Returns number

    The number of entries in the dict.

values

  • get values(): OptionalHVal<null | HVal>[]
  • for (let value of dict.values) {
      console.log(value.getKind())
    }
    

    Returns OptionalHVal<null | HVal>[]

    All values for the dict.

Methods

[Symbol.iterator]

  • [Symbol.iterator](): Iterator<HValRow, any, undefined>
  • Iterate over a dict.

    This enables a 'for ... of' loop to be used directly on an iterator.

    Returns Iterator<HValRow, any, undefined>

    A new iterator for a dict.

    // Iterate a dict
    for (let row of dict) {
      console.log(row.name)
      console.log(row.value)
    }
    

any

  • any(filter: string | OptionalHVal<null | HVal> | Node, cx?: Partial<EvalContext>): boolean
  • Return true if the dict matches the specified filter or if the value exists in the dict at least once.

    if (dict.any('site and geoCity == "London"')) {
      ...
    }
    
    throws

    An error for a invalid haystack filter.

    Parameters

    • filter: string | OptionalHVal<null | HVal> | Node

      The haystack value, haystack filter or AST node.

    • Optional cx: Partial<EvalContext>

      Optional haystack filter evaluation context.

    Returns boolean

    True if the property value exists in the dict.

asArrayLike

  • asArrayLike(): ArrayLike<HValRow>
  • Returns ArrayLike<HValRow>

    The dict as an array like object.

clear

  • clear(): void
  • Clear all entries from the dict.

    // Clear all the entries from the dict.
    dict.clear()
    

    Returns void

compareTo

  • compareTo(value: unknown): number
  • Compares two values.

    Parameters

    • value: unknown

      The value to compare against.

    Returns number

    The sort order as negative, 0, or positive.

equals

  • equals(value: unknown): boolean
  • Value equality check.

    Parameters

    • value: unknown

      The value to test.

    Returns boolean

    True if the value is the same.

get

  • get<Value>(name: string): undefined | Value
  • Returns a haystack value from the dict or undefined if it can't be found.

    // Gets the value as an HVal so cast to an HStr.
    const str = dict.get('foo') as HStr
    
    if (str) {
      // Do something.
    }
    
    // Method is generic to make it easier on the eye for casting.
    const str1 = dict.get<HStr>('foo')
    

    Type parameters

    • Value: OptionalHVal<null | HVal>

    Parameters

    • name: string

      The name of the value to find.

    Returns undefined | Value

    The value or undefined if it can't be found.

getKind

  • getKind(): Kind
  • Returns Kind

    The value's kind.

has

  • has(name: string): boolean
  • Returns true if the dict has the specified key.

    if (dict.has('foo')) {
      // Do something
    }
    

    Parameters

    • name: string

      The name of the key.

    Returns boolean

    True if the value exists in the dict.

inspect

  • inspect(message?: string): Def
  • Dump the value to the local console output.

    Parameters

    • Optional message: string

      An optional message to display before the value.

    Returns Def

    The value instance.

isEmpty

  • isEmpty(): boolean
  • if (dict.isEmpty()) {
      // There are no entries in the dict.
    }
    

    Returns boolean

    True when there are no entries in the dict.

isKind

  • isKind(kind: Kind): boolean
  • Compares the value's kind.

    Parameters

    • kind: Kind

      The kind to compare against.

    Returns boolean

    True if the kind matches.

matches

  • matches(filter: string | Node, cx?: Partial<EvalContext>): boolean
  • Returns true if the haystack filter matches the value.

    This method is the same as any.

    if (dict.matches('site and geoCity == "London"')) {
      // Do something
    }
    

    Parameters

    • filter: string | Node

      The filter to test.

    • Optional cx: Partial<EvalContext>

      Optional haystack filter evaluation context.

    Returns boolean

    True if the filter matches ok.

newCopy

  • newCopy(): HDict
  • Returns HDict

    Returns a copy of the dict.

protos

  • protos(namespace?: HNamespace): HDict[]
  • Return a reflected array of children prototypes.

    If a namespace isn't specified then the default environment namespace will be used.

    Parameters

    • Optional namespace: HNamespace

      An optional namespace to perform the protos call from.

    Returns HDict[]

    An array of dicts.

reflect

  • reflect(namespace?: HNamespace): Reflection
  • Analyze this dict and return its implemented defs.

    If a namespace isn't specified then the default environment namespace will be used.

    Parameters

    • Optional namespace: HNamespace

      An optional namespace to perform the reflect from.

    Returns Reflection

    An array of dicts.

remove

  • remove(name: string): void
  • Removes a property from the dict.

    // Removes the tag named foo.
    dict.remove('foo')
    

    Parameters

    • name: string

      The property name.

    Returns void

set

  • set(name: string, value: HVal | HaysonVal): Def
  • Set a haystack value.

    dict.set('foo', HStr.make('New value'))
    
    // Set the value using Hayson
    dict.set('foo', 'New value')
    

    Parameters

    • name: string

      The name to set.

    • value: HVal | HaysonVal

      The haystack value to set.

    Returns Def

    The dict instance.

toAxon

  • toAxon(): string
  • Returns string

    An Axon encoded string.

toDict

  • toDict(): HDict
  • Returns HDict

    The value as a dict.

toFilter

  • toFilter(): string
  • Encodes to an encoded zinc value that can be used in a haystack filter string.

    A dict isn't supported in filter so throw an error.

    Returns string

    The encoded value that can be used in a haystack filter.

toGrid

  • toGrid(): HGrid<HDict>
  • // Convert the dict to an HGrid with one row.
    const hgrid = dict.toGrid()
    

    Returns HGrid<HDict>

    The dict as a grid.

toJSON

  • toJSON(): HaysonDict
  • Returns HaysonDict

    A JSON reprentation of the object.

toList

  • toList<Value>(): HList<Value>
  • // Convert the dict to an HList of haystack strings.
    const hlist = dict.toList<HStr>()
    

    Type parameters

    • Value: HVal<Value>

    Returns HList<Value>

    All the dict's values as a haystack list

toObj

  • toObj(): HValObj
  • Returns the underlying object being managed by the store.

    // Gets a JS Object with the keys as strings and the values as HVals.
    const obj = dict.toObj()
    

    Returns HValObj

    A the underlying object.

toString

  • toString(): string
  • Returns string

    A string representation of the value.

toZinc

  • toZinc(): string
  • Encodes to an encoding zinc value.

    Returns string

    The encoded zinc string.

update

  • update(...dicts: (HDict | HaysonDict)[]): Def
  • Update a dict from another dict(s) or Hayson dict(s).

    dict.update(otherDict, anotherDict)
    
    // Update using a Hayson object
    dict.update({ dis: 'A new display string', curVal: 20 })
    

    Parameters

    • Rest ...dicts: (HDict | HaysonDict)[]

      The dicts to update from.

    Returns Def

    The dict instance.

validate

  • validate(): void
  • Iterates through the dict to ensure we have a valid set of haystack values.

    As the dict's internals are directly exposed calling this method will ensure all the values held in the dict are valid haystack values.

    Returns void

Generated using TypeDoc