prefix-matches

Find matching keys in a given object, for a given prefix string

MIT 11 个版本
安装
npm install prefix-matches
yarn add prefix-matches
pnpm add prefix-matches
bun add prefix-matches
README

Prefix Matches

Find matching keys in a given object, for a given prefix string

Warning: experimental

Installation

npm i --save prefix-matches

then, in your scripts:

const prefixMatches = require('prefix-matches')

Example

const prefixMatches = require('prefix-matches')

// Resolves simple cases
prefixMatches('w', {
	watch: 'watch things',
	build: 'build things'
}) // => [{ watch: 'watch things' }]

// Does not flatten result set
prefixMatches('w', {
	watch: {
		js: 'watch javascript',
		css: 'watch css'
	},
	build: 'build things'
}) // => [{ watch: { js: 'watch javascript', css: 'watch css' }}]

// Resolves nested prefixes
prefixMatches('w.j', {
	watch: {
		js: 'watch javascript',
		css: 'watch css'
	},
	write: {
		js: 'write javascript'
	}
}) // => [{ 'watch.js': 'watch javascript' }, { 'write.js': 'write javascript' }]

// ... and so on
prefixMatches('b.f.j', {
	build: {
		frontend: {
			js: 'build javascript',
			css: 'build css'
		}
	}
}) // => [{ 'build.frontend.js': 'build javascript' }]

Why?

To attempt better prefixing support for the package-scripts project.

Tests

A basic test suite has been authored in AVA, used for its terrifying speed. To run it:

npm test
版本列表
1.0.1 2017-05-26
1.0.0 2017-05-21
0.0.9 2016-05-03
0.0.8 2016-05-03
0.0.7 2016-05-03
0.0.6 2016-05-02
0.0.5 2016-05-02
0.0.4 2016-05-02
0.0.3 2016-05-02
0.0.2 2016-05-02
0.0.1 2016-05-02