Skip to content

Commit 0ab3fb2

Browse files
committed
Extracted utils to a separted file
1 parent d0b030a commit 0ab3fb2

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/FluentSchema.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
const { flat, hasCombiningKeywords, isFluentSchema, last } = require('./utils')
23

34
const initialState = {
45
$schema: 'http://json-schema.org/draft-07/schema#',
@@ -8,25 +9,6 @@ const initialState = {
89
required: [],
910
}
1011

11-
const isFluentSchema = obj => typeof obj.title === 'function'
12-
13-
const hasCombiningKeywords = attributes =>
14-
attributes.anyOf || attributes.anyOf || attributes.anyOf || attributes.not
15-
16-
const last = arr => {
17-
const [prop] = [...arr].reverse()
18-
return prop
19-
}
20-
21-
const flat = array =>
22-
array.reduce((memo, prop) => {
23-
const { name, ...rest } = prop
24-
return {
25-
...memo,
26-
[name]: rest,
27-
}
28-
}, {})
29-
3012
const setMeta = (schema, prop) => {
3113
const [key, value] = prop
3214
const currentProp = last(schema.properties)

src/utils.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const isFluentSchema = obj => typeof obj.anyOf === 'function'
2+
3+
const hasCombiningKeywords = attributes =>
4+
attributes.anyOf || attributes.anyOf || attributes.anyOf || attributes.not
5+
6+
const last = arr => {
7+
const [prop] = [...arr].reverse()
8+
return prop
9+
}
10+
11+
const flat = array =>
12+
array.reduce((memo, prop) => {
13+
const { name, ...rest } = prop
14+
return {
15+
...memo,
16+
[name]: rest,
17+
}
18+
}, {})
19+
20+
module.exports = {
21+
isFluentSchema,
22+
hasCombiningKeywords,
23+
last,
24+
flat,
25+
}

0 commit comments

Comments
 (0)