Skip to content

⬅️ Back to Table of Contents

📄 depsParser

📊 Analysis Summary

Metric Count
🔧 Functions 1

📚 Table of Contents

🛠️ File Location:

📂 packages/core/useWebWorkerFn/lib/depsParser.ts

Functions

depsParser(deps: string[], localDeps: Function[]): string

Concatenates the dependencies into a comma separated string. this string will then be passed as an argument to the "importScripts" function

Parameters:

  • deps any: array of string
  • localDeps any: array of function

Returns: undefined a string composed by the concatenation of the array elements "deps" and "importScripts".

Examples:

depsParser(['demo1', 'demo2']) // return importScripts('demo1', 'demo2')
Raw JSDoc
/**
 *
 * Concatenates the dependencies into a comma separated string.
 * this string will then be passed as an argument to the "importScripts" function
 *
 * @param deps array of string
 * @param localDeps array of function
 * @returns a string composed by the concatenation of the array
 * elements "deps" and "importScripts".
 *
 * @example
 * depsParser(['demo1', 'demo2']) // return importScripts('demo1', 'demo2')
 */

Calls:

  • deps.map(dep =>'${dep}').toString
  • localDeps.filter(dep => typeof dep === 'function').map((fn) => { const str = fn.toString() if (str.trim().startsWith('function')) { return str } else { const name = fn.name returnconst ${name} = ${str}} }).join
  • depsString.trim
Code
function depsParser(deps: string[], localDeps: Function[]) {
  if (deps.length === 0 && localDeps.length === 0)
    return ''

  const depsString = deps.map(dep => `'${dep}'`).toString()
  const depsFunctionString = localDeps.filter(dep => typeof dep === 'function').map((fn) => {
    const str = fn.toString()
    if (str.trim().startsWith('function')) {
      return str
    }
    else {
      const name = fn.name
      return `const ${name} = ${str}`
    }
  }).join(';')
  const importString = `importScripts(${depsString});`

  return `${depsString.trim() === '' ? '' : importString} ${depsFunctionString}`
}

Generated by Syntax Scribe