path-to-regex
Advanced tools
Comparing version 1.3.4 to 1.3.5
38
index.js
@@ -88,16 +88,21 @@ module.exports = Regex; | ||
// console.log("str:", str); | ||
// console.log("key:",key); | ||
// console.log("a:",a); | ||
// console.log("pat:",pat); | ||
// console.log("quant:",quant); | ||
// console.log("index:",index); | ||
// console.log("string:",string); | ||
// console.log("key:", key); | ||
// console.log("a:", a); | ||
// console.log("pat:", pat); | ||
// console.log("quant:", quant); | ||
// console.log("index:", index); | ||
// console.log("string:", string); | ||
count++; | ||
// let pq = pat?pat[pat.length-1]:""; | ||
// pq = (pq==="+"||pq==="*")?"?":""; | ||
const pattern = (pat ? pat : notseparator + "+"); | ||
const isMultiple = (quant === "*" || quant === "+") ? true : false; | ||
const isRequired = (quant !== "*" && quant !== "?") ? true : false; | ||
// if (pat && /^(\[[^\[\]]+\]|\([^\(\)]+\)|\.|\\.)[\+\*]$/) isMultiple = true; | ||
let isRequired = (quant !== "*" && quant !== "?") ? true : false; | ||
if (!quant && pat && /^(\[[^\[\]]+\]|\([^\(\)]+\)|\.|\\.)[\*\?]?$/) isRequired = false; | ||
const quantifier = quant ? quant : ""; | ||
// console.log("isMultiple", isMultiple); | ||
// console.log("isRequired", isRequired); | ||
@@ -115,5 +120,15 @@ // const startChar = path.charAt(index-1); | ||
if (isToken && index && (!isMultiple || !isRequired)) | ||
this.regstr += "?"; | ||
if (isToken && index) { | ||
if (!isMultiple || !isRequired) { | ||
if (quant || pat) { | ||
this.regstr += "?"; | ||
} | ||
} | ||
} | ||
console.log("isStarted", isStarted); | ||
console.log("isStoped", isStoped); | ||
console.log("isToken", isToken); | ||
console.log("this.regstr 1:", this.regstr); | ||
const regstr = | ||
@@ -129,3 +144,2 @@ isMultiple ? | ||
this.regstr += regstr; | ||
// /^[\/]?foo\/?((?:[\/]?.+)+)[\/]?$/ | ||
@@ -132,0 +146,0 @@ const data = { |
{ | ||
"name": "path-to-regex", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "Turn a path string such as /user/:id or /user/:id(\\d+) into a regular expression", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -736,16 +736,88 @@ const PathToRegex = require("../index.js"); | ||
describe("14. Тестируем шаблон '/foo/:bar/:baz'", function () { | ||
const re = new PathToRegex("/foo/:bar/:baz"); | ||
const reend = new PathToRegex("/foo/:bar/:baz", { case: false, toEnd: false }); | ||
console.log("14. REGEXP toEnd[true]:", re.regexp); | ||
console.log("14. REGEXP toEnd[false]:", reend.regexp); | ||
it("14.1 шаблон не совпадает со строкой ''. результат: `undefined`", function () { | ||
assert.equal(re.match(""), undefined); | ||
assert.equal(reend.match(""), undefined); | ||
}); | ||
it("14.2 шаблон не совпадает со строкой '/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/"), undefined); | ||
assert.equal(reend.match("/"), undefined); | ||
}); | ||
describe("14. Тестируем шаблон '/user/:id/bar/:key(\\d+):post?fak/:key(\\d+)*:foo+/test/pictures-:multi(\\w+?\\.png)*/:key?'", function () { | ||
it("14.3 шаблон не совпадает со строкой 'foo'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo"), undefined); | ||
assert.equal(reend.match("foo"), undefined); | ||
}); | ||
it("14.4 шаблон не совпадает со строкой '/foo'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo"), undefined); | ||
assert.equal(reend.match("/foo"), undefined); | ||
}); | ||
it("14.5 шаблон не совпадает со строкой 'foo/'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo/"), undefined); | ||
assert.equal(reend.match("foo/"), undefined); | ||
}); | ||
it("14.6 шаблон не совпадает со строкой '/foo/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/"), undefined); | ||
assert.equal(reend.match("/foo/"), undefined); | ||
}); | ||
it("14.7 шаблон не совпадает со строкой 'foo/bar'. результат: `undefined`. " + re.regexp, function () { | ||
assert.equal(re.match("foo/bar"), undefined); | ||
assert.equal(reend.match("foo/bar"), undefined); | ||
}); | ||
it("14.8 шаблон совпадает со строкой '/foo/bar'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/bar"), undefined); | ||
assert.equal(reend.match("/foo/bar"), undefined); | ||
}); | ||
it("14.9 шаблон совпадает со строкой 'foo/bar/'. результат: `undefined`", function () { | ||
assert.equal(re.match("foo/bar/"), undefined); | ||
assert.equal(reend.match("foo/bar/"), undefined); | ||
}); | ||
it("14.10 шаблон совпадает со строкой '/foo/bar/'. результат: `undefined`", function () { | ||
assert.equal(re.match("/foo/bar/"), undefined); | ||
assert.equal(reend.match("/foo/bar/"), undefined); | ||
}); | ||
it("14.11 шаблон совпадает со строкой 'foo/bar/baz'. результат: `{ bar: 'bar', baz: 'baz' }`", function () { | ||
expect(re.match("foo/bar/baz")).to.deep.equal({ bar: 'bar', baz: 'baz' }); | ||
expect(reend.match("foo/bar/baz")).to.deep.equal({ bar: 'bar', baz: 'baz' }); | ||
}); | ||
it("14.12 шаблон совпадает со строкой 'foo/bar/baz'. результат: `{ bar: 'bar', baz: 'baz' }`", function () { | ||
expect(re.match("/foo/bar/baz")).to.deep.equal({ bar: 'bar', baz: 'baz' }); | ||
expect(reend.match("/foo/bar/baz")).to.deep.equal({ bar: 'bar', baz: 'baz' }); | ||
}); | ||
it("14.13 шаблон совпадает со строкой 'foo/bar/baz'. результат: `{ bar: 'bar', baz: 'baz' }`", function () { | ||
expect(re.match("foo/bar/baz/")).to.deep.equal({ bar: 'bar', baz: 'baz' }); | ||
expect(reend.match("foo/bar/baz/")).to.deep.equal({ bar: 'bar', baz: 'baz' }); | ||
}); | ||
it("14.14 шаблон совпадает со строкой 'foo/bar/baz'. результат: `{ bar: 'bar', baz: 'baz' }`", function () { | ||
expect(re.match("/foo/bar/baz/")).to.deep.equal({ bar: 'bar', baz: 'baz' }); | ||
expect(reend.match("/foo/bar/baz/")).to.deep.equal({ bar: 'bar', baz: 'baz' }); | ||
}); | ||
}); | ||
describe("15. Тестируем шаблон '/user/:id/bar/:key(\\d+):post?fak/:key(\\d+)*:foo+/test/pictures-:multi(\\w+?\\.png)*/:key?'", function () { | ||
const re = new PathToRegex("/user/:id/bar/:key(\\d+):post?fak/:key(\\d+)*:foo+/test/pictures-:multi(\\w+?\\.png)*/:key?"); | ||
console.log("14. REGEXP:", re.regexp); | ||
it("шаблон совпадает со строкой '/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png/333'. \n\tрезультат: `{ id: '123', key: [ '111', '222', '333' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
const reend = new PathToRegex("/user/:id/bar/:key(\\d+):post?fak/:key(\\d+)*:foo+/test/pictures-:multi(\\w+?\\.png)*/:key?", { case: false, toEnd: false }); | ||
console.log("15. REGEXP toEnd[true]: ", re.regexp); | ||
console.log("15. REGEXP toEnd[false]:", reend.regexp); | ||
it("15.1 шаблон совпадает со строкой '/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png/333'. \n\tрезультат: `{ id: '123', key: [ '111', '222', '333' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
expect(re.match("/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png/333")).to.deep.equal({ id: '123', key: ['111', '222', '333'], post: 'qwerty', foo: ['foo'], multi: ['p01.png', 'p02.png', 'p03.png'] }); | ||
expect(reend.match("/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png/333")).to.deep.equal({ id: '123', key: ['111', '222', '333'], post: 'qwerty', foo: ['foo'], multi: ['p01.png', 'p02.png', 'p03.png'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png'. \n\tрезультат: `{ id: '123', key: [ '111', '222' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
it("15.2 шаблон совпадает со строкой '/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png'. \n\tрезультат: `{ id: '123', key: [ '111', '222' ], post: 'qwerty', foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
expect(re.match("/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png")).to.deep.equal({ id: '123', key: ['111', '222'], post: 'qwerty', foo: ['foo'], multi: ['p01.png', 'p02.png', 'p03.png'] }); | ||
expect(reend.match("/user/123/bar/111qwertyfak/222foo/test/pictures-p01.png, p02.png, p03.png")).to.deep.equal({ id: '123', key: ['111', '222'], post: 'qwerty', foo: ['foo'], multi: ['p01.png', 'p02.png', 'p03.png'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/123/bar/111fak/foo/test/pictures-p01.png, p02.png, p03.png'. \n\tрезультат: `{ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
it("15.3 шаблон совпадает со строкой '/user/123/bar/111fak/foo/test/pictures-p01.png, p02.png, p03.png'. \n\tрезультат: `{ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png', 'p02.png', 'p03.png' ] }`", function () { | ||
expect(re.match("/user/123/bar/111fak/foo/test/pictures-p01.png, p02.png, p03.png")).to.deep.equal({ id: '123', key: ['111'], post: undefined, foo: ['foo'], multi: ['p01.png', 'p02.png', 'p03.png'] }); | ||
}); | ||
it("шаблон совпадает со строкой '/user/123/bar/111fak/foo/test/pictures-p01.png'. \n\tрезультат: `{ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png' ] }`", function () { | ||
it("15.4 шаблон совпадает со строкой '/user/123/bar/111fak/foo/test/pictures-p01.png'. \n\tрезультат: `{ id: '123', key: [ '111' ], post: undefined, foo: [ 'foo' ], multi: [ 'p01.png' ] }`", function () { | ||
expect(re.match("/user/123/bar/111fak/foo/test/pictures-p01.png")).to.deep.equal({ id: '123', key: ['111'], post: undefined, foo: ['foo'], multi: ['p01.png'] }); | ||
@@ -767,4 +839,2 @@ }); | ||
// const re2 = new PathToRegex("/user/:id"); | ||
@@ -771,0 +841,0 @@ // // console.log("REGEX:", "\t\t"+re2.regexp, "\t\t", re2.regexp, "\t\t", re2.regstr, "\t\t", re2.path); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
81255
1025
0