From e480f14365bb50c3b927904486d22afe6643a05a Mon Sep 17 00:00:00 2001 From: kj Date: Tue, 28 May 2024 22:21:31 -0700 Subject: [PATCH] Update adds a basic unique id function --- index.mjs | 14 ++++++++++---- package.json | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/index.mjs b/index.mjs index 7aaf7b9..5fc7419 100644 --- a/index.mjs +++ b/index.mjs @@ -2,9 +2,15 @@ import { parse, fragment, serialize, serializeOuter } from '@begin/parse5' import isCustomElement from './lib/is-custom-element.mjs' import { encode, decode } from './lib/transcode.mjs' import walk from './lib/walk.mjs' -import { customAlphabet } from 'nanoid' -const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz'; -const nanoid = customAlphabet(alphabet, 7); + +function uuid() { + return 'xxxxyxxxx'.replace(/[xy]/g, function(c) { + let r = Math.random() * 16 | 0, v = c == 'x' + ? r + : (r & 0x3 | 0x8) + return v.toString(16) + }) +} export default function Enhancer(options={}) { const { @@ -12,7 +18,7 @@ export default function Enhancer(options={}) { elements=[], scriptTransforms=[], styleTransforms=[], - uuidFunction=nanoid, + uuidFunction=uuid, bodyContent=false, enhancedAttr=true } = options diff --git a/package.json b/package.json index 79b01c6..39e91d8 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "tape-es": "^1.2.17" }, "dependencies": { - "@begin/parse5": "^0.0.4", - "nanoid": "^4.0.1" + "@begin/parse5": "^0.0.4" } }