MCPcopy Create free account
hub / github.com/decaporg/decap-cms / validateMinMax

Function validateMinMax

packages/decap-cms-lib-widgets/src/validations.ts:5–31  ·  view source on GitHub ↗
(
  t: (key: string, options: unknown) => string,
  fieldLabel: string,
  value?: List<unknown>,
  min?: number,
  max?: number,
)

Source from the content-addressed store, hash-verified

3import type { List } from 'immutable';
4
5export function validateMinMax(
6 t: (key: string, options: unknown) => string,
7 fieldLabel: string,
8 value?: List<unknown>,
9 min?: number,
10 max?: number,
11) {
12 function minMaxError(messageKey: string) {
13 return {
14 type: 'RANGE',
15 message: t(`editor.editorControlPane.widget.${messageKey}`, {
16 fieldLabel,
17 minCount: min,
18 maxCount: max,
19 count: min,
20 }),
21 };
22 }
23
24 if ([min, max, value?.size].every(isNumber) && (value!.size < min! || value!.size > max!)) {
25 return minMaxError(min === max ? 'rangeCountExact' : 'rangeCount');
26 } else if (isNumber(min) && min > 0 && value?.size && value.size < min) {
27 return minMaxError('rangeMin');
28 } else if (isNumber(max) && value?.size && value.size > max) {
29 return minMaxError('rangeMax');
30 }
31}

Callers

nothing calls this directly

Calls 1

minMaxErrorFunction · 0.85

Tested by

no test coverage detected