All files / src/type-identity utility.js

100% Statements 118/118
100% Branches 12/12
100% Functions 2/2
100% Lines 118/118

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 1291x   1x 1x   1x 1x   1x   1x 1x   1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 58x   58x 58x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 58x   58x 58x 58x 58x 57x 58x 58x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
// @ts-check
 
import { isFunction, isStringValue } from '../base';
// import { isClass, isES3Function } from '../function';
 
// import { isConstructable } from '../function/utility';
// import { getOwnPropertyDescriptor } from '../utility';
 
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
 
/** @typedef {import('../function/typedef.js').ES3Function} ES3Function */
/** @typedef {import('../function/typedef.js').ClassConstructor<typeof Function>} ClassConstructor */
 
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
 
/**
 * Does approve whether the passed value matches the default data-structure of a non-enumerable
 * property-descriptor which is ...
 * `{ value: 'string-value', enumerable: false, writable: false, configurable: true }`
 * @internal
 * @param {any} value
 * @returns {boolean}
 *  Whether the passed value matches the default data-structure of a non-enumerable property-descriptor.
 * @category Type Identity Helper
 */
export function doesMatchNonEnumerableDescriptorDefault(value) {
  const { value: key, enumerable, writable, configurable } = value || {};
 
  return isStringValue(key) && enumerable === false && writable === false && configurable === true;
}
 
/**
 * Does approve whether the passed value matches the stable
 * (redefined) form of a non-enumerable property-descriptor.
 * @internal
 * @param {any} value
 * @returns {boolean}
 *  Whether the passed value matches the stable (redefined)
 *  form of a non-enumerable property-descriptor.
 * @category Type Identity Helper
 */
export function doesMatchStableNonEnumerableDescriptor(value) {
  const { get: getKey, value: key, enumerable, writable, configurable } = value || {};
 
  return (
    ((isFunction(getKey) && isStringValue(getKey())) || isStringValue(key)) &&
    enumerable === false &&
    writable !== true &&
    configurable === false
  );
}
 
// // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
//
// /**
//  * @param {ClassConstructor | ES3Function} constructor
//  * @returns {boolean}
//  * @category Type Identity Helper
//  */
// export function isStableTypeIdentityCustomConstructor(constructor) {
//   // guard.
//   if (!isClass(constructor) && !isES3Function(constructor)) {
//     return false;
//   }
//   // const { enumerable, writable, configurable } = getOwnPropertyDescriptor(constructor, 'name');
//   // const isStableNameDescriptor =
//   //   enumerable === false && writable !== true && configurable === false;
//
//   const isStableNameDescriptor = doesMatchStableNonEnumerableDescriptor(
//     getOwnPropertyDescriptor(constructor, 'name')
//   );
//   // proceed clause.
//   if (isStableNameDescriptor) {
//     const { enumerable, writable, configurable } = getOwnPropertyDescriptor(
//       constructor.prototype,
//       Symbol.toStringTag
//     );
//     // ... does feature both ...
//     //  - a stable constructor-name descriptor ... and ...
//     //  - a stable [Symbol.toStringTag] (custom tag-name) descriptor.
//     return enumerable === false && writable !== true && configurable === false;
//   }
//   // early exit.
//   return false;
// }
//
// // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
//
// /**
//  * @param {ClassConstructor | ES3Function} constructor
//  * @param {string } taggedType
//  * @returns {boolean}
//  * @category Type Identity Helper
//  */
// export function isStableTaggedCustomConstructor(constructor, taggedType) {
//   // let isConfirmed = isConstructable(constructor) && (isClass(constructor) || isES3Function(constructor) )
//
//   // guard.
//   if (!isConstructable(constructor)) {
//     throw new TypeError(
//       'The provided "constructor" parameter must be a constructable function type.'
//     );
//   }
//   // guard.
//   if (!(isClass(constructor) || isES3Function(constructor))) {
//     throw new TypeError('A built-in constructor function is not a custom constructor.');
//   }
//   // guard.
//   if (!isString(taggedType)) {
//     throw new TypeError('The provided "taggedType" parameter must be a string type.');
//   }
//   const {
//     get: getTaggedType,
//     enumerable,
//     writable,
//     configurable
//   } = getOwnPropertyDescriptor(constructor.prototype, Symbol.toStringTag) ?? {};
//
//   return (
//     isFunction(getTaggedType) &&
//     getTaggedType() === String(taggedType) &&
//     enumerable === false &&
//     writable !== true &&
//     configurable === true
//   );
// }
//
// // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----