cl01/wp-content/plugins/code-snippets/js/utils/shortcodes.ts
2025-02-24 12:39:24 +08:00

11 lines
346 B
TypeScript
Executable File

export type ShortcodeAtts = Record<string, unknown>
export const buildShortcodeTag = (tag: string, atts: ShortcodeAtts): string =>
`[${[
tag,
...Object.entries(atts)
.filter(([, value]) => Boolean(value))
.map(([att, value]) =>
'boolean' === typeof value ? att : `${att}=${JSON.stringify(value)}`)
].filter(Boolean).join(' ')}]`