Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

regexparam

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexparam - npm Package Compare versions

Comparing version 2.0.2 to 3.0.0

16

dist/index.js

@@ -1,4 +0,8 @@

function parse(str, loose) {
if (str instanceof RegExp) return { keys:false, pattern:str };
var c, o, tmp, ext, keys=[], pattern='', arr = str.split('/');
/**
* @param {string|RegExp} input The route pattern
* @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
*/
function parse(input, loose) {
if (input instanceof RegExp) return { keys:false, pattern:input };
var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
arr[0] || arr.shift();

@@ -9,4 +13,4 @@

if (c === '*') {
keys.push('wild');
pattern += '/(.*)';
keys.push(c);
pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
} else if (c === ':') {

@@ -34,3 +38,3 @@ o = tmp.indexOf('?', 1);

return route.replace(RGX, (x, lead, key, optional) => {
x = values[key=='*' ? 'wild' : key.substring(1)];
x = values[key=='*' ? key : key.substring(1)];
return x ? '/'+x : (optional || key=='*') ? '' : '/' + key;

@@ -37,0 +41,0 @@ });

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.regexparam={})}(this,(function(e){var n=/(\/|^)([:*][^/]*?)(\?)?(?=[/.]|$)/g;e.inject=function(e,t){return e.replace(n,(e,n,i,r)=>(e=t["*"==i?"wild":i.substring(1)])?"/"+e:r||"*"==i?"":"/"+i)},e.parse=function(e,n){if(e instanceof RegExp)return{keys:!1,pattern:e};var t,i,r,f,s=[],p="",o=e.split("/");for(o[0]||o.shift();r=o.shift();)"*"===(t=r[0])?(s.push("wild"),p+="/(.*)"):":"===t?(i=r.indexOf("?",1),f=r.indexOf(".",1),s.push(r.substring(1,~i?i:~f?f:r.length)),p+=~i&&!~f?"(?:/([^/]+?))?":"/([^/]+?)",~f&&(p+=(~i?"?":"")+"\\"+r.substring(f))):p+="/"+r;return{keys:s,pattern:new RegExp("^"+p+(n?"(?=$|/)":"/?$"),"i")}}}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.regexparam={})}(this,(function(e){var n=/(\/|^)([:*][^/]*?)(\?)?(?=[/.]|$)/g;e.inject=function(e,t){return e.replace(n,(e,n,i,r)=>(e=t["*"==i?i:i.substring(1)])?"/"+e:r||"*"==i?"":"/"+i)},e.parse=function(e,n){if(e instanceof RegExp)return{keys:!1,pattern:e};var t,i,r,f,s=[],p="",o=e.split("/");for(o[0]||o.shift();r=o.shift();)"*"===(t=r[0])?(s.push(t),p+="?"===r[1]?"(?:/(.*))?":"/(.*)"):":"===t?(i=r.indexOf("?",1),f=r.indexOf(".",1),s.push(r.substring(1,~i?i:~f?f:r.length)),p+=~i&&!~f?"(?:/([^/]+?))?":"/([^/]+?)",~f&&(p+=(~i?"?":"")+"\\"+r.substring(f))):p+="/"+r;return{keys:s,pattern:new RegExp("^"+p+(n?"(?=$|/)":"/?$"),"i")}}}));

@@ -23,5 +23,7 @@ export function parse(route: string, loose?: boolean): {

: T extends `${string}*`
? { wild: string }
? { "*": string }
: T extends `${string}*?`
? { "*"?: string }
: {};
export function inject<T extends string>(route: T, values: RouteParams<T>): string;
{
"name": "regexparam",
"version": "2.0.2",
"version": "3.0.0",
"repository": "lukeed/regexparam",
"description": "A tiny (394B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍",
"description": "A tiny (399B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍",
"unpkg": "dist/index.min.js",

@@ -7,0 +7,0 @@ "module": "dist/index.mjs",

# regexparam [![CI](https://github.com/lukeed/regexparam/actions/workflows/ci.yml/badge.svg)](https://github.com/lukeed/regexparam/actions/workflows/ci.yml)
> A tiny (394B) utility that converts route patterns into RegExp. Limited alternative to [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) 🙇
> A tiny (399B) utility that converts route patterns into RegExp. Limited alternative to [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) 🙇

@@ -16,2 +16,3 @@ With `regexparam`, you may turn a pathing string (eg, `/users/:id`) into a regular expression.

* Wildcards (`*`, `/books/*`, `/books/:genre/*`)
* Optional Wildcard (`/books/*?`)

@@ -81,11 +82,20 @@ This module exposes three module definitions:

// baz.pattern => /^\/users\/(.*)\/?$/i
// baz.keys => ['wild']
// baz.keys => ['*']
baz.pattern.test('/users'); //=> false
baz.pattern.test('/users/lukeed'); //=> true
baz.pattern.test('/users/'); //=> true
exec('/users/lukeed/repos/new', baz);
//=> { wild: 'lukeed/repos/new' }
// Optional Wildcard
// ---
let baz = parse('/users/*?');
// baz.pattern => /^\/users(?:\/(.*))?(?=$|\/)/i
// baz.keys => ['*']
baz.pattern.test('/users'); //=> true
baz.pattern.test('/users/lukeed'); //=> true
baz.pattern.test('/users/'); //=> true
// Injecting

@@ -117,3 +127,3 @@ // ---

slug: 'hello',
wild: 'x/y/z',
'*': 'x/y/z',
}); //=> '/posts/hello/x/y/z'

@@ -214,3 +224,3 @@

> **Note:** To replace a wildcard segment (eg, `/*`), define a `values.wild` key.
> **Note:** To replace a wildcard segment (eg, `/*`), define a `values['*']` key.

@@ -217,0 +227,0 @@

Sorry, the diff of this file is not supported yet

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