Sha256: 16cc809d0d0accd5c474a834da0f4d8045ace86289762efbc06ff38cd1ecdde1

Contents?: true

Size: 1.33 KB

Versions: 22

Compression:

Stored size: 1.33 KB

Contents

import camelCase from "lodash.camelcase";
import kebabCase from "lodash.kebabcase";
import mapValues from "lodash.mapvalues";
import keyBy from "lodash.keyby";

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,
  camelCase,
  kebabCase,
  keyBy,
  mapValues,
};

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
coveragebook_components-0.19.8 app/assets/js/helpers/lang.js
coveragebook_components-0.19.7 app/assets/js/helpers/lang.js
coveragebook_components-0.19.6 app/assets/js/helpers/lang.js
coveragebook_components-0.19.5 app/assets/js/helpers/lang.js
coveragebook_components-0.19.4 app/assets/js/helpers/lang.js
coveragebook_components-0.19.3 app/assets/js/helpers/lang.js
coveragebook_components-0.19.2 app/assets/js/helpers/lang.js
coveragebook_components-0.19.1 app/assets/js/helpers/lang.js
coveragebook_components-0.19.0 app/assets/js/helpers/lang.js
coveragebook_components-0.18.8 app/assets/js/helpers/lang.js
coveragebook_components-0.18.7 app/assets/js/helpers/lang.js
coveragebook_components-0.18.0 app/assets/js/helpers/lang.js
coveragebook_components-0.17.7 app/assets/js/helpers/lang.js
coveragebook_components-0.17.6 app/assets/js/helpers/lang.js
coveragebook_components-0.17.5 app/assets/js/helpers/lang.js
coveragebook_components-0.17.4 app/assets/js/helpers/lang.js
coveragebook_components-0.17.3 app/assets/js/helpers/lang.js
coveragebook_components-0.17.2 app/assets/js/helpers/lang.js
coveragebook_components-0.17.1 app/assets/js/helpers/lang.js
coveragebook_components-0.17.0 app/assets/js/helpers/lang.js