Comparing version 2.0.4 to 3.0.0-canary-1
60
index.js
@@ -9,6 +9,6 @@ 'use strict'; | ||
function isConstant(src) { | ||
return constantinople(src, {pug: runtime, 'pug_interp': undefined}); | ||
return constantinople(src, {pug: runtime, pug_interp: undefined}); | ||
} | ||
function toConstant(src) { | ||
return constantinople.toConstant(src, {pug: runtime, 'pug_interp': undefined}); | ||
return constantinople.toConstant(src, {pug: runtime, pug_interp: undefined}); | ||
} | ||
@@ -25,12 +25,20 @@ | ||
assert(Array.isArray(attrs), 'Attrs should be an array'); | ||
assert(attrs.every(function (attr) { | ||
return attr && | ||
typeof attr === 'object' && | ||
typeof attr.name === 'string' && | ||
(typeof attr.val === 'string' || typeof attr.val === 'boolean') && | ||
typeof attr.mustEscape === 'boolean'; | ||
}), 'All attributes should be supplied as an object of the form {name, val, mustEscape}'); | ||
assert( | ||
attrs.every(function(attr) { | ||
return ( | ||
attr && | ||
typeof attr === 'object' && | ||
typeof attr.name === 'string' && | ||
(typeof attr.val === 'string' || typeof attr.val === 'boolean') && | ||
typeof attr.mustEscape === 'boolean' | ||
); | ||
}), | ||
'All attributes should be supplied as an object of the form {name, val, mustEscape}' | ||
); | ||
assert(options && typeof options === 'object', 'Options should be an object'); | ||
assert(typeof options.terse === 'boolean', 'Options.terse should be a boolean'); | ||
assert( | ||
typeof options.terse === 'boolean', | ||
'Options.terse should be a boolean' | ||
); | ||
assert( | ||
typeof options.runtime === 'function', | ||
@@ -51,3 +59,5 @@ 'Options.runtime should be a function that takes a runtime function name and returns the source code that will evaluate to that function at runtime' | ||
if (options.format === 'html') { | ||
var str = stringify(runtime.attr(key, toConstant(val), mustEscape, options.terse)); | ||
var str = stringify( | ||
runtime.attr(key, toConstant(val), mustEscape, options.terse) | ||
); | ||
var last = buf[buf.length - 1]; | ||
@@ -68,3 +78,14 @@ if (last && last[last.length - 1] === str[0]) { | ||
if (options.format === 'html') { | ||
buf.push(options.runtime('attr') + '("' + key + '", ' + val + ', ' + stringify(mustEscape) + ', ' + stringify(options.terse) + ')'); | ||
buf.push( | ||
options.runtime('attr') + | ||
'("' + | ||
key + | ||
'", ' + | ||
val + | ||
', ' + | ||
stringify(mustEscape) + | ||
', ' + | ||
stringify(options.terse) + | ||
')' | ||
); | ||
} else { | ||
@@ -79,3 +100,3 @@ if (mustEscape) { | ||
attrs.forEach(function(attr){ | ||
attrs.forEach(function(attr) { | ||
var key = attr.name; | ||
@@ -109,5 +130,7 @@ var val = attr.val; | ||
} else { | ||
classes = classes.map(function (cls, i) { | ||
classes = classes.map(function(cls, i) { | ||
if (isConstant(cls)) { | ||
cls = stringify(classEscaping[i] ? runtime.escape(toConstant(cls)) : toConstant(cls)); | ||
cls = stringify( | ||
classEscaping[i] ? runtime.escape(toConstant(cls)) : toConstant(cls) | ||
); | ||
classEscaping[i] = false; | ||
@@ -119,3 +142,8 @@ } | ||
'class', | ||
options.runtime('classes') + '([' + classes.join(',') + '], ' + stringify(classEscaping) + ')', | ||
options.runtime('classes') + | ||
'([' + | ||
classes.join(',') + | ||
'], ' + | ||
stringify(classEscaping) + | ||
')', | ||
false, | ||
@@ -122,0 +150,0 @@ classesBuf |
{ | ||
"name": "pug-attrs", | ||
"version": "2.0.4", | ||
"version": "3.0.0-canary-1", | ||
"description": "Generate code for Pug attributes", | ||
@@ -9,5 +9,5 @@ "keywords": [ | ||
"dependencies": { | ||
"constantinople": "^3.0.1", | ||
"js-stringify": "^1.0.1", | ||
"pug-runtime": "^2.0.5" | ||
"constantinople": "^4.0.1", | ||
"js-stringify": "^1.0.2", | ||
"pug-runtime": "3.0.0-canary-1" | ||
}, | ||
@@ -22,4 +22,3 @@ "files": [ | ||
"author": "Forbes Lindesay", | ||
"license": "MIT", | ||
"gitHead": "1bdf628a70fda7a0d840c52f3abce54b1c6b0130" | ||
"license": "MIT" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
7933
143
2
1
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Addedconstantinople@4.0.1(transitive)
+ Addedpug-runtime@3.0.0-canary-1(transitive)
- Removed@types/babel-types@7.0.16(transitive)
- Removed@types/babylon@6.16.9(transitive)
- Removedbabel-runtime@6.26.0(transitive)
- Removedbabel-types@6.26.0(transitive)
- Removedbabylon@6.18.0(transitive)
- Removedconstantinople@3.1.2(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedesutils@2.0.3(transitive)
- Removedlodash@4.17.21(transitive)
- Removedpug-runtime@2.0.5(transitive)
- Removedregenerator-runtime@0.11.1(transitive)
- Removedto-fast-properties@1.0.3(transitive)
Updatedconstantinople@^4.0.1
Updatedjs-stringify@^1.0.2
Updatedpug-runtime@3.0.0-canary-1