How to use decamelize-keys - 9 common examples

To help you get started, we’ve selected a few decamelize-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 DS3Lab / easeml / client / javascript / easemlclient / src / datasets.js View on Github external
function createDataset (input) {
  // Collect fields of interest.
  input = decamelizeKeys(input, '-')
  let data = {
    'id': input['id'],
    'source': input['source'],
    'source-address': input['source-address'],
    'name': input['name'] || '',
    'description': input['description'] || '',
    'access-key': input['access-key'] || ''
  }

  // Run post request as a promise.
  return new Promise((resolve, reject) => {
    this.axiosInstance.post('/datasets', data)
      .then(result => {
        let id = result.headers.location
        id = id.substr(id.lastIndexOf('/') + 1)
github DS3Lab / easeml / client / javascript / easemlclient / src / jobs.js View on Github external
function createJob (input) {
  // Collect fields of interest.
  input = decamelizeKeys(input, '-')
  let data = {
    'dataset': input['dataset'],
    'objective': input['objective'],
    'alt-objectives': input['alt-objectives'] || [],
    'models': input['models'],
    'accept-new-models': input['accept-new-models'] === true,
    'max-tasks': Number(input['max-tasks']),
    'config-space': input['config-space'] || ''
  }

  // The config space must be passed as a string because that is how it is stored.
  if (typeof data['config-space'] !== 'string') {
    data['config-space'] = JSON.stringify(data['config-space'])
  }

  // Run post request as a promise.
github DS3Lab / easeml / client / javascript / easemlclient / src / tasks.js View on Github external
function getTasks (query) {
  // This allows us to accept camel case keys.
  query = decamelizeKeys(query || {}, '-')

  // Run query and collect results as a promise.
  return new Promise((resolve, reject) => {
    common.runGetQuery(this.axiosInstance, '/tasks', query)
      .then(data => {
        let items = []

        if (data) {
          for (let i = 0; i < data.length; i++) {
            items.push(transformDataItem(data[i]))
          }
        }

        resolve(items)
      })
      .catch(e => {
github DS3Lab / easeml / client / javascript / easemlclient / src / datasets.js View on Github external
function getDatasets (query) {
  // This allows us to accept camel case keys.
  query = decamelizeKeys(query || {}, '-')

  // Reformat schema fields.
  if ('schema-in' in query && typeof (query['schema-in']) !== 'string') {
    query['schema-in'] = JSON.stringify(query['schema-in'])
  }
  if ('schema-out' in query && typeof (query['schema-out']) !== 'string') {
    query['schema-out'] = JSON.stringify(query['schema-out'])
  }

  // Run query and collect results as a promise.
  return new Promise((resolve, reject) => {
    common.runGetQuery(this.axiosInstance, '/datasets', query)
      .then(data => {
        let items = []

        if (data) {
github DS3Lab / easeml / client / javascript / easemlclient / src / modules.js View on Github external
function validateModuleFields (input) {
  input = decamelizeKeys(input, '-')
  let errors = {}

  if (!input.id) {
    errors['id'] = 'The id must be specified.'
  } else if (!common.ID_FORMAT.test(input.id)) {
    errors['id'] = 'The id can contain only letters, numbers and underscores.'
  }

  if (!input.source) {
    errors['type'] = 'The type must be specified.'
  } else if (!['model', 'objective', 'optimizer'].includes(input.source)) {
    errors['source'] = 'The type must be either "model", "objective" or "optimizer".'
  }

  if (!input.source) {
    errors['source'] = 'The source must be specified.'
github DS3Lab / easeml / client / javascript / easemlclient / src / jobs.js View on Github external
function validateJobFields (input) {
  input = decamelizeKeys(input, '-')
  let errors = {}

  if (!input.dataset) {
    errors['dataset'] = 'The dataset must be specified.'
  }

  if (!input.objective) {
    errors['objective'] = 'The objective must be specified.'
  }

  if (!input.models) {
    errors['models'] = 'The models list must be specified and cannot be empty.'
  }

  return errors
}
github akameco / pixiv-app-api / src / index.ts View on Github external
private async _get(
    target: string,
    options: PixivFetchOptions = {}
  ): Promise {
    options = options || {}

    if (options.data) {
      options.method = 'post'
      options.headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
      options.data = stringify(decamelizeKeys(options.data))
    }

    if (options.params) {
      options.params = decamelizeKeys(options.params)
    }
    const { data } = await instance(target, options as AxiosRequestConfig)
    this.nextUrl = data && data.next_url ? data.next_url : null
    return this.camelcaseKeys ? camelcaseKeys(data, { deep: true }) : data
  }
}
github akameco / pixiv-app-api / src / index.ts View on Github external
password: '',
      refreshToken: ''
    }

    if (this.refreshToken === '') {
      data.grantType = 'password'
      data.username = this.username
      data.password = this.password
    } else {
      data.grantType = 'refresh_token'
      data.refreshToken = this.refreshToken
    }

    const axiosResponse = await axios.post(
      'https://oauth.secure.pixiv.net/auth/token',
      stringify(decamelizeKeys(data)),
      { headers }
    )

    const { response } = axiosResponse.data
    this.auth = response
    this.refreshToken = axiosResponse.data.response.refresh_token
    instance.defaults.headers.common.Authorization = `Bearer ${response.access_token}`
    return this.camelcaseKeys
      ? camelcaseKeys(response, { deep: true })
      : response
  }
github akameco / pixiv-app-api / src / index.ts View on Github external
private async _get(
    target: string,
    options: PixivFetchOptions = {}
  ): Promise {
    options = options || {}

    if (options.data) {
      options.method = 'post'
      options.headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
      options.data = stringify(decamelizeKeys(options.data))
    }

    if (options.params) {
      options.params = decamelizeKeys(options.params)
    }
    const { data } = await instance(target, options as AxiosRequestConfig)
    this.nextUrl = data && data.next_url ? data.next_url : null
    return this.camelcaseKeys ? camelcaseKeys(data, { deep: true }) : data
  }
}

decamelize-keys

Convert object keys from camel case

MIT
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis

Popular decamelize-keys functions