Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

himalaya

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

himalaya - npm Package Compare versions

Comparing version 0.2.4 to 0.2.5

12

lib/parser.js

@@ -56,9 +56,11 @@ 'use strict';

// closing tag of the same name
var _len = stack.length;
while (--_len > -1) {
if (tagName === stack[_len].tagName) {
stack = stack.slice(0, _len);
nodes = stack[_len - 1].children;
var currentIndex = stack.length - 1;
while (currentIndex > 0) {
if (tagName === stack[currentIndex].tagName) {
stack = stack.slice(0, currentIndex);
var previousIndex = currentIndex - 1;
nodes = stack[previousIndex].children;
break;
}
currentIndex = currentIndex - 1;
}

@@ -65,0 +67,0 @@ }

{
"name": "himalaya",
"description": "HTML to JSON parser",
"version": "0.2.4",
"version": "0.2.5",
"author": "Chris Andrejewski <christopher.andrejewski@gmail.com>",

@@ -6,0 +6,0 @@ "ava": {

@@ -9,2 +9,4 @@ # Himalaya

[![Build Status](https://travis-ci.org/andrejewski/himalaya.svg?branch=master)](https://travis-ci.org/andrejewski/himalaya)
## Usage

@@ -11,0 +13,0 @@

@@ -46,9 +46,11 @@ export default function parser (tokens, options) {

// closing tag of the same name
let len = stack.length
while (--len > -1) {
if (tagName === stack[len].tagName) {
stack = stack.slice(0, len)
nodes = stack[len - 1].children
let currentIndex = stack.length - 1
while (currentIndex > 0) {
if (tagName === stack[currentIndex].tagName) {
stack = stack.slice(0, currentIndex)
const previousIndex = currentIndex - 1
nodes = stack[previousIndex].children
break
}
currentIndex = currentIndex - 1
}

@@ -55,0 +57,0 @@ }

@@ -50,26 +50,63 @@ import test from 'ava'

test('parser() should handle optional-close tags', t => {
const parserOptions = {
voidTags: [],
closingTags: ['p']
{
const parserOptions = {
voidTags: [],
closingTags: ['p']
}
const str = '<p>This is one<p>This is two</p>'
const tokens = lexer(str, lexerOptions)
const nodes = parser(tokens, parserOptions)
t.deepEqual(nodes, [{
type: 'element',
tagName: 'p',
attributes: [],
children: [{
type: 'text',
content: 'This is one'
}]
}, {
type: 'element',
tagName: 'p',
attributes: [],
children: [{
type: 'text',
content: 'This is two'
}]
}])
}
const str = '<p>This is one<p>This is two</p>'
const tokens = lexer(str, lexerOptions)
const nodes = parser(tokens, parserOptions)
t.deepEqual(nodes, [{
type: 'element',
tagName: 'p',
attributes: [],
children: [{
type: 'text',
content: 'This is one'
}]
}, {
type: 'element',
tagName: 'p',
attributes: [],
children: [{
type: 'text',
content: 'This is two'
}]
}])
{
const parserOptions = {
voidTags: [],
closingTags: ['p', 'span']
}
const str = '<p>This is one <span>okay<p>This is two</p>'
const tokens = lexer(str, lexerOptions)
const nodes = parser(tokens, parserOptions)
t.deepEqual(nodes, [{
type: 'element',
tagName: 'p',
attributes: [],
children: [{
type: 'text',
content: 'This is one '
}, {
type: 'element',
tagName: 'span',
attributes: [],
children: [{
type: 'text',
content: 'okay'
}]
}]
}, {
type: 'element',
tagName: 'p',
attributes: [],
children: [{
type: 'text',
content: 'This is two'
}]
}])
}
})

@@ -76,0 +113,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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