Skip to content

Commit

Permalink
Update adds a basic unique id function
Browse files Browse the repository at this point in the history
  • Loading branch information
kj committed May 29, 2024
1 parent 7f07d89 commit e480f14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 10 additions & 4 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ 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 {
initialState={},
elements=[],
scriptTransforms=[],
styleTransforms=[],
uuidFunction=nanoid,
uuidFunction=uuid,
bodyContent=false,
enhancedAttr=true
} = options
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"tape-es": "^1.2.17"
},
"dependencies": {
"@begin/parse5": "^0.0.4",
"nanoid": "^4.0.1"
"@begin/parse5": "^0.0.4"
}
}

0 comments on commit e480f14

Please sign in to comment.