How to use the @serverless/utils.isArray function in @serverless/utils

To help you get started, we’ve selected a few @serverless/utils 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 serverless / components / registry / AwsLambdaFunction / src / index.js View on Github external
async pack() {
      let shims = []
      let inputDirPath = this.code

      if (isArray(this.code)) {
        inputDirPath = this.code[0] // first item is path to code dir
        shims = this.code.slice() // clone array
        shims.shift() // remove first item since it's the path to code dir
      }

      const outputFileName = `${this.instanceId}-${Date.now()}.zip`
      const outputFilePath = path.join(tmpdir(), outputFileName)

      await packDir(inputDirPath, outputFilePath, shims)
      this.zip = readFileSync(outputFilePath)
      return this.zip
    }
github serverless / components / registry / AwsLambdaFunction / src / index.js View on Github external
const hashCode = async (code) => {
  // TODO BRN: Upgrade this to hash all code references in the array. Need to redeploy in the event that the shim changes.
  const options = {
    folders: { exclude: ['node_modules'] }
  }
  let folderToHash = code
  if (isArray(code)) {
    folderToHash = code[0]
  }
  const hashObj = await hashElement(folderToHash, options)
  return hashObj.hash
}
github serverless / components / src / plugins / Info / index.js View on Github external
forEach((item) => {
    const { type, data, children } = item
    const title = item.title || data.title
    log(`|- ${title} - ${type}`)
    const subLog = (line) => log(`   ${line}`)
    if (isArray(data)) {
      printArray(compact(data), subLog, level + 1)
    } else {
      // TODO BRN: Fix this...
      // eslint-disable-next-line no-use-before-define
      printObj(compact(data), subLog, level + 1)
    }
    if (children && level <= 1) {
      if (isArray(children)) {
        printArray(compact(children), subLog)
      } else {
        // TODO BRN: Fix this...
        // eslint-disable-next-line no-use-before-define
        printObj(compact(children), subLog)
      }
    }
  }, arr)
github serverless / components / registry / AwsLambdaLayerVersion / src / index.js View on Github external
async pack() {
      let inputDirPath = this.content

      if (isArray(this.content)) {
        inputDirPath = this.content[0] // first item is path to content dir
      }

      const outputFileName = `${this.instanceId}-${Date.now()}.zip`
      const outputFilePath = path.join(tmpdir(), outputFileName)

      await packDir(inputDirPath, outputFilePath)
      this.zip = await readFile(outputFilePath)
      return this.zip
    }
github serverless / components / src / plugins / Info / index.js View on Github external
forEach((item) => {
    const { type, data, children } = item
    const title = item.title || data.title
    log(`|- ${title} - ${type}`)
    const subLog = (line) => log(`   ${line}`)
    if (isArray(data)) {
      printArray(compact(data), subLog, level + 1)
    } else {
      // TODO BRN: Fix this...
      // eslint-disable-next-line no-use-before-define
      printObj(compact(data), subLog, level + 1)
    }
    if (children && level <= 1) {
      if (isArray(children)) {
        printArray(compact(children), subLog)
      } else {
        // TODO BRN: Fix this...
        // eslint-disable-next-line no-use-before-define
        printObj(compact(children), subLog)
      }
    }
  }, arr)
github serverless / components / src / utils / variable / resolveVariables.js View on Github external
const visitVariables = (value, visited) => {
  value = resolve(value)
  if (value && !visited.has(value)) {
    if (isArray(value)) {
      visited.add(value)
      forEachIndexed((aValue, index) => (value[index] = visitVariables(aValue, visited)), value)
      visited.delete(value)
    } else if (isObject(value)) {
      visited.add(value)
      forEachObjIndexed((oValue, key) => {
        if (key !== 'children' && key !== 'inputTypes') {
          value[key] = visitVariables(oValue, visited)
        }
      }, value)
      visited.delete(value)
    }
  }
  return value
}
github serverless / components / src / plugins / Info / index.js View on Github external
const printObj = (obj, log, level = 0) => {
  if (!obj) {
    return
  }
  const subLog = (line) => log(`   ${line}`)
  if (
    (keys(obj).length === 3 || (keys(obj).length === 4 && obj.children)) &&
    obj.title &&
    obj.type &&
    obj.data
  ) {
    if (isArray(obj.data)) {
      printArray(compact(obj.data), subLog, level + 1)
    } else {
      printObj(compact(obj.data), subLog, level)
    }
    if (obj.children && level <= 1) {
      if (isArray(obj.children)) {
        printArray(compact(obj.children), subLog)
      } else {
        printObj(compact(obj.children), subLog)
      }
    }
  } else {
    forEach((val, key) => {
      if (isArray(val)) {
        printArray(val, subLog, level + 1)
      } else if (isObject(val)) {
github serverless / components / src / plugins / Info / index.js View on Github external
forEach((val, key) => {
      if (isArray(val)) {
        printArray(val, subLog, level + 1)
      } else if (isObject(val)) {
        log(`${key}:`)
        printObj(val, subLog, level + 1)
      } else {
        log(`${key}: ${val}`)
      }
    }, obj)
  }
github serverless / components / src / utils / component / walkReduceComponentOwnVariables.js View on Github external
return (accum, value, keys, iteratee, recur) => {
    let result = accum
    if (isObject(value) && !visited.has(value)) {
      if (isVariable(value)) {
        visited.add(value)
        result = iteratee(result, value, keys)
      } else if (isArray(value) || !isNativeObject(value)) {
        visited.add(value)
        forEach((childValue, childKdx) => {
          if (!isComponent(childValue)) {
            const newKeys = concat(keys, [childKdx])
            result = recur(result, childValue, newKeys, iteratee)
          }
        }, value)
      }
    }
    return result
  }
}