How to use the humps.decamelizeKeys function in humps

To help you get started, we’ve selected a few humps examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codesandbox / codesandbox-client / packages / app / src / app / store / services / api.js View on Github external
// If it is an absolute url.
  const url = getUrl(endpoint);

  const options = { url, method };

  if (jwt) {
    options.headers = {
      Authorization: `Bearer ${jwt}`,
    };
  }

  if (body) {
    if (method === 'GET' && body != null) {
      // Convert body to ?x=y&b=a format
      options.url += optionsToParameterizedUrl(decamelizeKeys(body));
    } else {
      options.data = decamelizeKeys(body);
    }
  }

  const result = await axios(options);

  const camelizedData = shouldCamelize
    ? camelizeKeys(result.data)
    : result.data;

  // Quickfix to prevent underscored dependencies from being camelized.
  // Never store data as keys in the future.
  if (
    camelizedData &&
    camelizedData.data &&
github codesandbox / codesandbox-client / src / app / store / services / api.js View on Github external
const url = getUrl(endpoint);

  const options = { url, method };

  if (jwt) {
    options.headers = {
      Authorization: `Bearer ${jwt}`,
    };
  }

  if (body) {
    if (method === 'GET' && body != null) {
      // Convert body to ?x=y&b=a format
      options.url += optionsToParameterizedUrl(decamelizeKeys(body));
    } else {
      options.data = decamelizeKeys(body);
    }
  }

  const result = await axios(options);
  return shouldCamelize ? camelizeKeys(result.data) : result.data;
});
github DefinitelyTyped / DefinitelyTyped / humps / humps-tests.ts View on Github external
humps.depascalize('helloWorldFooBar');

humps.camelizeKeys(someObject);
humps.pascalizeKeys(someObject);
humps.decamelizeKeys(someObject);
humps.depascalizeKeys(someObject);

humps.camelizeKeys(someObject, someOptions);
humps.pascalizeKeys(someObject, someOptions);
humps.decamelizeKeys(someObject, someOptions);
humps.depascalizeKeys(someObject, someOptions);

humps.camelizeKeys(someObject, someOptions2);
humps.pascalizeKeys(someObject, someOptions2);
humps.decamelizeKeys(someObject, someOptions2);
humps.depascalizeKeys(someObject, someOptions2);

humps.camelizeKeys(someObject, someOptions3);
humps.pascalizeKeys(someObject, someOptions3);
humps.decamelizeKeys(someObject, someOptions3);
humps.depascalizeKeys(someObject, someOptions3);
github kisi-inc / client-js / lib / index.js View on Github external
return new Promise(function(resolve, reject) {
    var readyQueryParams;
    if (queryParams) {
      readyQueryParams = humps.decamelizeKeys(_.omit(queryParams, 'page'));

      if (readyQueryParams.q instanceof Object) {
        readyQueryParams.q = JSON.stringify(readyQueryParams.q);
      }
    }

    request[method.toLowerCase()](url.resolve(_this.context.baseUrl, path))
    .send(humps.decamelizeKeys(params))
    .query(readyQueryParams)
    .set('Accept', 'application/json')
    .set('X-Authentication-Token', _this.context.authenticationToken)
    .timeout(_this.context.timeout)
    .then(function(response) {
      if (_this.context.camelize) {
        response.body = humps.camelizeKeys(response.body);
      }
github cube-js / cube.js / examples / hn-insights / hnCrawler.js View on Github external
events.forEach(e => {
    outStream.write(`${JSON.stringify(humps.decamelizeKeys(e))}\n`, 'utf8');
  });
  outStream.end();
github sysgears / apollo-universal-starter-kit / modules / database / server-ts / sql / crud.js View on Github external
return async function(conds, values, trx) {
    try {
      if (values.id) {
        delete values.id;
      }

      let builder = knex(T)
        .update(decamelizeKeys(values))
        .where(decamelizeKeys(conds));

      if (trx) {
        builder.transacting(trx);
      }

      return builder;
    } catch (e) {
      log.error(`Error in ${T}.updateMultiCondition()`, e);
      throw e;
    }
  };
}
github juliantrueflynn / slack_clone / frontend / util / workspaceAPIUtil.js View on Github external
export const createWorkspace = workspace => (
  fetch('api/workspaces', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    credentials: 'include',
    body: JSON.stringify(decamelizeKeys(workspace, { separator: '_' }))
  }).then(response =>
    response.json().then(json => ({ json, response }))
  ).then(({ json, response }) => {
    if (!response.ok) {
      throw json;
    }
    return json;
  }).catch(errors => {
    throw errors || ['Unknown workspace error!'];
  })
);
github nano3labs / fetch-redux-crud / src / api / utilities.js View on Github external
export const requestBody = (record, key) =>
  JSON.stringify(humps.decamelizeKeys({ [singular(key)]: record }, { split: /(?=[A-Z0-9])/ }))
github leonardowf / leonardo-vs-react / 06-react-redux-starter-kit / src / redux / modules / login.js View on Github external
export const signup = (userProps) => {
  axios.defaults.headers.post['Content-Type'] = 'application/json'
  axios.defaults.headers.post['Accepts'] = 'application/json'

  userProps.passwordConfirmation = userProps.password

  var userSignup = {
    user: userProps
  }

  var request = axios.post('http://localhost:4000/v1/users.json', humps.decamelizeKeys(userSignup))

  return {
    type: SIGNUP,
    payload: request
  }
}
github leonardowf / leonardo-vs-react / 07-redux-call-api-implementation / src / redux / middlewares / callApi.js View on Github external
if (authenticate && authToken && userEmail) {
    headers = {
      ...headers,
      'Authorization': `Token token="${authToken}", email="${userEmail}"`
    }
  }

  if (storeId && storeResource) {
    url = `stores/${storeId}/${url}`
  }

  return axios({
    method,
    url,
    baseURL: API_ROOT,
    data: decamelizeKeys(data),
    headers
  })
  .then(function (response) {
    return camelizeKeys(response.data)
  })
  .catch(function (response) {
    return Promise.reject(response)
  })
}

humps

Underscore-to-camelCase converter (and vice versa) for strings and object keys in JavaScript.

MIT
Latest version published 7 years ago

Package Health Score

53 / 100
Full package analysis