glob-props
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

glob-props

Use /glob/strings/**/*.* as javascript object properties! ✨

npm license travis status Build status Coverage Status David David Commitizen friendly semantic-release

NPM

Installation

npm install glob-props
yarn install glob-props

Usage

import { GlobProps } from 'glob-props'
 
// define a regular object with glob expressions for keys.
// the values are not constrained in any way.
const regularObject = {
  'src/**/*.*': 'isSrc',
  'dst/**/*.*': 'isDst'
};
 
const globber = GlobProps(obj);
 
// Accessing `globber` by a specific key returns:
// 1. A match on the first property that the key matches.
// 2. undefined when no match is found, just like regualrObject.
 
globber['src/index.ts']              // returns 'isSrc'
globber['src/deep/er/search.txt']    // returns 'isSrc'
globber['dst/index.ts']              // returns 'isDst'
globber['non-existant/glob/pattern'] // returns undefined

Implementation

glob-props creates an object proxy over a regularObject.

When accessed with a concrete string, the proxied get method performs a glob search, returning the value of the first glob that matches the concrete string.

Why

glob-props makes it trivially simple to create a many-to-one mapper or simple routers. The look up is reduced to an object access. And then again, why not?!

Development Tooling

License

Apache-2.0

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Support

Bugs, PRs, comments, suggestions welcomed!

Dependencies (5)

Dev Dependencies (22)

Package Sidebar

Install

npm i glob-props

Weekly Downloads

0

Version

1.0.0

License

Apache-2.0

Last publish

Collaborators

  • sramam