Skip to content

Commit

Permalink
refactor(checks): update all as arrow fns
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 5, 2019
1 parent 3038a84 commit b70a3e1
Show file tree
Hide file tree
Showing 51 changed files with 152 additions and 173 deletions.
5 changes: 2 additions & 3 deletions packages/checks/src/exists-not-null.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function existsAndNotNull(x: any) {
return x != null;
}
export const existsAndNotNull =
(x: any) => x != null;
5 changes: 2 additions & 3 deletions packages/checks/src/exists.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function exists(x: any) {
return x !== undefined;
}
export const exists =
(x: any) => x !== undefined;
5 changes: 2 additions & 3 deletions packages/checks/src/has-crypto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function hasCrypto() {
return typeof window !== "undefined" && window["crypto"] !== undefined;
}
export const hasCrypto =
() => typeof window !== "undefined" && window["crypto"] !== undefined;
6 changes: 3 additions & 3 deletions packages/checks/src/has-max-length.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function hasMaxLength(len: number, x: ArrayLike<any>) {
return x != null && x.length <= len;
}
export const hasMaxLength =
(len: number, x: ArrayLike<any>) =>
x != null && x.length <= len;
6 changes: 3 additions & 3 deletions packages/checks/src/has-min-length.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function hasMinLength(len: number, x: ArrayLike<any>) {
return x != null && x.length >= len;
}
export const hasMinLength =
(len: number, x: ArrayLike<any>) =>
x != null && x.length >= len;
5 changes: 2 additions & 3 deletions packages/checks/src/has-performance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isFunction } from "./is-function";

export function hasPerformance() {
return typeof performance !== 'undefined' && isFunction(performance.now);
}
export const hasPerformance =
() => typeof performance !== 'undefined' && isFunction(performance.now);
6 changes: 3 additions & 3 deletions packages/checks/src/has-wasm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function hasWASM() {
return (typeof window !== "undefined" && typeof window["WebAssembly"] !== "undefined") ||
export const hasWASM =
() =>
(typeof window !== "undefined" && typeof window["WebAssembly"] !== "undefined") ||
(typeof global !== "undefined" && typeof global["WebAssembly"] !== "undefined");
}
17 changes: 9 additions & 8 deletions packages/checks/src/has-webgl.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export function hasWebGL() {
try {
document.createElement("canvas").getContext("webgl");
return true;
} catch (e) {
return false;
}
}
export const hasWebGL =
() => {
try {
document.createElement("canvas").getContext("webgl");
return true;
} catch (e) {
return false;
}
};
5 changes: 2 additions & 3 deletions packages/checks/src/has-websocket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function hasWebSocket() {
return typeof WebSocket !== "undefined";
}
export const hasWebSocket =
() => typeof WebSocket !== "undefined";
6 changes: 3 additions & 3 deletions packages/checks/src/implements-function.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function implementsFunction(x: any, fn: string | symbol) {
return x != null && typeof x[fn] === "function";
}
export const implementsFunction =
(x: any, fn: string | symbol) =>
x != null && typeof x[fn] === "function";
6 changes: 3 additions & 3 deletions packages/checks/src/is-arraylike.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isArrayLike(x: any): x is ArrayLike<any> {
return (x != null && typeof x !== "function" && x.length !== undefined);
}
export const isArrayLike =
(x: any): x is ArrayLike<any> =>
(x != null && typeof x !== "function" && x.length !== undefined);
5 changes: 2 additions & 3 deletions packages/checks/src/is-blob.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isBlob(x: any): x is Blob {
return x instanceof Blob;
}
export const isBlob =
(x: any): x is Blob => x instanceof Blob;
5 changes: 2 additions & 3 deletions packages/checks/src/is-boolean.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isBoolean(x: any): x is boolean {
return typeof x === "boolean";
}
export const isBoolean =
(x: any): x is boolean => typeof x === "boolean";
5 changes: 2 additions & 3 deletions packages/checks/src/is-chrome.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isChrome() {
return typeof window !== "undefined" && !!window["chrome"];
}
export const isChrome =
() => typeof window !== "undefined" && !!window["chrome"];
5 changes: 2 additions & 3 deletions packages/checks/src/is-date.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isDate(x: any): x is Date {
return x instanceof Date;
}
export const isDate =
(x: any): x is Date => x instanceof Date;
5 changes: 2 additions & 3 deletions packages/checks/src/is-even.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isEven(x: number) {
return (x % 2) === 0;
}
export const isEven =
(x: number) => (x % 2) === 0;
5 changes: 2 additions & 3 deletions packages/checks/src/is-false.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isFalse(x: any): x is false {
return x === false;
}
export const isFalse =
(x: any): x is false => x === false;
5 changes: 2 additions & 3 deletions packages/checks/src/is-file.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isFile(x: any): x is File {
return x instanceof File;
}
export const isFile =
(x: any): x is File => x instanceof File;
5 changes: 2 additions & 3 deletions packages/checks/src/is-firefox.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isFirefox() {
return typeof window !== "undefined" && !!window["InstallTrigger"];
}
export const isFirefox =
() => typeof window !== "undefined" && !!window["InstallTrigger"];
5 changes: 2 additions & 3 deletions packages/checks/src/is-function.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isFunction(x: any): x is Function {
return typeof x === "function";
}
export const isFunction =
(x: any): x is Function => typeof x === "function";
6 changes: 3 additions & 3 deletions packages/checks/src/is-ie.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function isIE() {
return typeof document !== "undefined" &&
export const isIE =
() =>
typeof document !== "undefined" &&
(typeof document["documentMode"] !== "undefined" ||
navigator.userAgent.indexOf("MSIE") > 0);
}
6 changes: 3 additions & 3 deletions packages/checks/src/is-in-range.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isInRange(min: number, max: number, x: number) {
return x >= min && x <= max;
}
export const isInRange =
(min: number, max: number, x: number) =>
x >= min && x <= max;
6 changes: 3 additions & 3 deletions packages/checks/src/is-int32.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isInt32(x: any): x is number {
return typeof x === "number" && (x | 0) === x;
}
export const isInt32 =
(x: any): x is number =>
typeof x === "number" && (x | 0) === x;
6 changes: 3 additions & 3 deletions packages/checks/src/is-iterable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isIterable(x: any): x is Iterable<any> {
return x != null && typeof x[Symbol.iterator] === "function";
}
export const isIterable =
(x: any): x is Iterable<any> =>
x != null && typeof x[Symbol.iterator] === "function";
5 changes: 2 additions & 3 deletions packages/checks/src/is-map.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isMap(x: any): x is Map<any, any> {
return x instanceof Map;
}
export const isMap =
(x: any): x is Map<any, any> => x instanceof Map;
6 changes: 3 additions & 3 deletions packages/checks/src/is-mobile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function isMobile() {
return typeof navigator !== "undefined" &&
export const isMobile =
() =>
typeof navigator !== "undefined" &&
/mobile|tablet|ip(ad|hone|od)|android|silk/i.test(navigator.userAgent) &&
!/crios/i.test(navigator.userAgent);
}
5 changes: 2 additions & 3 deletions packages/checks/src/is-nan.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isNaN(x: any) {
return x !== x;
}
export const isNaN =
(x: any) => x !== x;
6 changes: 3 additions & 3 deletions packages/checks/src/is-negative.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isNegative(x: any): x is number {
return typeof x === "number" && x < 0;
}
export const isNegative =
(x: any): x is number =>
typeof x === "number" && x < 0;
17 changes: 9 additions & 8 deletions packages/checks/src/is-node.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
declare var process: any;

