Skip to content

Releases: chocolateboy/get-wild

v3.0.0

28 Apr 18:47
Compare
Choose a tag to compare

Breaking Changes

  • bracketed integers are now always treated as indices rather than only when the object is an array
  • collect is called for indexed access to non-arrays as well as for wildcard matches against them

Features

  • for indexed properties, collect is passed the index as a second argument (omitted for wildcard matches)
  • the return value of collect can be an array-like for indexed access rather than the full array required for wildcard matches

Migration

To access numeric string properties on non-arrays, the properties should be typed as strings, e.g.:

Before

import { get } from 'get-wild'

const obj = {
    1: { '-1': 'foo' },
    2: { '-2': 'bar' },
}

get(obj, '[0]')         // undefined <- obj["0"]
get(obj, '[-1]')        // undefined <- obj["-1"]
get(obj, '[1][-1]')     // "foo"     <- obj["1"]["-1"]
get(obj, '[2][-2]')     // "bar"     <- obj["2"]["-2"]
get(obj, '1.-1')        // "foo"     <- obj["1"]["-1"]
get(obj, '["2"]["-2"]') // "bar"     <- obj["2"]["-2"]
get(obj, '[3.1415927]') // syntax error

After

get(obj, '[0]')         // { "-1": "foo" } <- collect(obj)[0]
get(obj, '[-1]')        // { "-2": "bar" } <- collect(obj)[-1]
get(obj, '[1][-1]')     // "bar"           <- collect(obj)[1] |> collect(#)[-1]
get(obj, '[2][-2]')     // undefined       <- collect(obj)[2]
get(obj, '1.-1')        // "foo"           <- obj["1"]["-1"]
get(obj, '["2"]["-2"]') // "bar"           <- obj["2"]["-2"]
get(obj, '[3.1415927]') // syntax error