Sha256: ad4013a7b24e557921aad94015efa8bc3693b02dd3d8ff07c899573293f67d42

Contents?: true

Size: 668 Bytes

Versions: 2

Compression:

Stored size: 668 Bytes

Contents

function camelize(snakeCase) {
  return snakeCase.replace(/_[a-z]/g, function(match) {
    return match[1].toUpperCase();
  });
};

camelize.keys = function(object) {
  return Object.keys(object).reduce((result, key) => {
    result[camelize(key)] = object[key];
    return result;
  }, {});
};

camelize.deep = function(object) {
  if (Array.isArray(object)) {
    return object.map(camelize.deep);
  }
  else if (typeof object === 'object' && object) {
    return Object.keys(object).reduce((result, key) => {
      result[camelize(key)] = camelize.deep(object[key]);
      return result;
    }, {});
  }
  else {
    return object;
  }
};

export default camelize;

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pageflow-react-0.1.1 js/src/utils/camelize.js
pageflow-react-0.1.0 js/src/utils/camelize.js