All files truetype.ts

100% Statements 191/191
100% Branches 33/33
100% Functions 17/17
100% Lines 191/191

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 1921x 1x 1x 1x 1x 1x 1x 86x 86x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 1x 1x 1x 1x 1x 1x 1x 1x 77x 77x 1x 1x 1x 1x 1x 1x 1x 1x 82x 82x 1x 1x 1x 1x 1x 1x 1x 1x 24x 24x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 18x 18x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 1x 1x 1x 1x 1x 1x 1x 1x 17x 17x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 1x 1x 1x 1x 1x 1x 1x 1x 1x 78x 78x 1x 78x 78x 1x 78x 78x 1x 78x 78x 75x 78x 78x 1x 1x 1x 1x 1x 1x 1x 1x 78x 78x 78x 16x 16x 78x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 6x 10x 4x 4x 4x  
/**
 * Check if a value is not undefined
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isDefined(value: any): boolean {
  return value !== undefined
}
 
/**
 * Check if value is null
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isNull(value: any): boolean {
  return value === null
}
 
/**
 * Check if value is not null
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isNotNull(value: any): boolean {
  return value !== null
}
 
/**
 * Check if value is "valid" (not null or undefined)
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isValid(value: any): boolean {
  return isDefined(value) && isNotNull(value)
}
 
/**
 * Check if value is a number
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isNumber(value: any): boolean {
  return Number.isFinite(value)
}
 
/**
 * Check if value is an integer number
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isInteger(value: any): boolean {
  return isNumber(value) && Number.isInteger(value)
}
 
/**
 * Check if value is a float point number
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isFloat(value: any): boolean {
  return isNumber(value) && !isInteger(value)
}
 
/**
 * Check if value is a boolean
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isBoolean(value: any): boolean {
  return is(value, 'Boolean')
}
 
/**
 * Check if value is a string
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isString(value: any): boolean {
  return is(value, 'String')
}
 
/**
 * Check if value is an object
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isObject(value: any): boolean {
  return is(value, 'Object')
}
 
/**
 * Check if value is an Array
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isArray(value: any): boolean {
  return Array.isArray(value)
}
 
/**
 * Check if value is a Date object
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isDate(value: any): boolean {
  return is(value, 'Date')
}
 
/**
 * Check if value is a Regular Expression
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isRegExp(value: any): boolean {
  return is(value, 'RegExp')
}
 
/**
 * Check if value is a function
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isFunction(value: any): boolean {
  return is(value, 'Function')
}
 
/**
 * Check if value is an instance of type
 *
 * @param {*} value
 * @param {string} type
 * @returns {boolean}
 */
export function is(value: any, type: string): boolean {
  switch (type) {
    case 'Integer':
      return isInteger(value)
 
    case 'Float':
      return isFloat(value)
 
    case 'Array':
      return isArray(value)
 
    default:
      return instance(value) === type
  }
}
 
/**
 * Get the constructor class name of the value
 *
 * @param {*} value
 * @returns {string}
 */
export function instance(value: any): string {
  return isValid(value)
    ? value.constructor.name
    : isNull(value)
    ? 'Null'
    : 'Undefined'
}
 
/**
 * Check if value is empty.
 * Only for string, array and objects. Any other type will return false.
 *
 * @param {*} value
 * @returns {boolean}
 */
export function isEmpty(value: any): boolean {
  if (isString(value) || isArray(value)) return !value.length
 
  if (isObject(value)) return !Object.keys(value).length
 
  return false
}