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

html-attribute-sorter

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-attribute-sorter - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

dist/types/strategy/vuejs.d.ts

12

CHANGELOG.md
# Changelog
## [0.3.0](https://www.github.com/shufo/html-attribute-sorter/compare/v0.2.1...v0.3.0) (2022-08-06)
### Features
* 🎸 add vuejs sorting strategy ([3d4219f](https://www.github.com/shufo/html-attribute-sorter/commit/3d4219f9ae26b83714b4ac43ad6c24eed7b8e412))
### Fixes
* 🐛 unexpected custom directive position for vuejs order ([c40d0ad](https://www.github.com/shufo/html-attribute-sorter/commit/c40d0ad1c9ffe9d21886406727fd2edd7e5e2c68))
### [0.2.1](https://www.github.com/shufo/html-attribute-sorter/compare/v0.2.0...v0.2.1) (2022-08-06)

@@ -4,0 +16,0 @@

2

dist/main.js

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

"use strict";var l=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var x=(r,t)=>{for(var e in t)l(r,e,{get:t[e],enumerable:!0})},A=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of h(t))!y.call(r,s)&&s!==e&&l(r,s,{get:()=>t[s],enumerable:!(o=_(t,s))||o.enumerable});return r};var w=r=>A(l({},"__esModule",{value:!0}),r);var T={};x(T,{sortAttributes:()=>b});module.exports=w(T);var a=class{constructor(t){this.strategy=t}setStrategy(t){this.strategy=t}sort(t){return this.strategy.sort(t)}};var g=class{sort(t){return t.sort()}};var c=class{constructor(){this.orderedAttrsRegex=["class","id","name","data-.+","ng-.+","src","for","type","href","value","values","title","alt","role","aria-.+","tabindex","style"]}sort(t){let e=[];this.orderedAttrsRegex.forEach(s=>{t.forEach(n=>{new RegExp(`^${s}`).test(n)&&e.push(n)})});let o=t.filter(s=>e.indexOf(s)===-1).sort();return e.concat(o)}};var p=class{constructor(){this.orderedAttrsRegex=["class","id","data-.+"]}sort(t){let e=[];this.orderedAttrsRegex.forEach(s=>{t.forEach(n=>{new RegExp(`^${s}`).test(n)&&e.push(n)})});let o=t.filter(s=>e.indexOf(s)===-1).sort();return e.concat(o)}};var f=[],m=[];function b(r,t={order:"code_guide"}){let e=r.replace(/<(?!\/)(?:"[^"]*"|'[^']*'|[^"'])*?>/g,o=>E(o));return I(e,t)}function E(r){let t=f.push(r)-1;return R(t.toString())}function O(r,t){let e=m.push(t)-1;return v(r,e.toString())}function R(r){return"___sort_tags_#___".replace("#",r)}function v(r,t){return`${r}_attrs_#___`.replace("#",t)}function I(r,t){return r.replace(/___sort_tags_(\d+)___/g,(e,o)=>{let n=f[o].replace(/([-:.\w\d]+)=("[^"]*"|'[^']*'|[^"'])/g,(i,d)=>O(d,i));return $(n,t).replace(/[-:.\w\d]+_attrs_(\d+)___/g,(i,d)=>m[d])})}function $(r,t){let e=P(t.order),o=new a(e);return r.replace(/(?<=<[-:.\w\d]+\s)[^>]*?(?=\/?>)/g,s=>{let u=s.split(/\s/).filter(i=>i.length>0);return o.sort(u).join(" ")})}function P(r){switch(r){case"alphabetical":return new g;case"code_guide":return new c;case"idiomatic":return new p}}0&&(module.exports={sortAttributes});
"use strict";var u=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var I=(r,t)=>{for(var e in t)u(r,e,{get:t[e],enumerable:!0})},O=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of E(t))!v.call(r,s)&&s!==e&&u(r,s,{get:()=>t[s],enumerable:!(i=_(t,s))||i.enumerable});return r};var x=r=>O(u({},"__esModule",{value:!0}),r);var b={};I(b,{sortAttributes:()=>y});module.exports=x(b);var g=class{constructor(t){this.strategy=t}setStrategy(t){this.strategy=t}sort(t){return this.strategy.sort(t)}};var p=class{sort(t){return t.sort()}};var d=class{constructor(){this.orderedAttrsRegex=["class","id","name","data-.+","ng-.+","src","for","type","href","value","values","title","alt","role","aria-.+","tabindex","style"]}sort(t){let e=[];this.orderedAttrsRegex.forEach(s=>{t.forEach(n=>{new RegExp(`^${s}`).test(n)&&e.push(n)})});let i=t.filter(s=>e.indexOf(s)===-1).sort();return e.concat(i)}};var l=class{constructor(){this.orderedAttrsRegex=["class","id","data-.+"]}sort(t){let e=[];this.orderedAttrsRegex.forEach(s=>{t.forEach(n=>{new RegExp(`^${s}`).test(n)&&e.push(n)})});let i=t.filter(s=>e.indexOf(s)===-1).sort();return e.concat(i)}};var f=class{constructor(){this.DEFINITION=["is","v-is"];this.LIST_RENDERING=["v-for"];this.CONDITIONALS=["v-if","v-else-if","v-else","v-show","v-cloak"];this.RENDER_MODIFIERS=["v-once","v-pre"];this.GLOBAL=["id"];this.UNIQUE=["ref","key"];this.SLOT=["v-slot","slot"];this.TWO_WAY_BINDING=["v-model"];this.OTHER_DIRECTIVES=/v-[-:\w\d]+/g;this.EVENTS=["@click","v-on="];this.CONTENT=["v-text","v-html"];this.headingOrderedAttrsRegex=[...this.DEFINITION,...this.LIST_RENDERING,...this.CONDITIONALS,...this.RENDER_MODIFIERS,...this.GLOBAL,...this.UNIQUE,...this.SLOT,...this.TWO_WAY_BINDING];this.tailOrderedAttrsRegex=[...this.EVENTS,...this.CONTENT]}sort(t){let e=[],i=[];this.headingOrderedAttrsRegex.forEach(o=>{t.forEach(a=>{new RegExp(`^${o}`).test(a)&&e.push(a)})}),this.tailOrderedAttrsRegex.forEach(o=>{t.forEach(a=>{new RegExp(`^${o}`).test(a)&&i.push(a)})});let s=t.filter(o=>e.indexOf(o)===-1).filter(o=>i.indexOf(o)===-1),n=s.filter(o=>this.OTHER_DIRECTIVES.test(o)),c=s.filter(o=>n.indexOf(o)===-1);return e.concat(n).concat(c).concat(i)}};var S=[],m=[];function y(r,t={order:"code_guide"}){let e=r.replace(/<(?!\/)[-:.\w\d@]+\s(?:"[^"]*"|'[^']*'|[^"'])*?>/g,i=>N(i));return w(e,t)}function N(r){let t=S.push(r)-1;return T(t.toString())}function R(r,t){let e=m.push(t)-1;return A(r,e.toString())}function T(r){return"___sort_tags_#___".replace("#",r)}function A(r,t){return`${r}_attrs_#___`.replace("#",t)}function w(r,t){return r.replace(/___sort_tags_(\d+)___/g,(e,i)=>{let n=S[i].replace(/([-:.\w\d]+)=("[^"]*"|'[^']*'|[^"'])/g,(a,h)=>R(h,a));return D(n,t).replace(/[-:.\w\d]+_attrs_(\d+)___/g,(a,h)=>m[h])})}function D(r,t){let e=L(t.order),i=new g(e);return r.replace(/(?<=<[-:.\w\d]+\s)[^>]*?(?=\/?>)/g,s=>{let c=s.split(/\s/).filter(a=>a.length>0);return i.sort(c).join(" ")})}function L(r){switch(r){case"alphabetical":return new p;case"code_guide":return new d;case"idiomatic":return new l;case"vuejs":return new f}throw new Error("You can specify only [alphabetical|code_guide|idiomatic|vuejs] for sorting order")}0&&(module.exports={sortAttributes});
//# sourceMappingURL=main.js.map

@@ -1,4 +0,4 @@

export declare type Strategy = "alphabetical" | "code_guide" | "idiomatic";
export declare type Strategy = "alphabetical" | "code_guide" | "idiomatic" | "vuejs";
export interface ISortOption {
order: Strategy;
}
{
"name": "html-attribute-sorter",
"version": "0.2.1",
"version": "0.3.0",
"description": "An html attribute sorter",

@@ -5,0 +5,0 @@ "main": "dist/main.js",

@@ -8,3 +8,3 @@ [![npm](https://img.shields.io/npm/v/html-attribute-sorter)](https://www.npmjs.com/package/html-attribute-sorter)

You can sort attributes by alphabetical, [code guide](https://codeguide.co/#attribute-order) or [idiomatic](https://github.com/necolas/idiomatic-html#attribute-order) order.
You can sort attributes by alphabetical, [code guide](https://codeguide.co/#attribute-order), [vue/attributes-order](https://eslint.vuejs.org/rules/attributes-order.html) or [idiomatic](https://github.com/necolas/idiomatic-html#attribute-order) order.

@@ -79,5 +79,5 @@ ## Installation

| key | value |
| ----- | ----------------------------------------------------------------------------------------------------------------- |
| order | An order to sort attributes. You can specify `alphabetical`, `code_guide` or `idiomatic`. default: `code_guide` |
| key | value |
| ----- | ------------------------------------------------------------------------------------------------------------------------ |
| order | An order to sort attributes. You can specify `alphabetical`, `code_guide`, `idiomatic` or `vuejs`. default: `code_guide` |

@@ -84,0 +84,0 @@ ## Testing

@@ -6,2 +6,3 @@ import { ISortOption, Strategy } from "./options";

import { IdiomaticStrategy } from "./strategy/idiomatic";
import { VuejsStrategy } from "./strategy/vuejs";

@@ -16,3 +17,3 @@ const maps: Array<string> = [];

const replaced = html.replace(
/<(?!\/)(?:"[^"]*"|'[^']*'|[^"'])*?>/g,
/<(?!\/)[-:.\w\d@]+\s(?:"[^"]*"|'[^']*'|[^"'])*?>/g,
(match: string) => {

@@ -84,3 +85,9 @@ return storeTags(match);

return new IdiomaticStrategy();
case "vuejs":
return new VuejsStrategy();
}
throw new Error(
`You can specify only [alphabetical|code_guide|idiomatic|vuejs] for sorting order`
);
}

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

export type Strategy = "alphabetical" | "code_guide" | "idiomatic";
export type Strategy = "alphabetical" | "code_guide" | "idiomatic" | "vuejs";

@@ -3,0 +3,0 @@ export interface ISortOption {

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