From 442f7b709f39ed2ac6bf073dd427f7f12659011d Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Wed, 26 Sep 2018 21:02:41 +0200 Subject: [PATCH] Use is-buffer ponyfill for better browser support (#66) --- source/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/index.ts b/source/index.ts index bd1034a..d53a3da 100644 --- a/source/index.ts +++ b/source/index.ts @@ -54,6 +54,7 @@ export const enum TypeName { const toString = Object.prototype.toString; const isOfType = (type: string) => (value: any): value is T => typeof value === type; +const isBuffer = (input: any): input is Buffer => !is.nullOrUndefined(input) && !is.nullOrUndefined(input.constructor) && is.function_(input.constructor.isBuffer) && input.constructor.isBuffer(input); const getObjectType = (value: any): TypeName | null => { const objectName = toString.call(value).slice(8, -1) as string; @@ -101,7 +102,7 @@ function is(value: any): TypeName { // tslint:disable-line:only-arrow-functions return TypeName.Array; } - if (Buffer.isBuffer(value)) { + if (isBuffer(value)) { return TypeName.Buffer; } @@ -132,7 +133,7 @@ namespace is { // tslint:disable-line:no-namespace // tslint:enable:variable-name export const array = Array.isArray; - export const buffer = Buffer.isBuffer; + export const buffer = isBuffer; export const nullOrUndefined = (value: any): value is null | undefined => null_(value) || undefined(value); export const object = (value: any): value is object => !nullOrUndefined(value) && (function_(value) || isObject(value));