Add has* env detection (#1207)
This commit is contained in:
@@ -9,6 +9,7 @@ Changes:
|
||||
- Add `bi*` utilities for `bigint` operations (mirror of `bn*`)
|
||||
- Add `stringPascalCase` utility
|
||||
- Add `isCodec` to check for Codec-like structures
|
||||
- Add `has*` detection shortcuts (e.g. `hasWasm` or `hasBuffer`)
|
||||
- Optimize for `hexToU8a` and `u8aToHex` functions
|
||||
- Optimize `u8aEq` to use `DataView` for compares
|
||||
- Space optimization for bip39 wordlists
|
||||
|
||||
@@ -14,6 +14,7 @@ export * from './buffer';
|
||||
export * from './compact';
|
||||
export * from './extractTime';
|
||||
export * from './format';
|
||||
export * from './has';
|
||||
export * from './hex';
|
||||
export * from './is';
|
||||
export * from './lazy';
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const hasBigInt = typeof BigInt !== 'undefined';
|
||||
export const hasBuffer = typeof Buffer !== 'undefined';
|
||||
export const hasDirname = typeof __dirname !== 'undefined';
|
||||
export const hasProcess = typeof process === 'object';
|
||||
export const hasWasm = typeof WebAssembly !== 'undefined';
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { hasBuffer } from '../has';
|
||||
|
||||
/**
|
||||
* @name isBuffer
|
||||
* @summary Tests for a `Buffer` object instance.
|
||||
@@ -16,5 +18,5 @@
|
||||
* ```
|
||||
*/
|
||||
export function isBuffer (value: unknown): value is Buffer {
|
||||
return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);
|
||||
return hasBuffer && Buffer.isBuffer(value);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { isObject } from './is/object';
|
||||
import { isU8a } from './is/u8a';
|
||||
import { u8aToHex } from './u8a/toHex';
|
||||
import { u8aToU8a } from './u8a/toU8a';
|
||||
import { hasProcess } from './has';
|
||||
|
||||
type ConsoleType = 'error' | 'log' | 'warn';
|
||||
type LogType = ConsoleType | 'debug';
|
||||
@@ -121,7 +122,7 @@ function getDebugFlag (env: string[], type: string): boolean {
|
||||
}
|
||||
|
||||
function parseEnv (type: string): [boolean, number] {
|
||||
const env = (typeof process === 'object' ? process : {}).env || {};
|
||||
const env = (hasProcess ? process : {}).env || {};
|
||||
const maxSize = parseInt(env.DEBUG_MAX || '-1', 10);
|
||||
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user