Skip to content

object

Helpers for working with objects: read their keys, values, and entries, and transform them with mapValues, mapEntries, and filterEntries.

ts
import { keys, mapValues } from "std::object"

node main() {
  const scores = { alice: 1, bob: 2 }
  print(keys(scores))   // ["alice", "bob"]

  const scaled = mapValues(scores) as (value, key) {
    return value * 10
  }
  print(scaled)         // { alice: 10, bob: 20 }
}

Functions

keys

ts
keys(obj: any): string[]

Return an array of an object's own enumerable property names.

@param obj - The object

Parameters:

NameTypeDefault
objany

Returns: string[]

(source)

values

ts
values(obj: any): any[]

Return an array of an object's own enumerable property values.

@param obj - The object

Parameters:

NameTypeDefault
objany

Returns: any[]

(source)

entries

ts
entries(obj: any): any[]

Return an array of an object's own enumerable entries, each as { key, value }.

@param obj - The object

Parameters:

NameTypeDefault
objany

Returns: any[]

(source)

mapValues

ts
mapValues(obj: any, func: (any, string) => any): any

Return a new object with the same keys, but with each value transformed by the function.

@param obj - The object to transform @param func - The function receiving (value, key)

Parameters:

NameTypeDefault
objany
func(any, string) => any

Returns: any

(source)

mapEntries

ts
mapEntries(obj: any, func: (any, string) => any): any

Return a new object by applying the function to each entry.

@param obj - The object to transform @param func - The function receiving (value, key) returning

Parameters:

NameTypeDefault
objany
func(any, string) => any

Returns: any

(source)

filterEntries

ts
filterEntries(obj: any, func: (any, string) => boolean): any

Return a new object containing only the entries for which the function returns true.

@param obj - The object to filter @param func - The predicate receiving (value, key)

Parameters:

NameTypeDefault
objany
func(any, string) => boolean

Returns: any

(source)

everyEntry

ts
everyEntry(obj: any, func: (any, string) => boolean): boolean

Return true if the function returns true for every entry in the object.

@param obj - The object to test @param func - The predicate receiving (value, key)

Parameters:

NameTypeDefault
objany
func(any, string) => boolean

Returns: boolean

(source)

someEntry

ts
someEntry(obj: any, func: (any, string) => boolean): boolean

Return true if the function returns true for at least one entry in the object.

@param obj - The object to test @param func - The predicate receiving (value, key)

Parameters:

NameTypeDefault
objany
func(any, string) => boolean

Returns: boolean

(source)