Get the data of one pattern

Read back the data stored at exactly one pattern with get, not the data of the pattern that best matches.

Use this to see whether a pattern is there before adding to it, or to read back what add stored. find answers for a query; get answers for one pattern itself:

const patrun = require('patrun')

const pm = patrun({ gex: true })
  .add({ cmd: 'list' }, 'LIST')
  .add({ cmd: 'l*' }, 'L-GLOB')
  .add({ cmd: '*' }, 'ANY')

pm.find({ cmd: 'load' }) // → 'L-GLOB'  the pattern that matches
pm.get({ cmd: 'load' }) // → null  no pattern is cmd:load
pm.get({ cmd: 'l*' }) // → 'L-GLOB'  the pattern with that glob
pm.get({ cmd: '*' }) // → 'ANY'  the pattern with the star

To add to what a pattern holds, read it with get and add the result:

const patrun = require('patrun')

const pm = patrun().add({ a: 1 }, ['x'])

const held = pm.get({ a: 1 })
pm.add({ a: 1 }, (held || []).concat('y'))
pm.get({ a: 1 }) // → ['x', 'y']

In Go #

Get gives the data and whether the pattern holds any:

pm := patrun.New(patrun.Options{Gex: true})
pm.Add(map[string]string{"cmd": "l*"}, s("L-GLOB"))

pm.Find(map[string]string{"cmd": "load"}) // → "L-GLOB"
pm.Get(map[string]string{"cmd": "load"})  // → not found
pm.Get(map[string]string{"cmd": "l*"})    // → "L-GLOB"

What to watch for #

get never settles for a pattern with fewer properties, as find does, nor gives one with more, as list does. A glob and the star are asked for as themselves, and an interval by any of its spellings. It gives the data as it was added: a customiser's function is not called. A pattern that add would refuse holds nothing, so get answers null for it, and Go's Get does not panic.

This page describes patrun 9.0.0 for JavaScript and 0.4.0 for Go. Edit this page · This page as Markdown