How to use the ramda-adjunct.renameKeysWith function in ramda-adjunct

To help you get started, we’ve selected a few ramda-adjunct 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 XGHeaven / nos-node-sdk / src / lib / util.ts View on Github external
return function changeCase(obj: any): any {
    switch (type(obj)) {
      case 'Object':
        obj = renameKeysWith(renameFunc, obj)
        for (const [key, value] of Object.entries(obj)) {
          obj[key] = changeCase(value)
        }
        break
      case 'Array':
        for (let i = 0; i < obj.length; i++) {
          obj[i] = changeCase(obj[i])
        }
        obj = obj.slice() // clone
        break
    }

    return obj
  }
}
github XGHeaven / nos-node-sdk / src / lib / authorization.ts View on Github external
import { createHmac } from 'crypto'
import { join, map, pickBy, pipe, prop, sortBy, toLower, toPairs } from 'ramda'
import { renameKeysWith } from 'ramda-adjunct'
import { Resource } from '../type/resource'
import { getResourceString } from './resource'

// lower-case header name
const normalizeHeaders = renameKeysWith(toLower)

const canonicalizedHeaders = pipe(
  pickBy((_, key) => key.startsWith('x-nos-')),
  toPairs,
  sortBy(prop('0')),
  map(join(':')),
  join('\n')
)

const normalizeDate = function(date: any) {
  return new Date(date).toUTCString()
}

const joinParts = join('\n')

export function signature(secretKey: string, verb: string, headers: any, resource: Resource) {
github XGHeaven / nos-node-sdk / src / lib / util.ts View on Github external
export const camelCaseObject = renameObjectNameFactory(camelCase)
export const CamelCaseObject = renameObjectNameFactory(CamelCase)
export const kababCaseObject = renameObjectNameFactory(kababCase)

export function stream2Buffer(stream: ReadableStream): Promise {
  const bufs: Buffer[] = []
  return new Promise((resolve, reject) => {
    stream.on('data', buf => bufs.push(buf))
    stream.on('end', () => {
      resolve(Buffer.concat(bufs))
    })
    stream.on('error', reject)
  })
}

export const addMetadataPrefix = renameKeysWith(
  pipe(
    kababCase,
    concat('x-nos-')
  )
)
export function getMetadataFromHeaders(headers: Headers): ObjectMetadata {
  let keyIt = headers.keys()
  const metadata: ObjectMetadata = {}

  let res = keyIt.next()
  while (!res.done) {
    const key = res.value
    if (key.startsWith('x-nos-')) {
      metadata[key.slice(6)] = headers.get(key) as string
    }
    res = keyIt.next()