1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.length = (targetVal, opts) => {
|
4 | const results = [];
|
5 | const { min, max } = opts;
|
6 | if (!targetVal)
|
7 | return results;
|
8 | let value;
|
9 | const valueType = typeof targetVal;
|
10 | if (valueType === 'object') {
|
11 | value = Object.keys(targetVal).length;
|
12 | }
|
13 | else if (Array.isArray(targetVal)) {
|
14 | value = targetVal.length + 1;
|
15 | }
|
16 | else if (valueType === 'number') {
|
17 | value = targetVal;
|
18 | }
|
19 | else if (valueType === 'string') {
|
20 | value = targetVal.length;
|
21 | }
|
22 | if (typeof value === 'undefined')
|
23 | return results;
|
24 | if (typeof min !== 'undefined' && value < min) {
|
25 | results.push({
|
26 | message: `min length is ${min}`,
|
27 | });
|
28 | }
|
29 | if (typeof max !== 'undefined' && value > max) {
|
30 | results.push({
|
31 | message: `max length is ${max}`,
|
32 | });
|
33 | }
|
34 | return results;
|
35 | };
|
36 |
|
\ | No newline at end of file |