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

attribute-analyzer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attribute-analyzer - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

42

index.js
export class EmptyAttribute {}
export function getAttributes(element) {
const localName = getLocalName(element);
element = element.replace("<"+localName, '');
if(element.endsWith(`</${localName}>`)) element = element.slice(0, -(`</${localName}>`.length));
if(element.endsWith(`/>`)) element = element.slice(0, -(`/>`.length));
if(element.endsWith(`>`)) element = element.slice(0, -(`>`.length));
const attributes = parseAttributes(element);
return correctify(attributes);
element = element.trim()
const localName = getLocalName(element)
//determine it is a self closing tag
if (element.endsWith(`/>`) && element.startsWith(`<${localName}`)) {
const lastIndexOf = element.lastIndexOf(`/>`)
element = element.slice(localName.length + 1, lastIndexOf).trim()
} else if (element.endsWith(`</${localName}>`) && element.startsWith(`<${localName}`)) {
element = element.slice(localName.length + 1, -localName.length - 3).trim()
const lastIndexOf = element.lastIndexOf(`>`)
element = element.slice(0, lastIndexOf).trim()
} else {
throw new Error("Parsing Error: Element does not have a closing tag")
}
const attributes = parseAttributes(element);
return correctify(attributes);
}

@@ -16,3 +30,3 @@

Object.keys(attributes).forEach(key => {
if(key == "") {
if (key == "") {
newobj[attributes[key]] = new EmptyAttribute();

@@ -66,8 +80,8 @@ } else {

export function getLocalName(input) {
const openingTagEndIndex = input.indexOf('>');
const tagStringWithoutClosingSlash = input.slice(0, openingTagEndIndex).trimEnd();
const tagName = tagStringWithoutClosingSlash.split(' ')[0].replace("<", '');
return tagName;
const openingTagEndIndex = input.indexOf('>');
const tagStringWithoutClosingSlash = input.slice(0, openingTagEndIndex).trimEnd();
const tagName = tagStringWithoutClosingSlash.split(' ')[0].replace("<", '');
return tagName;
}
{
"name": "attribute-analyzer",
"version": "1.0.4",
"version": "1.0.5",
"description": "Parse your complex element attributes with ease",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,3 +12,3 @@ <h1 align="center">attribute-analyzer</h1>

const input = `<a style="background-color: {red}" :data={"sa" + hello} test="yes" selected on:click='{() => alert("{}")}'></a>`;
const input = `<a style="background-color: {red}" :data={"sa" + hello} test="yes" selected on:click='{() => alert("{}")}'>hello</a>`;

@@ -15,0 +15,0 @@ //Getting the local name

import {EmptyAttribute, getAttributes, getLocalName } from "./index.js";
const input = `<a style="background-color: {red}" :data={"sa" + hello} test="yes" selected on:click='{() => alert("{}")}'></a>`;
const input = `<a style="background-color: {red};" :data={"sa" + hello} test="yes" selected on:click='{() => alert("{}")}'/>`;
const attributes = getAttributes(input);
console.log(getLocalName(input))
console.log(attributes)
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