Skip to content

Commit 924ec09

Browse files
committed
feat(core): expose fine-grained API for subject-case
1 parent e755726 commit 924ec09

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
import ensureCase from '../library/ensure-case';
22
import message from '../library/message';
33

4+
const negated = when => when === 'never';
5+
46
export default (parsed, when, value) => {
57
const {subject} = parsed;
68

7-
if (!subject) {
9+
if (typeof subject !== 'string') {
810
return [true];
911
}
1012

11-
const negated = when === 'never';
13+
const checks = (Array.isArray(value) ? value : [value]).map(check => {
14+
if (typeof check === 'string') {
15+
return {
16+
when: 'always',
17+
case: check
18+
};
19+
}
20+
return check;
21+
});
22+
23+
const result = checks.every(check => {
24+
const r = ensureCase(subject, check.case);
25+
return negated(check.when) ? !r : r;
26+
});
1227

13-
const result = ensureCase(subject, value);
1428
return [
15-
negated ? !result : result,
29+
negated(when) ? !result : result,
1630
message([`subject must`, negated ? `not` : null, `be ${value}`])
1731
];
1832
};

0 commit comments

Comments
 (0)