@patternslib/patternslib
Advanced tools
Comparing version 4.6.0 to 4.6.1
{ | ||
"name": "@patternslib/patternslib", | ||
"version": "4.6.0", | ||
"version": "4.6.1", | ||
"title": "Markup patterns to drive behaviour.", | ||
@@ -5,0 +5,0 @@ "description": "Patternslib is a JavaScript library that enables designers to build rich interactive prototypes without the need for writing any Javascript. All events are triggered by classes and other attributes in the HTML, without abusing the HTML as a programming language. Accessibility, SEO and well structured HTML are core values of Patterns.", |
@@ -18,3 +18,3 @@ // Patterns argument parser | ||
this.group_pattern = /([a-z][a-z0-9]*)-([A-Z][a-z0-0\-]*)/i; | ||
this.json_param_pattern = /^\s*{/i; | ||
this.json_param_pattern = /^\s*\[?\s*{/i; | ||
this.named_param_pattern = /^\s*([a-z][a-z0-9\-]*)\s*:(.*)/i; | ||
@@ -446,7 +446,11 @@ this.token_pattern = /((["']).*?(?!\\)\2)|\s*(\S+)\s*/g; | ||
const _parse = this._parse.bind(this); | ||
if (data.match(/&&/)) { | ||
frame = data.split(/\s*&&\s*/).map(_parse); | ||
} else { | ||
frame = [_parse(data)]; | ||
frame = _parse(data); | ||
} | ||
if (!Array.isArray(frame)) { | ||
frame = [frame]; | ||
} | ||
final_length = Math.max(frame.length, final_length); | ||
@@ -453,0 +457,0 @@ stack.push(frame); |
@@ -211,2 +211,108 @@ import _ from "underscore"; | ||
describe("JSON data attributes", function () { | ||
it("parses JSON objects", function (done) { | ||
const parser = new ArgumentParser("mypattern"); | ||
parser.addArgument("arg1", 0); | ||
const content = document.createElement("div"); | ||
content.innerHTML = ` | ||
<div data-pat-mypattern='{ "arg1": 1 }'></div> | ||
`; | ||
const opts = parser.parse(content.querySelector("[data-pat-mypattern]")); | ||
expect(opts).toEqual({ | ||
arg1: 1, | ||
}); | ||
done(); | ||
}); | ||
it("parses JSON arrays", function (done) { | ||
const parser = new ArgumentParser("mypattern"); | ||
parser.addArgument("arg1", 0); | ||
const content = document.createElement("div"); | ||
content.innerHTML = ` | ||
<div data-pat-mypattern='[{ "arg1": 1 }]'></div> | ||
`; | ||
const opts = parser.parse(content.querySelector("[data-pat-mypattern]")); | ||
expect(opts).toEqual({ | ||
arg1: 1, | ||
}); | ||
done(); | ||
}); | ||
it("parses JSON arrays with multiple configs", function (done) { | ||
const parser = new ArgumentParser("mypattern"); | ||
parser.addArgument("arg1", 0); | ||
parser.addArgument("arg2", false); | ||
const content = document.createElement("div"); | ||
content.innerHTML = ` | ||
<div data-pat-mypattern=' | ||
[ | ||
{ | ||
"arg1": 1, | ||
"arg2": true | ||
}, | ||
{ | ||
"arg1": 2, | ||
"arg2": false | ||
} | ||
] | ||
'></div> | ||
`; | ||
const opts = parser.parse( | ||
content.querySelector("[data-pat-mypattern]"), | ||
{}, | ||
true | ||
); | ||
expect(opts.length).toBe(2); | ||
expect(opts[0]).toEqual({ | ||
arg1: 1, | ||
arg2: true, | ||
}); | ||
expect(opts[1]).toEqual({ | ||
arg1: 2, | ||
arg2: false, | ||
}); | ||
done(); | ||
}); | ||
it("parses JSON arrays and includes defaults", function (done) { | ||
const parser = new ArgumentParser("mypattern"); | ||
parser.addArgument("arg1", 0); | ||
parser.addArgument("arg2", "okay"); | ||
parser.addArgument("arg3", false); | ||
const content = document.createElement("div"); | ||
content.innerHTML = ` | ||
<div data-pat-mypattern='{"arg1": 1}'></div> | ||
`; | ||
const opts = parser.parse(content.querySelector("[data-pat-mypattern]")); | ||
expect(opts).toEqual({ | ||
arg1: 1, | ||
arg2: "okay", | ||
arg3: false, | ||
}); | ||
done(); | ||
}); | ||
it("parses JSON arrays and does not include defaults if set so", function (done) { | ||
const parser = new ArgumentParser("mypattern"); | ||
parser.addArgument("arg1", 0); | ||
parser.addArgument("arg2", "okay"); | ||
parser.addArgument("arg3", false); | ||
const content = document.createElement("div"); | ||
content.innerHTML = ` | ||
<div data-pat-mypattern='{"arg1": 1}'></div> | ||
`; | ||
const opts = parser.parse( | ||
content.querySelector("[data-pat-mypattern]"), | ||
{}, | ||
false, | ||
false | ||
); | ||
expect(opts).toEqual({ | ||
arg1: 1, | ||
}); | ||
done(); | ||
}); | ||
}); | ||
describe("the shorthand notation", function () { | ||
@@ -213,0 +319,0 @@ it("Single argument", function () { |
Sorry, the diff of this file is too big to display
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
7300605
39827