Skip to content

Commit 778bbd4

Browse files
committed
feat: add clone option to config
1 parent 1176584 commit 778bbd4

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export function defineOptions<Props, Return extends Required<Props>>(
1919
if (isArray(properties) || !isObject(properties))
2020
throw 'the first argument is not an object. Please, use the type of object'
2121

22-
return parseProperties(properties, propertiesSettings)
22+
const props = config && config.clone ? { ...properties } : properties
23+
24+
return parseProperties(props, propertiesSettings)
2325
} catch (e) {
2426
errorLog(e, config ? config.mode : 'strict')
2527
}

tests/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,16 @@ it('Check plugin arguments', () => {
88
expect(() => defineOptions([], ['hello'])).toThrow()
99
expect(() => defineOptions([], {})).toThrow()
1010
})
11+
12+
it('Check plugin config', () => {
13+
const object = {}
14+
15+
const newObject = defineOptions(
16+
object,
17+
{ name: { required: false, default: 'hello' } },
18+
{ clone: true }
19+
)
20+
21+
expect(object).toEqual({})
22+
expect(newObject).toEqual({ name: 'hello' })
23+
})

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type OptionSettings<Properties> =
4242
export type ConfigMode = 'strict' | 'log' | 'disabled'
4343
export interface Config {
4444
mode?: ConfigMode
45+
clone?: boolean
4546
}
4647

4748
export function defineOptions<Properties, Return = Required<Properties>>(

0 commit comments

Comments
 (0)