Sha256: de2a18ef02584e95ef77cd59d7ce68dd3334ca3bd1027da3447ca8fb41a61c53

Contents?: true

Size: 1.12 KB

Versions: 51

Compression:

Stored size: 1.12 KB

Contents

function nameFunction(name, body) {
  return {
    [name](...args) {
      return body.apply(this, args);
    },
  }[name];
}

function isObject(thing) {
  return typeof thing === "object" && thing !== null;
}

function isNumeric(str) {
  if (typeof str != "string") return false; // we only process strings!
  return (
    !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
    !isNaN(parseFloat(str))
  ); // ...and ensure strings of whitespace fail
}

function roughSizeOfObject(object) {
  const objectList = [];
  const stack = [object];
  let bytes = 0;

  while (stack.length) {
    const value = stack.pop();

    if (typeof value === "boolean") {
      bytes += 4;
    } else if (typeof value === "string") {
      bytes += value.length * 2;
    } else if (typeof value === "number") {
      bytes += 8;
    } else if (typeof value === "object" && objectList.indexOf(value) === -1) {
      objectList.push(value);

      for (var i in value) {
        stack.push(value[i]);
      }
    }
  }
  return bytes;
}

export { nameFunction, isObject, isNumeric, roughSizeOfObject };

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
coveragebook_components-0.6.2 app/assets/js/helpers/lang.js
coveragebook_components-0.6.1 app/assets/js/helpers/lang.js
coveragebook_components-0.6.0 app/assets/js/helpers/lang.js
coveragebook_components-0.5.7 app/assets/js/helpers/lang.js
coveragebook_components-0.5.6 app/assets/js/helpers/lang.js
coveragebook_components-0.5.5 app/assets/js/helpers/lang.js
coveragebook_components-0.5.4 app/assets/js/helpers/lang.js
coveragebook_components-0.5.3 app/assets/js/helpers/lang.js
coveragebook_components-0.5.2 app/assets/js/helpers/lang.js
coveragebook_components-0.5.1 app/assets/js/helpers/lang.js
coveragebook_components-0.5.0 app/assets/js/helpers/lang.js