@design-edito/tools 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- import{a as N}from"./chunk-AFA3GSXO.js";var E={depth:20};async function z(d,o=E){let l=(o.documentObj??await N()).createElement("div"),{inputFreeTransform:a}=o;return l.innerHTML=a!==void 0?a(d):d,y(l,o)?.innerHTML??""}function y(d,o=E){let{tagName:e,attributes:l,childNodes:a}=d,{allowedTags:g=[],allowedAttributes:b={},forbiddenTags:m=[],forbiddenAttributes:A={},depth:w=20,verbose:s=!1}=o;if(w<=0)return console.warn("Max depth reached"),null;let f=e.toLowerCase().trim();if(m.includes("*")||m.includes(f))return s===!0&&console.warn(e,"tag is forbidden"),null;if(!(g.includes("*")||g.includes(f)))return s===!0&&console.warn(e,"tag is not allowed"),null;let p=document.createElement(e);Array.from(l).filter(({name:t,value:i})=>{let I=A["*"]??[],O=A[f]??[];if([...I,...O].some(({attributeName:r,attributeValues:u})=>typeof r=="string"&&r!=="*"&&t!==r||typeof r!="string"&&!r.test(t)?!1:u===void 0||u.includes("*")?(s===!0&&console.warn(t,"attribute on",e,"tag is forbidden"),!0):u.some(n=>typeof n=="string"&&i===n||typeof n!="string"&&n.test(i)?(s===!0&&console.warn(i,"value for",t,"attribute on",e,"tag is forbidden. Rule:",n),!0):!1)))return!1;let F=b["*"]??[],P=b[f]??[],x=[...F,...P],c=[e,"has no allowed attributes"];return x.some(({attributeName:r,attributeValues:u})=>typeof r=="string"&&r!=="*"&&t!==r?(c=[t,"attribute on",e,"tag is not allowed"],!1):typeof r!="string"&&!r.test(t)?(c=[t,"attribute on",e,"tag is not allowed"],!1):u===void 0||u.includes("*")?!0:u.some(n=>typeof n=="string"&&i===n||typeof n!="string"&&n.test(i)?!0:(c=[i,"value for",t,"attribute on",e,"tag is not allowed"],!1)))?!0:(s===!0&&console.warn(...c),!1)}).forEach(({name:t,value:i})=>{p.setAttribute(t,i)});let h=Array.from(a).map(t=>t.nodeType===Node.ELEMENT_NODE?y(t,{...o,depth:w-1}):t.nodeType===Node.TEXT_NODE||o.keepComments===!0&&t.nodeType===Node.COMMENT_NODE?t:null).filter(t=>t!==null);return p.replaceChildren(...h),p}export{E as a,z as b,y as c};
1
+ import{c as N}from"./chunk-LCLAV6Q2.js";var E={depth:20};async function z(d,o=E){let l=(o.documentObj??await N()).createElement("div"),{inputFreeTransform:a}=o;return l.innerHTML=a!==void 0?a(d):d,y(l,o)?.innerHTML??""}function y(d,o=E){let{tagName:e,attributes:l,childNodes:a}=d,{allowedTags:g=[],allowedAttributes:b={},forbiddenTags:m=[],forbiddenAttributes:A={},depth:w=20,verbose:s=!1}=o;if(w<=0)return console.warn("Max depth reached"),null;let f=e.toLowerCase().trim();if(m.includes("*")||m.includes(f))return s===!0&&console.warn(e,"tag is forbidden"),null;if(!(g.includes("*")||g.includes(f)))return s===!0&&console.warn(e,"tag is not allowed"),null;let p=document.createElement(e);Array.from(l).filter(({name:t,value:i})=>{let I=A["*"]??[],O=A[f]??[];if([...I,...O].some(({attributeName:r,attributeValues:u})=>typeof r=="string"&&r!=="*"&&t!==r||typeof r!="string"&&!r.test(t)?!1:u===void 0||u.includes("*")?(s===!0&&console.warn(t,"attribute on",e,"tag is forbidden"),!0):u.some(n=>typeof n=="string"&&i===n||typeof n!="string"&&n.test(i)?(s===!0&&console.warn(i,"value for",t,"attribute on",e,"tag is forbidden. Rule:",n),!0):!1)))return!1;let F=b["*"]??[],P=b[f]??[],x=[...F,...P],c=[e,"has no allowed attributes"];return x.some(({attributeName:r,attributeValues:u})=>typeof r=="string"&&r!=="*"&&t!==r?(c=[t,"attribute on",e,"tag is not allowed"],!1):typeof r!="string"&&!r.test(t)?(c=[t,"attribute on",e,"tag is not allowed"],!1):u===void 0||u.includes("*")?!0:u.some(n=>typeof n=="string"&&i===n||typeof n!="string"&&n.test(i)?!0:(c=[i,"value for",t,"attribute on",e,"tag is not allowed"],!1)))?!0:(s===!0&&console.warn(...c),!1)}).forEach(({name:t,value:i})=>{p.setAttribute(t,i)});let h=Array.from(a).map(t=>t.nodeType===Node.ELEMENT_NODE?y(t,{...o,depth:w-1}):t.nodeType===Node.TEXT_NODE||o.keepComments===!0&&t.nodeType===Node.COMMENT_NODE?t:null).filter(t=>t!==null);return p.replaceChildren(...h),p}export{E as a,z as b,y as c};
@@ -1 +1 @@
1
- var n=(e=>(e.NODE="Node.js",e.BROWSER="Browser",e.DENO="Deno",e.REACT_NATIVE="React Native",e.ELECTRON="Electron",e.CLOUDFLARE="Cloudflare Workers",e.AWS_LAMBDA="AWS Lambda",e))(n||{});function r(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"?"Node.js":typeof window<"u"&&typeof window.document<"u"?"Browser":typeof Deno<"u"?"Deno":typeof process<"u"&&typeof navigator.userAgent=="string"&&/ReactNative/.test(navigator.userAgent)?"React Native":typeof process<"u"&&typeof process.versions<"u"&&typeof process.version.electron<"u"?"Electron":typeof self<"u"&&typeof self.addEventListener=="function"&&typeof Headers<"u"?"Cloudflare Workers":typeof AWS<"u"&&typeof AWS.Lambda<"u"?"AWS Lambda":null}export{n as a,r as b};
1
+ var t=(e=>(e.NODE="Node.js",e.BROWSER="Browser",e.DENO="Deno",e.REACT_NATIVE="React Native",e.ELECTRON="Electron",e.CLOUDFLARE="Cloudflare Workers",e.AWS_LAMBDA="AWS Lambda",e))(t||{});function o(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"?"Node.js":typeof window<"u"&&typeof window.document<"u"?"Browser":typeof Deno<"u"?"Deno":typeof process<"u"&&typeof navigator.userAgent=="string"&&/ReactNative/.test(navigator.userAgent)?"React Native":typeof process<"u"&&typeof process.versions<"u"&&typeof process.version.electron<"u"?"Electron":typeof self<"u"&&typeof self.addEventListener=="function"&&typeof Headers<"u"?"Cloudflare Workers":typeof AWS<"u"&&typeof AWS.Lambda<"u"?"AWS Lambda":null}async function u(){let n=o();return["Browser","Electron"].includes(n)?window.document:new(await import("jsdom")).JSDOM().window.document}export{t as a,o as b,u as c};
package/index.js CHANGED
@@ -6,12 +6,11 @@ import * as cast from './utils/agnostic/cast/index.js'
6
6
  import * as charcodeString from './utils/agnostic/charcode-string/index.js'
7
7
  import * as clamp from './utils/agnostic/clamp/index.js'
8
8
  import * as clientsideHtmlSanitizer from './utils/agnostic/clientside-html-sanitizer/index.js'
9
- import * as detectRuntime from './utils/agnostic/detect-runtime/index.js'
9
+ import * as crossenv from './utils/agnostic/crossenv/index.js'
10
10
  import * as findDuplicatesInArray from './utils/agnostic/find-duplicates-in-array/index.js'
11
11
  import * as flattenGetters from './utils/agnostic/flatten-getters/index.js'
12
12
  import * as generateHtmlPlaceholders from './utils/agnostic/generate-html-placeholders/index.js'
13
13
  import * as generateNiceColor from './utils/agnostic/generate-nice-color/index.js'
14
- import * as getDocument from './utils/agnostic/get-document/index.js'
15
14
  import * as insertNode from './utils/agnostic/insert-node/index.js'
16
15
  import * as interpolate from './utils/agnostic/interpolate/index.js'
17
16
  import * as isArrayOf from './utils/agnostic/is-array-of/index.js'
@@ -49,12 +48,11 @@ export { cast }
49
48
  export { charcodeString }
50
49
  export { clamp }
51
50
  export { clientsideHtmlSanitizer }
52
- export { detectRuntime }
51
+ export { crossenv }
53
52
  export { findDuplicatesInArray }
54
53
  export { flattenGetters }
55
54
  export { generateHtmlPlaceholders }
56
55
  export { generateNiceColor }
57
- export { getDocument }
58
56
  export { insertNode }
59
57
  export { interpolate }
60
58
  export { isArrayOf }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-edito/tools",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",
@@ -1 +1,3 @@
1
- export default function arrayRandomPick(arr: any[], exclude?: any[]): any;
1
+ export declare const errorSybol: unique symbol;
2
+ export type ErrorSymbol = typeof errorSybol;
3
+ export default function arrayRandomPick<T>(arr: T[], exclude?: T[]): T | ErrorSymbol;
@@ -1 +1 @@
1
- function l(t,r=[]){let n=[...t].filter(e=>!r.includes(e)),a=n.length,o=Math.floor(Math.random()*a);return n[o]}export{l as default};
1
+ var f=Symbol();function a(t,e=[]){let r=[...t].filter(l=>!e.includes(l)),o=r.length;if(o===0)return f;let n=Math.floor(Math.random()*o);return r[n]}export{a as default,f as errorSybol};
@@ -1 +1 @@
1
- import{a,b,c}from"../../../chunks/chunk-LCBMRJKP.js";import"../../../chunks/chunk-AFA3GSXO.js";import"../../../chunks/chunk-CF6GPH7Z.js";export{b as default,a as defaultOptions,c as sanitizeElement};
1
+ import{a,b,c}from"../../../chunks/chunk-EFFU6KXJ.js";import"../../../chunks/chunk-LCLAV6Q2.js";export{b as default,a as defaultOptions,c as sanitizeElement};
@@ -7,4 +7,5 @@ export declare enum RuntimeName {
7
7
  CLOUDFLARE = "Cloudflare Workers",
8
8
  AWS_LAMBDA = "AWS Lambda"
9
9
  }
10
- export default function detectRuntime(): RuntimeName | null;
10
+ export declare function detectRuntime(): RuntimeName | null;
11
+ export declare function getDocument(): Promise<Document>;
@@ -0,0 +1 @@
1
+ import{a,b,c}from"../../../chunks/chunk-LCLAV6Q2.js";export{a as RuntimeName,b as detectRuntime,c as getDocument};
@@ -1 +1 @@
1
- import{a as o}from"../../../chunks/chunk-AFA3GSXO.js";import"../../../chunks/chunk-CF6GPH7Z.js";async function x(e,m){let i=m??await o(),l=/^[A-Za-z]+/,d=/#[A-Za-z]+[\w\-\:]*/,r=/\.[A-Za-z]+[\w\-]*/,u=/\[[A-Za-z]+[\w\-]*(="[\w\-]+")?\]/,a=e.match(l)??[],n=e.match(d)??[],p=e.match(r)??[],g=e.match(u)??[],h=a[a.length-1]??"div",s=n[n.length-1]??null,f=p.map(t=>t.replace(/^\./,"")),A=g.map(t=>t.replace(/^\[/,"").replace(/\]$/,"").split("=")),c=i.createElement(h);return s!==null&&(c.id=s),c.classList.add(...f),A.forEach(([t,w=""])=>{t!==void 0&&c.setAttribute(t,w)}),c}export{x as default};
1
+ import{c as o}from"../../../chunks/chunk-LCLAV6Q2.js";async function x(e,m){let i=m??await o(),l=/^[A-Za-z]+/,d=/#[A-Za-z]+[\w\-\:]*/,r=/\.[A-Za-z]+[\w\-]*/,u=/\[[A-Za-z]+[\w\-]*(="[\w\-]+")?\]/,a=e.match(l)??[],n=e.match(d)??[],p=e.match(r)??[],g=e.match(u)??[],h=a[a.length-1]??"div",s=n[n.length-1]??null,f=p.map(t=>t.replace(/^\./,"")),A=g.map(t=>t.replace(/^\[/,"").replace(/\]$/,"").split("=")),c=i.createElement(h);return s!==null&&(c.id=s),c.classList.add(...f),A.forEach(([t,w=""])=>{t!==void 0&&c.setAttribute(t,w)}),c}export{x as default};
@@ -1 +1 @@
1
- import{b as i}from"../../../chunks/chunk-LCBMRJKP.js";import{a as o}from"../../../chunks/chunk-AFA3GSXO.js";import"../../../chunks/chunk-CF6GPH7Z.js";async function a(n,e){let s=e?.documentObj??await o(),r=e?.sanitize!==void 0?await i(n,e.sanitize):n,t=s.createElement("div");return t.innerHTML=r,Array.from(t.childNodes).filter(d=>[Node.ELEMENT_NODE,Node.TEXT_NODE].includes(d.nodeType))}export{a as default};
1
+ import{b as i}from"../../../chunks/chunk-EFFU6KXJ.js";import{c as o}from"../../../chunks/chunk-LCLAV6Q2.js";async function a(n,e){let s=e?.documentObj??await o(),r=e?.sanitize!==void 0?await i(n,e.sanitize):n,t=s.createElement("div");return t.innerHTML=r,Array.from(t.childNodes).filter(d=>[Node.ELEMENT_NODE,Node.TEXT_NODE].includes(d.nodeType))}export{a as default};
@@ -1 +0,0 @@
1
- import{b as n}from"./chunk-CF6GPH7Z.js";async function o(){let t=n();return["Browser","Electron"].includes(t)?window.document:new(await import("jsdom")).JSDOM().window.document}export{o as a};
@@ -1 +0,0 @@
1
- import{a,b}from"../../../chunks/chunk-CF6GPH7Z.js";export{a as RuntimeName,b as default};
@@ -1 +0,0 @@
1
- export default function getDocument(): Promise<Document>;
@@ -1 +0,0 @@
1
- import{a}from"../../../chunks/chunk-AFA3GSXO.js";import"../../../chunks/chunk-CF6GPH7Z.js";export{a as default};