nude-element
Advanced tools
Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "nude-element", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Composable web component helpers", | ||
@@ -35,2 +35,3 @@ "main": "index.js", | ||
"globals": "latest", | ||
"htest.dev": "^0.0.14", | ||
"release-it": "^17.2.1", | ||
@@ -37,0 +38,0 @@ "typedoc": "latest", |
@@ -11,2 +11,7 @@ import { | ||
let Self = class Prop { | ||
/** | ||
* @type {Props} props - The props object this prop belongs to | ||
*/ | ||
props; | ||
constructor (name, spec, props) { | ||
@@ -52,5 +57,5 @@ if (spec instanceof Prop && name === spec.name) { | ||
...inferDependencies(spec.convert), | ||
...(spec.additionalDependencies ?? []), | ||
]); | ||
} | ||
// this.dependencies = new Set(spec.dependencies ?? inferDependencies(spec.get)); | ||
@@ -57,0 +62,0 @@ // Computed properties are not reflected by default |
@@ -120,2 +120,3 @@ # Nude Props | ||
| `dependencies` | `string[]` | undefined | Override the auto-detected dependencies with these prop names. Useful when the dependencies are not immediately obvious from the function body | | ||
| `additionalDependencies` | `string[]` | undefined | Add these prop names to the auto-detected dependencies. Useful when *most* of the dependencies are auto-detected, but some need to be added without redefining *all* the dependencies with the `dependencies` property. | | ||
| `equals` | `Function` | undefined | A function to compare two values for equality. If not provided the default equality check depends on the `type` of the value. | | ||
@@ -122,0 +123,0 @@ | `parse` | `Function` | undefined | A function to parse the value from an attribute. If not provided, the value will be parsed based on the `type`. | |
@@ -90,10 +90,10 @@ import * as allTypes from "./types/index.js"; | ||
export function resolve (type) { | ||
if (typeof type === "string") { | ||
type = globalThis[type]; | ||
} | ||
if (type) { | ||
if (typeof type === "function") { | ||
if (typeof type === "function" || typeof type === "string") { | ||
type = { is: type }; | ||
} | ||
if (typeof type.is === "string") { | ||
type.is = globalThis[type.is]; | ||
} | ||
} | ||
@@ -100,0 +100,0 @@ |
import { resolveValue } from "../../util.js"; | ||
import { parse, stringify, equals } from "../types.js"; | ||
import { split } from "./util.js"; | ||
function parseEntries (value, { values, keys, separator = ", ", defaultValue = true, defaultKey } = {}) { | ||
let entries; | ||
function parseEntries (value, { values, keys, separator = ", ", defaultValue = true, defaultKey, pairs } = {}) { | ||
let entries = value; | ||
if (!Array.isArray(entries)) { | ||
separator = separator.trim(); | ||
let entrySeparatorRegex = RegExp(`\\s*(?<!\\\\)${separator}\\s*`); | ||
entries = value.trim().split(entrySeparatorRegex); | ||
if (typeof value === "string") { | ||
entries = split(value, { separator, pairs }); | ||
@@ -12,0 +11,0 @@ entries = entries.map((entry, index) => { |
import { parse, stringify, equals } from "../types.js"; | ||
import { split } from "./util.js"; | ||
function parseList (value, { values, separator = ",", splitter } = {}) { | ||
if (!Array.isArray(value)) { | ||
if (!splitter) { | ||
// Make whitespace optional and flexible, unless the separator consists entirely of whitespace | ||
let isSeparatorWhitespace = !separator.trim(); | ||
splitter = isSeparatorWhitespace ? /\s+/ : new RegExp(separator.replace(/\s+/g, "\\s*")); | ||
} | ||
value = typeof value === "string" ? value.trim().split(splitter) : [value]; | ||
function parseList (value, { values, ...options } = {}) { | ||
if (typeof value === "string") { | ||
value = split(value, options); | ||
} | ||
else { | ||
value = Array.isArray(value) ? value : [value]; | ||
} | ||
@@ -14,0 +12,0 @@ if (values) { |
67693
34
1647
7