New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

pattern-map

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pattern-map

Maps patterns with matching tokens to each other.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

pattern-map

Build Status

npm install pattern-map

This module allows for matching patterns and extracting matches from those pattern. Once the matches are extracted they then can be applied to other patterns to resolve them and create new strings.

Sample usage:

var patternMap = require('pattern-map');

var urlPattern = patternMap('/bundles/{widget}.js');
var filePattern = patternMap('src/{widget}/index.js');

var matches = urlPattern.match('/bundles/sortableList.js');
// { 'widget' : 'sortableList' }

var fileLocation = filePattern.resolve(matches);
// "src/sortableList/index.js"

API

patternMap(patternString)

Returns a new pattern. Uses the patternString to establish how it will match. All pattern methods are immutable.

Example:

var pattern = patternMap('/{path}/{version}/{module}/{theme}.css');

pattern.tokens([ unique ])

Returns all tokens in the order they are defined in the pattern. If unique is truthy, it will only return unique tokens.

Example:

patternMap('{dir}/{subDir}/{dir}/{target}.json').tokens();
// ['dir', 'subDir', 'dir', 'target']

patternMap('{dir}/{subDir}/{dir}/{target}.json').tokens(true);
// ['dir', 'subDir', 'target']

pattern.match(string)

Compares string against the pattern. If it matches the pattern returns an object such that it has a key for each value returned by tokens() which has a value extracted from the corresponing position of string. Returns undefined otherwise.

Example:

patternMap('/modules/{app}.js?build={version}').match('/modules/chat.js?build=0.1.3');
// { 'app' : 'chat', 'version' : '0.1.3' }

pattern.resolve(matches)

Replaces tokens with corresponding values from the matches object.

Example:

patternMap('src/{widget}/styles/{theme}.less').resolve({ 'widget' : 'navigation', 'theme' : 'highConstrast' });
// "src/navigation/styles/highContrast.less"

Keywords

pattern-map

FAQs

Package last updated on 17 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts