escape-html-template-tag
Advanced tools
Comparing version 2.0.4 to 2.1.0
@@ -11,1 +11,5 @@ # Changelog | ||
- Fix export style for require in node.js | ||
## 2.1.0 | ||
- improve types |
@@ -1,12 +0,12 @@ | ||
export declare function join(array: any, separator: any): HtmlSafeString; | ||
export declare function safe(value: any): HtmlSafeString; | ||
declare class HtmlSafeString { | ||
declare const inspect: unique symbol; | ||
export declare function join(array: (string | HtmlSafeString)[], separator: string | HtmlSafeString): HtmlSafeString; | ||
export declare function safe(value: unknown): HtmlSafeString; | ||
export declare class HtmlSafeString { | ||
private _parts; | ||
private _subs; | ||
constructor(parts: string[], subs: unknown[]); | ||
private _escapeHtml; | ||
constructor(parts: readonly string[], subs: readonly unknown[]); | ||
toString(): string; | ||
inspect(): string; | ||
[inspect](): string; | ||
} | ||
export default function escapeHtml(parts: any, ...subs: any[]): HtmlSafeString; | ||
export default function escapeHtml(parts: TemplateStringsArray, ...subs: unknown[]): HtmlSafeString; | ||
export {}; |
@@ -1,2 +0,76 @@ | ||
var t={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},n=new RegExp(Object.keys(t).join("|"),"g");function r(t,n){return null==n&&(n=","),t.length<=0?new e([""],[]):new e([""].concat(Array(t.length-1).fill(n),[""]),t)}var e=function(){function e(t,n){this._parts=t,this._subs=n}var i=e.prototype;return i._escapeHtml=function(i){return i instanceof e?i:Array.isArray(i)?r(i,""):String(i).replace(n,function(n){return t[n]})},i.toString=function(){var t=this;return this._parts.reduce(function(n,r,e){return n+t._escapeHtml(t._subs[e-1])+r})},i.inspect=function(){return this.constructor.name+" '"+this.toString()+"'"},e}();function i(t){return new e(t,[].slice.call(arguments,1))}var u=Object.assign(i,{default:i,join:r,safe:function(t){return new e([String(t)],[])}});module.exports=u; | ||
var ENTITIES = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": ''', | ||
'/': '/', | ||
'`': '`', | ||
'=': '=' | ||
}; | ||
var inspect = Symbol["for"]('nodejs.util.inspect.custom'); | ||
var ENT_REGEX = new RegExp(Object.keys(ENTITIES).join('|'), 'g'); | ||
function join(array, separator) { | ||
if (separator === undefined || separator === null) { | ||
separator = ','; | ||
} | ||
if (array.length <= 0) { | ||
return new HtmlSafeString([''], []); | ||
} | ||
return new HtmlSafeString([''].concat(Array(array.length - 1).fill(separator), ['']), array); | ||
} | ||
function safe(value) { | ||
return new HtmlSafeString([String(value)], []); | ||
} | ||
function escapehtml(unsafe) { | ||
if (unsafe instanceof HtmlSafeString) { | ||
return unsafe.toString(); | ||
} | ||
if (Array.isArray(unsafe)) { | ||
return join(unsafe, '').toString(); | ||
} | ||
return String(unsafe).replace(ENT_REGEX, function (_char) { | ||
return ENTITIES[_char]; | ||
}); | ||
} | ||
var HtmlSafeString = /*#__PURE__*/function () { | ||
function HtmlSafeString(parts, subs) { | ||
this._parts = parts; | ||
this._subs = subs; | ||
} | ||
var _proto = HtmlSafeString.prototype; | ||
_proto.toString = function toString() { | ||
var _this = this; | ||
return this._parts.reduce(function (result, part, i) { | ||
var sub = _this._subs[i - 1]; | ||
return result + escapehtml(sub) + part; | ||
}); | ||
}; | ||
_proto[inspect] = function () { | ||
return "HtmlSafeString '" + this.toString() + "'"; | ||
}; | ||
return HtmlSafeString; | ||
}(); | ||
function escapeHtml(parts) { | ||
return new HtmlSafeString(parts, [].slice.call(arguments, 1)); | ||
} | ||
var index_cjs = Object.assign(escapeHtml, { | ||
"default": escapeHtml, | ||
join: join, | ||
safe: safe | ||
}); | ||
module.exports = index_cjs; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,83 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n||self).escapeHtmlTemplateTag=t()}(this,function(){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},t=new RegExp(Object.keys(n).join("|"),"g");function e(n,t){return null==t&&(t=","),n.length<=0?new r([""],[]):new r([""].concat(Array(n.length-1).fill(t),[""]),n)}var r=function(){function r(n,t){this._parts=n,this._subs=t}var i=r.prototype;return i._escapeHtml=function(i){return i instanceof r?i:Array.isArray(i)?e(i,""):String(i).replace(t,function(t){return n[t]})},i.toString=function(){var n=this;return this._parts.reduce(function(t,e,r){return t+n._escapeHtml(n._subs[r-1])+e})},i.inspect=function(){return this.constructor.name+" '"+this.toString()+"'"},r}();function i(n){return new r(n,[].slice.call(arguments,1))}return Object.assign(i,{default:i,join:e,safe:function(n){return new r([String(n)],[])}})}); | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.escapeHtmlTemplateTag = factory()); | ||
}(this, (function () { | ||
var ENTITIES = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": ''', | ||
'/': '/', | ||
'`': '`', | ||
'=': '=' | ||
}; | ||
var inspect = Symbol["for"]('nodejs.util.inspect.custom'); | ||
var ENT_REGEX = new RegExp(Object.keys(ENTITIES).join('|'), 'g'); | ||
function join(array, separator) { | ||
if (separator === undefined || separator === null) { | ||
separator = ','; | ||
} | ||
if (array.length <= 0) { | ||
return new HtmlSafeString([''], []); | ||
} | ||
return new HtmlSafeString([''].concat(Array(array.length - 1).fill(separator), ['']), array); | ||
} | ||
function safe(value) { | ||
return new HtmlSafeString([String(value)], []); | ||
} | ||
function escapehtml(unsafe) { | ||
if (unsafe instanceof HtmlSafeString) { | ||
return unsafe.toString(); | ||
} | ||
if (Array.isArray(unsafe)) { | ||
return join(unsafe, '').toString(); | ||
} | ||
return String(unsafe).replace(ENT_REGEX, function (_char) { | ||
return ENTITIES[_char]; | ||
}); | ||
} | ||
var HtmlSafeString = /*#__PURE__*/function () { | ||
function HtmlSafeString(parts, subs) { | ||
this._parts = parts; | ||
this._subs = subs; | ||
} | ||
var _proto = HtmlSafeString.prototype; | ||
_proto.toString = function toString() { | ||
var _this = this; | ||
return this._parts.reduce(function (result, part, i) { | ||
var sub = _this._subs[i - 1]; | ||
return result + escapehtml(sub) + part; | ||
}); | ||
}; | ||
_proto[inspect] = function () { | ||
return "HtmlSafeString '" + this.toString() + "'"; | ||
}; | ||
return HtmlSafeString; | ||
}(); | ||
function escapeHtml(parts) { | ||
return new HtmlSafeString(parts, [].slice.call(arguments, 1)); | ||
} | ||
var index_cjs = Object.assign(escapeHtml, { | ||
"default": escapeHtml, | ||
join: join, | ||
safe: safe | ||
}); | ||
return index_cjs; | ||
}))); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "escape-html-template-tag", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Tag literal strings with this function to html escape interpolated values", | ||
@@ -15,4 +15,4 @@ "source": "src/index.ts", | ||
"scripts": { | ||
"test": "standard && node test/index.test.js", | ||
"prepublish": "rm -rf dist && microbundle -f cjs,umd src/index.cjs.ts && microbundle -f es,modern src/index.ts && mv dist/index.modern.js dist/index.modern.mjs && mv dist/index.modern.js.map dist/index.modern.mjs.map" | ||
"test": "tsc --noEmit --strict src/* && standard && node test/index.test.js", | ||
"prepublish": "rm -rf dist && microbundle --no-compress -f cjs,umd src/index.cjs.ts && microbundle --no-compress -f es,modern src/index.ts && mv dist/index.modern.js dist/index.modern.mjs && mv dist/index.modern.js.map dist/index.modern.mjs.map" | ||
}, | ||
@@ -40,3 +40,4 @@ "repository": { | ||
"microbundle": "^0.13.0", | ||
"standard": "14.3.1" | ||
"standard": "14.3.1", | ||
"typescript": "^4.2.4" | ||
}, | ||
@@ -43,0 +44,0 @@ "standard": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
26989
264
3
1