Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3359x 3359x 3359x 3359x 2680x 3359x 3359x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 56x 56x 56x 56x 56x 56x 56x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 39x 39x 39x 39x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 32x 32x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 502x 502x 1x 1x 1x 1x 1x 1x 1x 1x 87x 87x 87x 6x 87x 87x 1x 1x 1x 1x 1x 1x 1x 1x 351x 351x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 70x 70x 1x 1x 1x 1x 1x 1x 1x 1x 67x 67x 67x 11x 67x 67x 1x 1x 1x 1x 1x 1x 1x 1x 35x 35x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 70x 70x 1x 1x 1x 1x 1x 1x 1x 1x 64x 64x 64x 6x 64x 64x 1x 1x 1x 1x 1x 1x 1x 1x 35x 35x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 70x 70x 1x 1x 1x 1x 1x 1x 1x 1x 69x 69x 69x 3x 69x 69x 1x 1x 1x 1x 1x 1x 1x 1x 35x 35x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 70x 70x 1x 1x 1x 1x 1x 1x 1x 1x 69x 69x 69x 3x 69x 69x 1x 1x 1x 1x 1x 1x 1x 1x 35x 35x 1x | // @ts-check
import { getPrototypeOf, getTypeSignature, getDefinedConstructorName } from '../utility';
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/* eslint-disable yoda */
/**
* Detects any function type, which is ... not only the `typeof` operator
* returns the `'function'` string for the operated `value`, but the latter
* also features both of a function's call methods `call` and `apply`.
*
* This method is essential and **safe**.
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is Function}
* A boolean value which indicates whether
* the tested type is any kind of function.
* @category Base and Boxed Type Detection
*/
export function isFunction(value) {
return (
'function' === typeof value &&
'function' === typeof value.bind &&
'function' === typeof value.call &&
'function' === typeof value.apply
);
}
/* eslint-enable yoda */
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/** @typedef {import('../typedef.js').AnyObject} AnyObject */
/** @typedef {import('../typedef.js').PlainObject} PlainObject */
/** @typedef {import('../typedef.js').DictionaryObject} DictionaryObject */
/**
* Matches generic object types hence real objects and boxed objects alike
* excluding function types (though they are technically objects too) and
* the `null` value, which is a primitive value and just a placeholder for
* a yet missing/unassigned object type.
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is AnyObject}
* Whether the passed value matches the generic object type.
* @category Base and Boxed Type Detection
*/
export function isObject(value) {
// - more explicit. exits early with `false` in case
// of any passed non-object and non-null value.
return typeof value === 'object' && value !== null;
// // - exits early with `false` in case of any passed falsy
// // value like `undefined`, `null`, `''`, `0`, ``false.
// return !!value && typeof value === 'object';
}
/**
* Matches object structures where the constructor exclusively is the built-in
* `Object` type, which does exclude instances of custom ES6-class and ES3
* constructor functions.
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is PlainObject}
* Whether the passed value is a direct instance of the built-in `Object` type.
* @category Base and Boxed Type Detection
*/
export function isObjectObject(value) {
return (
getTypeSignature(value) === '[object Object]' && getDefinedConstructorName(value) === 'Object'
);
}
/**
* Matches object structures which do not have a prototype object.
* Such objects remain unaffected by changes of `Object.prototype`.
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is DictionaryObject}
* Whether the passed value can be described as _"Null-prototype object"_
* or _"Prototype-less object"_.
* @category Base and Boxed Type Detection
*/
export function isDictionaryObject(value) {
return getTypeSignature(value) === '[object Object]' && (getPrototypeOf(value) ?? null) === null;
}
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/** @typedef {import('../typedef.js').StringValue} StringValue */
/** @typedef {import('../typedef.js').BoxedString} BoxedString */
/** @typedef {import('../typedef.js').StringType} StringType */
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is StringValue}
* Whether the passed value is a primitive string value.
* @category Base and Boxed Type Detection
*/
export function isStringValue(value) {
return typeof value === 'string';
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BoxedString}
* Whether the passed value is a boxed `String` object type.
* @category Base and Boxed Type Detection
*/
export function isBoxedString(value) {
return (
getTypeSignature(value) === '[object String]' &&
getDefinedConstructorName(value) === 'String' &&
typeof value === 'object'
);
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is StringType}
* Whether the passed value is a string, either a primitive string value or a boxed `String` object type.
* @category Base and Boxed Type Detection
*/
export function isString(value) {
return isStringValue(value) || isBoxedString(value);
}
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/** @typedef {import('../typedef.js').NumberValue} NumberValue */
/** @typedef {import('../typedef.js').BoxedNumber} BoxedNumber */
/** @typedef {import('../typedef.js').NumberType} NumberType */
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is NumberValue}
* Whether the passed value is a primitive number value.
* @category Base and Boxed Type Detection
*/
export function isNumberValue(value) {
return typeof value === 'number';
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BoxedNumber}
* Whether the passed value is a boxed `Number` object type.
* @category Base and Boxed Type Detection
*/
export function isBoxedNumber(value) {
return (
getTypeSignature(value) === '[object Number]' &&
getDefinedConstructorName(value) === 'Number' &&
typeof value === 'object'
);
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is NumberType}
* Whether the passed value is a number, either a primitive number value or a boxed `Number` object type.
* @category Base and Boxed Type Detection
*/
export function isNumber(value) {
return isNumberValue(value) || isBoxedNumber(value);
}
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/** @typedef {import('../typedef.js').BooleanValue} BooleanValue */
/** @typedef {import('../typedef.js').BoxedBoolean} BoxedBoolean */
/** @typedef {import('../typedef.js').BooleanType} BooleanType */
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BooleanValue}
* Whether the passed value is a primitive boolean value.
* @category Base and Boxed Type Detection
*/
export function isBooleanValue(value) {
return typeof value === 'boolean';
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BoxedBoolean}
* Whether the passed value is a boxed `Boolean` object type.
* @category Base and Boxed Type Detection
*/
export function isBoxedBoolean(value) {
return (
getTypeSignature(value) === '[object Boolean]' &&
getDefinedConstructorName(value) === 'Boolean' &&
typeof value === 'object'
);
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BooleanType}
* Whether the passed value is boolean, either a primitive boolean value or a boxed `Boolean` object type.
* @category Base and Boxed Type Detection
*/
export function isBoolean(value) {
return isBooleanValue(value) || isBoxedBoolean(value);
}
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/** @typedef {import('../typedef.js').SymbolValue} SymbolValue */
/** @typedef {import('../typedef.js').BoxedSymbol} BoxedSymbol */
/** @typedef {import('../typedef.js').SymbolType} SymbolType */
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is SymbolValue}
* Whether the passed value is a primitive symbol value.
* @category Base and Boxed Type Detection
*/
export function isSymbolValue(value) {
return typeof value === 'symbol';
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BoxedSymbol}
* Whether the passed value is a purposely boxed `Symbol` object type.
* @category Base and Boxed Type Detection
*/
export function isBoxedSymbol(value) {
return (
getTypeSignature(value) === '[object Symbol]' &&
getDefinedConstructorName(value) === 'Symbol' &&
typeof value === 'object'
);
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is SymbolType}
* Whether the passed value is a symbol, either a primitive symbol value or a purposely boxed `Symbol` object type.
* @category Base and Boxed Type Detection
*/
export function isSymbol(value) {
return isSymbolValue(value) || isBoxedSymbol(value);
}
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/** @typedef {import('../typedef.js').BigIntValue} BigIntValue */
/** @typedef {import('../typedef.js').BoxedBigInt} BoxedBigInt */
/** @typedef {import('../typedef.js').BigIntType} BigIntType */
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BigIntValue}
* Whether the passed value is a primitive bigint value.
* @category Base and Boxed Type Detection
*/
export function isBigIntValue(value) {
return typeof value === 'bigint';
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BoxedBigInt}
* Whether the passed value is a purposely boxed `BigInt` object type.
* @category Base and Boxed Type Detection
*/
export function isBoxedBigInt(value) {
return (
getTypeSignature(value) === '[object BigInt]' &&
getDefinedConstructorName(value) === 'BigInt' &&
typeof value === 'object'
);
}
/**
* @param {any} [value]
* An optionally passed value of any type.
* @returns {value is BigIntType}
* Whether the passed value is a bigint, either a primitive bigint value or a purposely boxed `BigInt` object type.
* @category Base and Boxed Type Detection
*/
export function isBigInt(value) {
return isBigIntValue(value) || isBoxedBigInt(value);
}
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
|