New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

trailblazer

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trailblazer

`trailblazer` is a minimalist regular expression-generator for paths with named parameters. Turn a path such as `/:foo` into a regular expression and extract the keys.

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20
decreased by-44.44%
Maintainers
1
Weekly downloads
 
Created
Source

trailblazer

trailblazer is a minimalist regular expression-generator for paths with named parameters. Turn a path such as /:foo into a regular expression and extract the keys.

Installation

npm install trailblazer

API

Function compile

export const compile = (path: string, options: Options) => Compile;
  • Create a regular expression from path and extract the key names.
import { compile } from 'trailblazer';

const path = '/foo/:bar';

const options = {
   sensitive: false,
   strict: false,
   start: true,
   end: true
};

const result = compile(path, options);

console.log(result.keys); // ['bar']
console.log(result.pattern); // /^\/foo\/([^\/]+)\/?$/i

result.pattern.test('/foo/123'); // true
result.pattern.exec('/foo/123'); // ['/foo/123', '123']

Type Options

type Options = {
    sensitive?: boolean;
    strict?: boolean;
    start?: boolean;
    end?: boolean;
}
  • sensitive: When true, the RegExp will be case sensitive.

    • Default: false
  • strict: When true, the RegExp allows an optional trailing slash to match.

    • Default: false
  • start: When true, the RegExp will match from the beginning of the string.

    • Default: true
  • end: When true, the RegExp will match to the end of the string.

    • Default: true

Type Compile

type Compile = {
    pattern: RegExp;
    keys: string[];
}
  • pattern: The RegExp created for the input path.
  • keys: An array of key names extracted from the input path.

FAQs

Package last updated on 28 May 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc