Socket
Socket
Sign inDemoInstall

htmljs-parser

Package Overview
Dependencies
Maintainers
5
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmljs-parser - npm Package Compare versions

Comparing version 2.11.2 to 3.0.0

dist/core/Parser.d.ts

97

package.json
{
"name": "htmljs-parser",
"description": "An HTML parser recognizes content and string placeholders and allows JavaScript expressions as attribute values",
"version": "3.0.0",
"author": "Phillip Gates-Idem <phillip.idem@gmail.com>",
"devDependencies": {
"@commitlint/cli": "^16.2.3",
"@commitlint/config-conventional": "^16.2.1",
"@types/benchmark": "^2.1.1",
"@types/degit": "^2.8.3",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.22",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"benchmark": "^2.1.4",
"cross-env": "^7.0.3",
"degit": "^2.8.4",
"esbuild": "0.14.27",
"esbuild-register": "^3.3.2",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
"fast-glob": "^3.2.11",
"fixpack": "^4.0.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.7",
"mocha": "^9.2.2",
"mocha-snap": "^4.3.0",
"nyc": "^15.1.0",
"prettier": "^2.6.0",
"semantic-release": "^19.0.2",
"typescript": "^4.6.2"
},
"exports": {
".": {
"import": "./dist/index.mjs",
"default": "./dist/index.js"
}
},
"files": [
"dist",
"!**/__tests__",
"!**/*.tsbuildinfo"
],
"homepage": "https://github.com/marko-js/htmljs-parser",
"keywords": [
"HTML",
"parser",
"JavaScript",
"browser",
"compiler",
"expressions",
"browser",
"nodejs",
"parser",
"server",
"nodejs",
"template",
"compiler"
"template"
],
"main": "index.js",
"scripts": {
"test": "npm run mocha && npm run jshint",
"mocha": "node_modules/.bin/mocha --ui bdd --reporter spec ./test",
"jshint": "node_modules/.bin/jshint *.js"
},
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"repository": {
"type": "git",
"url": "https://github.com/philidem/htmljs-parser.git"
"url": "https://github.com/marko-js/htmljs-parser.git"
},
"author": "Phillip Gates-Idem <phillip.idem@gmail.com>",
"maintainers": "Phillip Gates-Idem <phillip.idem@gmail.com>",
"dependencies": {
"char-props": "^0.1.5",
"complain": "^1.0.0"
"scripts": {
"bench": "npm run build && node -r esbuild-register ./src/__tests__/bench",
"build": "tsc -b && node -r esbuild-register build",
"ci:test": "nyc npm run mocha -- --forbid-pending --forbid-only",
"format": "npm run lint:eslint -- --fix && npm run lint:prettier -- --write && (fixpack || true)",
"lint": "tsc -b && npm run lint:eslint && npm run lint:prettier -- -l && fixpack",
"lint:eslint": "eslint -f visualstudio .",
"lint:prettier": "prettier \"./**/*{.ts,.js,.json,.md,.yml,rc}\"",
"mocha": "cross-env NODE_ENV=test mocha \"./src/**/__tests__/*.test.ts\"",
"prepare": "husky install",
"prepublishOnly": "npm run build",
"release": "semantic-release",
"report": "open ./coverage/lcov-report/index.html",
"test": "npm run mocha -- --watch",
"test:inspect": "npm test -- --inspect",
"test:update": "npm run mocha -- --update"
},
"devDependencies": {
"@babel/runtime": "^7.12.5",
"chai": "^4.0.0",
"colors": "^1.1.2",
"jshint": "^2.8.0",
"mocha": "^4.0.0",
"mocha-autotest": "^1.0.3"
},
"license": "MIT",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"version": "2.11.2"
"types": "dist/index.d.ts"
}

@@ -1,3 +0,2 @@

htmljs-parser
=============
# htmljs-parser

@@ -15,3 +14,2 @@ HTML parsers written according to the HTML spec will interpret all

Ideally, the template compiler should be able to handle any of the following:

@@ -28,16 +26,21 @@

- JavaScript expressions as attribute values
```html
<say-hello message=("Hello " + personName) count=2+2 large=true />
```
- Placeholders in the content of an element
```html
<div>
Hello ${personName}
</div>
<div>Hello ${personName}</div>
```
- Placeholders within attribute value strings
```html
<div data-message="Hello ${personName}!">
<div data-message="Hello ${personName}!"></div>
```
- JavaScript flow-control statements within HTML elements
```html

@@ -47,6 +50,7 @@ <div for(a in b) />

```
- JavaScript flow-control statements as elements
```html
<for (a in b)>
<if (a in b)>
<for (a in b)> <if (a in b)></if></for>
```

@@ -63,81 +67,78 @@

```javascript
var parser = require('htmljs-parser').createParser({
onText: function(event) {
// Text within an HTML element
var value = event.value;
},
var parser = require("htmljs-parser").createParser({
onText: function (event) {
// Text within an HTML element
var value = event.value;
},
onPlaceholder: function(event) {
// ${<value>]} // escape = true
// $!{<value>]} // escape = false
var value = event.value; // String
var escaped = event.escaped; // boolean
var withinBody = event.withinBody; // boolean
var withinAttribute = event.withinAttribute; // boolean
var withinString = event.withinString; // boolean
var withinOpenTag = event.withinOpenTag; // boolean
var pos = event.pos; // Integer
},
onPlaceholder: function (event) {
// ${<value>]} // escape = true
// $!{<value>]} // escape = false
var value = event.value; // String
var escaped = event.escaped; // boolean
var withinBody = event.withinBody; // boolean
var withinAttribute = event.withinAttribute; // boolean
var withinOpenTag = event.withinOpenTag; // boolean
var pos = event.pos; // Integer
},
onString: function(event) {
// Text within ""
var value = event.value; // String
var stringParts = event.stringParts; // Array
var isStringLiteral = event.isStringLiteral // Boolean
var pos = event.pos; // Integer
},
onString: function (event) {
// Text within ""
var value = event.value; // String
var pos = event.pos; // Integer
},
onCDATA: function(event) {
// <![CDATA[<value>]]>
var value = event.value; // String
var pos = event.pos; // Integer
},
onCDATA: function (event) {
// <![CDATA[<value>]]>
var value = event.value; // String
var pos = event.pos; // Integer
},
onOpenTag: function(event) {
var tagName = event.tagName; // String
var attributes = event.attributes; // Array
var argument = event.argument; // Object
var pos = event.pos; // Integer
},
onOpenTag: function (event) {
var tagName = event.tagName; // String
var attributes = event.attributes; // Array
var argument = event.argument; // Object
var pos = event.pos; // Integer
},
onCloseTag: function(event) {
// close tag
var tagName = event.tagName; // String
var pos = event.pos; // Integer
},
onCloseTag: function (event) {
// close tag
var tagName = event.tagName; // String
var pos = event.pos; // Integer
},
onDocumentType: function(event) {
// Document Type/DTD
// <!<value>>
// Example: <!DOCTYPE html>
var value = event.value; // String
var pos = event.pos; // Integer
},
onDocumentType: function (event) {
// Document Type/DTD
// <!<value>>
// Example: <!DOCTYPE html>
var value = event.value; // String
var pos = event.pos; // Integer
},
onDeclaration: function(event) {
// Declaration
// <?<value>?>
// Example: <?xml version="1.0" encoding="UTF-8" ?>
var value = event.value; // String
var pos = event.pos; // Integer
},
onDeclaration: function (event) {
// Declaration
// <?<value>?>
// Example: <?xml version="1.0" encoding="UTF-8" ?>
var value = event.value; // String
var pos = event.pos; // Integer
},
onComment: function(event) {
// Text within XML comment
var value = event.value; // String
var pos = event.pos; // Integer
},
onComment: function (event) {
// Text within XML comment
var value = event.value; // String
var pos = event.pos; // Integer
},
onScriptlet: function(event) {
// Text within <% %>
var value = event.value; // String
var pos = event.pos; // Integer
},
onScriptlet: function (event) {
// Text within <% %>
var value = event.value; // String
var pos = event.pos; // Integer
},
onError: function(event) {
// Error
var message = event.message; // String
var code = event.code; // String
var pos = event.pos; // Integer
}
onError: function (event) {
// Error
var message = event.message; // String
var code = event.code; // String
var pos = event.pos; // Integer
},
});

@@ -157,11 +158,11 @@

- **HTML Content (DEFAULT):**
The parser will look for any HTML tag and content placeholders while in
this mode and parse opening and closing tags accordingly.
The parser will look for any HTML tag and content placeholders while in
this mode and parse opening and closing tags accordingly.
- **Parsed Text Content**: The parser will look for the closing tag that matches
the current open tag as well as content placeholders but all other content
will be interpreted as text.
the current open tag as well as content placeholders but all other content
will be interpreted as text.
- **Static Text Content**: The parser will look for the closing tag that matches
the current open tag but all other content will be interpreted as raw text.
the current open tag but all other content will be interpreted as raw text.

@@ -216,3 +217,3 @@ ```javascript

```html
<div>
<div></div>
```

@@ -235,3 +236,3 @@

```html
<div class="demo" disabled=false data-number=123>
<div class="demo" disabled="false" data-number="123"></div>
```

@@ -248,14 +249,11 @@

name: 'class',
value: '"demo"',
literalValue: 'demo'
value: '"demo"'
},
{
name: 'disabled',
value: 'false',
literalValue: false
value: 'false'
},
{
name: 'data-number',
value: '123',
literalValue: 123
value: '123'
}

@@ -294,3 +292,3 @@ ]

```html
<for(var i = 0; i < 10; i++)>
<for(var i="0;" i < 10; i++)></for(var>
```

@@ -317,3 +315,3 @@

```html
<div if(x > y)>
<div if(x>y)></div>
```

@@ -430,4 +428,3 @@

```html
${"This is an escaped placeholder"}
$!{"This is a non-escaped placeholder"}
${"This is an escaped placeholder"} $!{"This is a non-escaped placeholder"}
```

@@ -449,3 +446,3 @@

--------
---

@@ -452,0 +449,0 @@ ```html

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