-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathprepare.js
39 lines (30 loc) · 1.07 KB
/
prepare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class UnknownSvelteOptionsError extends TypeError {
constructor(unknownOptions, allowedOptions) {
super(`Unknown options.
Unknown: [ ${unknownOptions.join(', ')} ]
Allowed: [ ${allowedOptions.join(', ')} ]
To pass both Svelte options and props to a component,
or to use props that share a name with a Svelte option,
you must place all your props under the \`props\` key:
render(Component, { props: { /** props here **/ } })
`)
this.name = 'UnknownSvelteOptionsError'
}
}
const createValidateOptions = (allowedOptions) => (options) => {
const isProps = !Object.keys(options).some((option) =>
allowedOptions.includes(option)
)
if (isProps) {
return { props: options }
}
// Check if any props and Svelte options were accidentally mixed.
const unknownOptions = Object.keys(options).filter(
(option) => !allowedOptions.includes(option)
)
if (unknownOptions.length > 0) {
throw new UnknownSvelteOptionsError(unknownOptions, allowedOptions)
}
return options
}
export { createValidateOptions, UnknownSvelteOptionsError }