mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 16:42:28 +03:00
30 lines
993 B
TypeScript
30 lines
993 B
TypeScript
// Loaded from https://deno.land/x/segno@v1.1.0/lib/validations/isIn.ts
|
|
|
|
|
|
// @ts-ignore allowing typedoc to build
|
|
import { assertString } from '../helpers/assertString.ts';
|
|
// @ts-ignore allowing typedoc to build
|
|
import { toString } from '../helpers/toString.ts';
|
|
|
|
//! change later
|
|
export const isIn = (str: string, options?: any) => {
|
|
assertString(str);
|
|
let i;
|
|
if (Object.prototype.toString.call(options) === '[object Array]') {
|
|
const array: any = [];
|
|
for (i in options) {
|
|
// https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
|
|
// istanbul ignore else
|
|
if ({}.hasOwnProperty.call(options, i)) {
|
|
array[i] = toString(options[i]);
|
|
}
|
|
}
|
|
return array.indexOf(str) >= 0;
|
|
} else if (typeof options === 'object') {
|
|
return options.hasOwnProperty(str);
|
|
} else if (options && typeof options.indexOf === 'function') {
|
|
return options.indexOf(str) >= 0;
|
|
}
|
|
return false;
|
|
};
|