export function isNode() {
if (typeof process === "object") {
if (typeof process.versions === "object") {
if (typeof process.versions.node !== "undefined") {
return true;
export const isNode =
() => {
if (typeof process === "object") {
if (typeof process.versions === "object") {
if (typeof process.versions.node !== "undefined") {
return true;
}
}
}
}
return false;
}
return false;
};
6 changes: 3 additions & 3 deletions packages/checks/src/is-not-string-iterable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function isNotStringAndIterable(x: any): x is Iterable<any> {
return x != null &&
export const isNotStringAndIterable =
(x: any): x is Iterable<any> =>
x != null &&
typeof x !== "string" &&
typeof x[Symbol.iterator] === "function";
}
5 changes: 2 additions & 3 deletions packages/checks/src/is-null.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isNull(x: any): x is null {
return x === null;
}
export const isNull =
(x: any): x is null => x === null;
5 changes: 2 additions & 3 deletions packages/checks/src/is-number.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isNumber(x: any): x is number {
return typeof x === "number";
}
export const isNumber =
(x: any): x is number => typeof x === "number";
6 changes: 3 additions & 3 deletions packages/checks/src/is-object.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isObject(x: any): x is Object {
return x !== null && typeof x === "object";
}
export const isObject =
(x: any): x is Object =>
x !== null && typeof x === "object";
5 changes: 2 additions & 3 deletions packages/checks/src/is-odd.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isOdd(x: number) {
return (x % 2) !== 0;
}
export const isOdd =
(x: number) => (x % 2) !== 0;
11 changes: 6 additions & 5 deletions packages/checks/src/is-plain-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const OBJP = Object.getPrototypeOf({});
*
* @param x
*/
export function isPlainObject(x: any): x is object {
let proto;
return Object.prototype.toString.call(x) === "[object Object]" &&
(proto = Object.getPrototypeOf(x), proto === null || proto === OBJP);
}
export const isPlainObject =
(x: any): x is object => {
let proto;
return Object.prototype.toString.call(x) === "[object Object]" &&
(proto = Object.getPrototypeOf(x), proto === null || proto === OBJP);
};
5 changes: 2 additions & 3 deletions packages/checks/src/is-positive.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isPosititve(x: any): x is number {
return typeof x === "number" && x > 0;
}
export const isPosititve =
(x: any): x is number => typeof x === "number" && x > 0;
5 changes: 2 additions & 3 deletions packages/checks/src/is-promise.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isPromise(x: any): x is Promise<any> {
return x instanceof Promise;
}
export const isPromise =
(x: any): x is Promise<any> => x instanceof Promise;
6 changes: 3 additions & 3 deletions packages/checks/src/is-promiselike.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { implementsFunction } from "./implements-function";

export function isPromiseLike(x: any): x is Promise<any> {
return x instanceof Promise ||
export const isPromiseLike =
(x: any): x is Promise<any> =>
x instanceof Promise ||
(implementsFunction(x, "then") && implementsFunction(x, "catch"));
}
5 changes: 2 additions & 3 deletions packages/checks/src/is-regexp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isRegExp(x: any): x is RegExp {
return x instanceof RegExp;
}
export const isRegExp =
(x: any): x is RegExp => x instanceof RegExp;
8 changes: 5 additions & 3 deletions packages/checks/src/is-safari.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { isChrome } from "./is-chrome";

export function isSafari() {
return typeof navigator !== "undefined" && /Safari/.test(navigator.userAgent) && !isChrome();
}
export const isSafari =
() =>
typeof navigator !== "undefined" &&
/Safari/.test(navigator.userAgent) &&
!isChrome();
5 changes: 2 additions & 3 deletions packages/checks/src/is-set.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isSet(x: any): x is Set<any> {
return x instanceof Set;
}
export const isSet =
(x: any): x is Set<any> => x instanceof Set;
5 changes: 2 additions & 3 deletions packages/checks/src/is-string.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isString(x: any): x is string {
return typeof x === "string";
}
export const isString =
(x: any): x is string => typeof x === "string";
5 changes: 2 additions & 3 deletions packages/checks/src/is-symbol.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isSymbol(x: any): x is Symbol {
return typeof x === "symbol";
}
export const isSymbol =
(x: any): x is Symbol => typeof x === "symbol";
6 changes: 3 additions & 3 deletions packages/checks/src/is-transferable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare var SharedArrayBuffer: any;

export function isTransferable(x: any) {
return x instanceof ArrayBuffer ||
export const isTransferable =
(x: any) =>
x instanceof ArrayBuffer ||
(typeof SharedArrayBuffer !== "undefined" && x instanceof SharedArrayBuffer) ||
(typeof MessagePort !== "undefined" && x instanceof MessagePort);
}
5 changes: 2 additions & 3 deletions packages/checks/src/is-true.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isTrue(x: any): x is boolean {
return x === true;
}
export const isTrue =
(x: any): x is boolean => x === true;
22 changes: 11 additions & 11 deletions packages/checks/src/is-typedarray.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export function isTypedArray(x: any): x is ArrayLike<number> {
return x && (x.constructor === Float32Array ||
x.constructor === Uint32Array ||
x.constructor === Uint8Array ||
x.constructor === Uint8ClampedArray ||
x.constructor === Int8Array ||
x.constructor === Uint16Array ||
x.constructor === Int16Array ||
x.constructor === Int32Array ||
x.constructor === Float64Array);
}
export const isTypedArray =
(x: any): x is ArrayLike<number> =>
x && (x.constructor === Float32Array ||
x.constructor === Uint32Array ||
x.constructor === Uint8Array ||
x.constructor === Uint8ClampedArray ||
x.constructor === Int8Array ||
x.constructor === Uint16Array ||
x.constructor === Int16Array ||
x.constructor === Int32Array ||
x.constructor === Float64Array);
6 changes: 3 additions & 3 deletions packages/checks/src/is-uint32.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isUint32(x: any): x is number {
return typeof x === "number" && (x >>> 0) === x;
}
export const isUint32 =
(x: any): x is number =>
typeof x === "number" && (x >>> 0) === x;
5 changes: 2 additions & 3 deletions packages/checks/src/is-undefined.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export function isUndefined(x: any): x is undefined {
return x === undefined;
}
export const isUndefined =
(x: any): x is undefined => x === undefined;
7 changes: 4 additions & 3 deletions packages/checks/src/is-uuid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export function isUUID(x: string) {
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(x);
}
const RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

export const isUUID =
(x: string) => RE.test(x);
7 changes: 4 additions & 3 deletions packages/checks/src/is-uuid4.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export function isUUIDv4(x: string) {
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(x);
}
const RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

export const isUUIDv4 =
(x: string) => RE.test(x);
Loading

0 comments on commit b70a3e1

Please sign in to comment.