Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Apr 20, 2022
1 parent 871452c commit c459cf3
Show file tree
Hide file tree
Showing 5 changed files with 522 additions and 566 deletions.
23 changes: 6 additions & 17 deletions lib/ipList/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@ import { EnvError, makeValidator } from 'envalid';
import ipaddr, { IPv4, IPv6, isValid } from 'ipaddr.js';
export type { IPv4, IPv6 };

export const ipList = makeValidator((input: string | string[]) => {
let items: string[];
if (typeof input === 'string') {
const trimmed = input.trim();
if (!trimmed) {
return [];
}

items = trimmed.split(',');
} else {
items = input;
export const ipList = makeValidator((input: string) => {
const trimmed = input.trim();
if (!trimmed) {
return [];
}

const items = trimmed.split(',');
const valid = items.every((ip, idx, arr) => {
ip = ip.trim();
arr[idx] = ip;
Expand All @@ -28,12 +22,7 @@ export const ipList = makeValidator((input: string | string[]) => {
return items;
});

export const ipListEx = makeValidator((input: string | (IPv4 | IPv6)[]) => {
if (Array.isArray(input)) {
// This can only happen if we get a default value
return input;
}

export const ipListEx = makeValidator((input: string) => {
if (!input.trim()) {
return [];
}
Expand Down
14 changes: 5 additions & 9 deletions lib/iso31661Alpha2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ export const iso31661Alpha2 = makeValidator((input: string) => {
throw new EnvError(`Invalid ISO 3166-1 alpha-2 input: "${input}"`);
});

export const iso31661Alpha2List = makeValidator((input: string | string[]) => {
if (typeof input === 'string') {
input = input.trim();
if (!input) {
return [];
}

input = input.split(',');
export const iso31661Alpha2List = makeValidator((input: string) => {
input = input.trim();
if (!input) {
return [];
}

const items = input.map((s) => s.trim().toUpperCase());
const items = input.split(',').map((s) => s.trim().toUpperCase());
const valid = items.every((s) => validator.isISO31661Alpha2(s));

if (valid) {
Expand Down
Loading

0 comments on commit c459cf3

Please sign in to comment.