How to use custom-functions-metadata - 2 common examples

To help you get started, we’ve selected a few custom-functions-metadata 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 OfficeDev / script-lab / packages / editor / src / utils / custom-functions / index.ts View on Github external
// Start by doing a quick match for a custom functions regex.
  // This one is super cheap to do, though it may have false positives (e.g., a snippet
  //   that has "@customfunction" but not inside a JSDOC tag).
  // So if it passes, do a follow-up and call into 'custom-functions-metadata' to do
  //   the slower but more accurate check.

  const isCustomFunctionRegex = /[\s\*]@customfunction[\s\*]/i; // a regex for "@customfunction" that's
  //  either preceded or followed by a "*" or space -- i.e., a whole-word match, to avoid something like
  //  "@customfunctions" (with a plural "s" on the end).
  //   cspell:ignore customfunctions

  if (!isCustomFunctionRegex.test(content)) {
    return false;
  }

  const parseResult = parseTree(content, '' /* name, unused */, getParseTreeOptions());
  return parseResult.functions.length > 0;
}
github OfficeDev / script-lab / packages / editor / src / utils / custom-functions / index.ts View on Github external
if (result.diagnostics!.length > 0) {
    return [
      {
        javascriptFunctionName: 'compileError',
        nonCapitalizedFullName: namespace + '.' + 'CompileError',
        status: 'error',
        errors: [
          'Could not compile the snippet. Please go back to the code editor to fix any syntax errors.',
        ],
        metadata: null,
      },
    ];
  }

  const parseTreeResult = parseTree(fileContent, solution.name, getParseTreeOptions());
  // Just in case, ensure that the result is consistent:
  if (parseTreeResult.functions.length !== parseTreeResult.extras.length) {
    throw new Error('Internal error while parsing custom function snippets.');
  }

  const functions = parseTreeResult.functions.map((metadata, index) => {
    const extras = parseTreeResult.extras[index];

    const { javascriptFunctionName } = extras;

    // For the full name, add namespace to the name.
    // Since we ideally want it non-capitalized, but the custom-function-metadata
    //   will capitalize names by default, do a comparison.
    // If the funcName and metadata name are the same (modulo casing) then just use the function name.
    // Otherwise, if the name was provided using a "@customfunction id name" syntax, use the provided name,
    //   whatever casing it's in.

custom-functions-metadata

Generate metadata for Excel Custom Functions.

MIT
Latest version published 3 months ago

Package Health Score

78 / 100
Full package analysis

Popular custom-functions-metadata functions