Skip to content

Commit

Permalink
Enforce the stringify from the worker too
Browse files Browse the repository at this point in the history
  • Loading branch information
Lcfvs committed Apr 26, 2021
1 parent 25b3ee8 commit 0d66a63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions lib/worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {
entries,
fromEntries
fromEntries,
hasOwnProperty
} = Object

const flag = '@@template'
Expand All @@ -23,14 +24,16 @@ const random = values => {
.filter(isHidden)[~~(Math.random() * (values.length + 1))] ?? 0]
}

const parse = ([name, value]) => [name, format(value)]
const parse = (parsed, [name, value]) => typeof value === 'function'
? parsed
: [...parsed, [name, format(value)]]

const format = value => {
return Object(value) !== value
? [value]
return typeof value !== 'object' || hasOwnProperty.call(value, 'toString')
? [value?.toString()]
: Array.isArray(value)
? [[...value.values()].map(format)]
: [fromEntries(entries(value).map(parse)), value[symbol]]
: [fromEntries(entries(value).reduce(parse, [])), value[symbol]]
}

const send = (template, client) => resolve => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lcf.vs/dom-engine",
"version": "2.2.3",
"version": "2.2.4",
"description": "A composable DOM based template engine",
"type": "module",
"main": "lib/engine.js",
Expand Down

0 comments on commit 0d66a63

Please sign in to comment.