Treats the keys of tree
as simple glob patterns. The following patterns are supported:
*
matches any text?
matches a single character**
matches any level of a tree
$ cat globKeys.yaml
"*.jpg": false
"*.txt": true
$ ori "globKeys(globKeys.yaml)/foo.jpg"
false
$ ori "globKeys(globKeys.yaml)/foo.txt"
true
Masking
globKeys
can be used in conjunction with tree:mask
to include or include values based on glob patterns.
This Origami function accepts a tree, then applies a mask
using globKeys
to return just the values whose keys have image file extensions:
// images.ori
// Return only the image files in the given tree
(tree) => mask(tree, globKeys({
// Apply these globs at all levels
**: {
*.gif: true
*.ico: true
*.jpeg: true
*.jpg: true
*.png: true
*.svg: true
*.tif: true
*.tiff: true
*.webp: true
}
}))
This would typically be applied to a tree of files, but for demonstration purposes a YAML file can simulate a small set of files:
# files.yaml
index.html: Index page
favicon.ico: (image data)
about:
index.html: About page
logo.jpeg: (image data)
Applying the mask to the data gives:
$ ori images.ori files.yaml
favicon.ico: (image data)
about:
logo.jpeg: (image data)