1.1.1 • Published 6 years ago

wildcard-named v1.1.1

Weekly downloads
10
License
MIT
Repository
github
Last release
6 years ago

Greenkeeper badge Build Status License npm version npm downloads

A small and easy-to-use utility module for matching strings using named and/or unnamed wildcards for JavaScript.

Installation

$ npm install wildcard-named

Usage

import wildcard from "wildcard-named";

Basic example

import wildcard from "wildcard-named";

wildcard("//blog.com/page/14", "//blog.com/page/[digit:page]");
// { page: '14' }

wildcard("abc-123:d2f", "[digit:a]-[alpah:b]:[alnum:c]");
// { a: 'abc', b: '123', c: 'd2f' }

Unnamed wildcards

import wildcard from "wildcard-named";

wildcard("a-b-c", "[alpah:]-[alpah:]-[alpah:]");
// { 0: 'a', 1: 'b', 2: 'c' }

Unmatched wildcards

When the pattern cannot be resolved, it will return null.

import wildcard from "wildcard-named";

wildcard("a-b-c", "[alpah:]");
// null

Wildcards

You can add your own filters using the .addFilter(filter, regex) function, like this:

import wildcard from "wildcard-named";

wildcard.addFilter("testA", "(.*?)");
wildcard.addFilter("testB", "([0-9])");

wildcard("match-1", "[testA:a]-[testB:b]");
// { a: 'match', b: '1' }

All registered filters are stored in a Map at wildcard.filters.

Predefined wildcards

FilterRegex
digit([0-9]+)
alnum([0-9A-Za-z]+)
alpah([A-Za-z]+)
xdigit([0-9A-Fa-f]+)
punct([\p{P}\d]+)
print([\x20-\x7e]*)
upper([A-Z]+)
lower([a-z]+)
all(.*?)

Tests

$ npm test
1.1.1

6 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

8 years ago

0.0.21

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago