How to use snakecase-keys - 8 common examples

To help you get started, we’ve selected a few snakecase-keys 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 nasa / earthdata-search / static / src / js / util / request / lambda.js View on Github external
transformRequest(data, headers) {
    // eslint-disable-next-line no-param-reassign
    headers.AuthTokenorization = `Bearer: ${this.authToken}`

    // Converts javascript compliant keys to snake cased keys for use
    // in URLs and request payloads
    const snakeKeyData = snakeCaseKeys(data)

    // Prevent keys that our external services don't support from being sent
    const filteredData = pick(snakeKeyData, this.permittedCmrKeys())

    // CWIC does not support CORS so all of our requests will need to go through
    // Lambda. POST requests to Lambda use a JSON string
    return JSON.stringify({ params: filteredData })
  }
github chaos-mesh / chaos-mesh / ui / src / lib / formikhelpers.ts View on Github external
export function yamlToExperiment(yamlObj: any): any {
  const { kind, metadata, spec } = snakeCaseKeys(yamlObj, {
    exclude: [/\.|\//], // Keys like app.kubernetes.io/component should be ignored
  }) as any

  if (!kind || !metadata || !spec) {
    throw new Error('Fail to parse the YAML file. Please check the kind, metadata, and spec fields.')
  }

  let result = {
    basic: {
      ...basic,
      ...metadata,
      labels: metadata.labels ? selectorsToArr(metadata.labels, ':') : [],
      annotations: metadata.annotations ? selectorsToArr(metadata.annotations, ':') : [],
      scope: {
        ...basic.scope,
        namespace_selectors: spec.selector.namespaces ?? [],
github nasa / earthdata-search / static / src / js / util / request / request.js View on Github external
transformRequest(data, headers) {
    if (this.authenticated) {
      // eslint-disable-next-line no-param-reassign
      headers.Authorization = `Bearer: ${this.authToken}`
    }

    if (data) {
      // Converts javascript compliant keys to snake cased keys for use
      // in URLs and request payloads
      const snakeKeyData = snakeCaseKeys(data, {
        exclude: [
          /edsc\.extra\.serverless/,
          'rawModel',
          'isValid'
        ]
      })

      const { ext } = data

      // Prevent keys that our external services don't support from being sent
      const filteredData = pick(snakeKeyData, this.permittedCmrKeys(ext))

      // POST requests to Lambda use a JSON string
      if (this.authenticated || this.lambda) {
        return JSON.stringify({
          requestId: this.requestId,
github nasa / earthdata-search / static / src / js / util / request / cmr.js View on Github external
transformRequest(data) {
    const cmrData = super.transformRequest(data)

    // Converts javascript compliant keys to snake cased keys for use
    // in URLs and request payloads
    const snakeKeyData = snakeCaseKeys(cmrData)

    // Prevent keys that our external services don't support from being sent
    const filteredData = pick(snakeKeyData, this.permittedCmrKeys())

    const result = prepKeysForCmr(filteredData, this.nonIndexedKeys())

    return result
  }
}
github agencyenterprise / aeboilerplate / api / src / services / tokens / save-auth-token.ts View on Github external
export const saveAuthToken = async (rawAuthToken) => {
  await db('auth_tokens').insert(snakeCaseKeys(rawAuthToken))
}
github ktmouk / hackaru-desktop / src / renderer / store / modules / api.js View on Github external
async request({ state, rootGetters }, config) {
    const res = await instance.request(
      u(config, {
        baseURL: rootGetters['auth/getApiUrl'],
        headers: { 'Accept-Language': i18n.locale },
        data: config.data && snakecaseKeys(config.data)
      })
    );
    return {
      data: camelcaseKeys(res.data || {}),
      headers: res.headers
    };
  }
};
github agencyenterprise / aeboilerplate / api / src / services / users / save-user.ts View on Github external
export const saveUser = async (rawUser) => {
  const [id] = await db('users')
    .insert(snakeCaseKeys(rawUser))
    .returning('id')

  return id
}

snakecase-keys

Convert an object's keys to snake case

MIT
Latest version published 9 days ago

Package Health Score

83 / 100
Full package analysis

Popular snakecase-keys functions