custom-functions-metadata
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -106,2 +106,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
const functionNames = []; | ||
const metadataFunctionNames = []; | ||
const ids = []; | ||
@@ -129,3 +130,3 @@ const sourceFile = ts.createSourceFile(sourceFileName, sourceCode, ts.ScriptTarget.Latest, true); | ||
const functionName = functionDeclaration.name ? functionDeclaration.name.text : ""; | ||
if (functionNames.indexOf(functionName) > -1) { | ||
if (checkForDuplicate(functionNames, functionName)) { | ||
const errorString = `Duplicate function name: ${functionName}`; | ||
@@ -162,8 +163,8 @@ functionErrors.push(logError(errorString, position)); | ||
validateName(name, position, extra); | ||
if (functionNames.indexOf(name) > -1) { | ||
if (checkForDuplicate(metadataFunctionNames, name)) { | ||
const errorString = `@customfunction tag specifies a duplicate name: ${name}`; | ||
functionErrors.push(logError(errorString, position)); | ||
} | ||
functionNames.push(name); | ||
if (ids.indexOf(id) > -1) { | ||
metadataFunctionNames.push(name); | ||
if (checkForDuplicate(ids, id)) { | ||
const errorString = `@customfunction tag specifies a duplicate id: ${id}`; | ||
@@ -218,2 +219,27 @@ functionErrors.push(logError(errorString, position)); | ||
/** | ||
* Case insensitive check of item in list | ||
* @param list Array of strings | ||
* @param item String to check against the list | ||
*/ | ||
function checkForDuplicate(list, item) { | ||
let duplicate = false; | ||
list.forEach((value) => { | ||
if (areStringsEqual(value, item)) { | ||
duplicate = true; | ||
} | ||
}); | ||
return duplicate; | ||
} | ||
/** | ||
* Function to compare strings | ||
* @param first First string | ||
* @param second Second string | ||
* @param ignoreCase Ignore the case of the string | ||
*/ | ||
function areStringsEqual(first, second, ignoreCase = true) { | ||
return (typeof first === "string" && typeof second === "string") | ||
? first.localeCompare(second, undefined, ignoreCase ? { sensitivity: "accent" } : undefined) === 0 | ||
: first === second; | ||
} | ||
/** | ||
* Get the position of the object | ||
@@ -220,0 +246,0 @@ * @param node function, parameter, or node |
{ | ||
"name": "custom-functions-metadata", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"description": "Generate metadata for Excel Custom Functions.", | ||
@@ -55,3 +55,3 @@ "main": "./lib/main.js", | ||
}, | ||
"gitHead": "647812a97ef144f5a6e8bdb80c847beaee246c4f" | ||
"gitHead": "9701f3f5f1104c2ac41954dafba00afe938e88bd" | ||
} |
@@ -153,2 +153,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
const functionNames: string[] = []; | ||
const metadataFunctionNames: string[] = []; | ||
const ids: string[] = []; | ||
@@ -180,3 +181,3 @@ const sourceFile = ts.createSourceFile(sourceFileName, sourceCode, ts.ScriptTarget.Latest, true); | ||
if (functionNames.indexOf(functionName) > -1) { | ||
if (checkForDuplicate(functionNames, functionName)) { | ||
const errorString = `Duplicate function name: ${functionName}`; | ||
@@ -224,3 +225,3 @@ functionErrors.push(logError(errorString, position)); | ||
if (functionNames.indexOf(name) > -1) { | ||
if (checkForDuplicate(metadataFunctionNames, name)) { | ||
const errorString = `@customfunction tag specifies a duplicate name: ${name}`; | ||
@@ -230,5 +231,5 @@ functionErrors.push(logError(errorString, position)); | ||
functionNames.push(name); | ||
metadataFunctionNames.push(name); | ||
if (ids.indexOf(id) > -1) { | ||
if (checkForDuplicate(ids, id)) { | ||
const errorString = `@customfunction tag specifies a duplicate id: ${id}`; | ||
@@ -293,2 +294,30 @@ functionErrors.push(logError(errorString, position)); | ||
/** | ||
* Case insensitive check of item in list | ||
* @param list Array of strings | ||
* @param item String to check against the list | ||
*/ | ||
function checkForDuplicate(list: string[], item: string): boolean { | ||
let duplicate: boolean = false; | ||
list.forEach((value: string) => { | ||
if (areStringsEqual(value, item)) { | ||
duplicate = true; | ||
} | ||
}); | ||
return duplicate; | ||
} | ||
/** | ||
* Function to compare strings | ||
* @param first First string | ||
* @param second Second string | ||
* @param ignoreCase Ignore the case of the string | ||
*/ | ||
function areStringsEqual(first: string, second: string, ignoreCase = true): boolean { | ||
return (typeof first === "string" && typeof second === "string") | ||
? first.localeCompare(second, undefined, ignoreCase ? { sensitivity: "accent" } : undefined) === 0 | ||
: first === second; | ||
} | ||
/** | ||
* Get the position of the object | ||
@@ -295,0 +324,0 @@ * @param node function, parameter, or node |
Duplicate function name: duplicate (7,2) | ||
@customfunction tag specifies a duplicate name: DUPLICATE (7,2) | ||
@customfunction tag specifies a duplicate id: DUPLICATE (7,2) | ||
@customfunction tag specifies a duplicate id: DUPLICATE (7,2) | ||
@customfunction tag specifies a duplicate name: DUPLICATE (15,2) |
Duplicate function name: duplicate (7,2) | ||
@customfunction tag specifies a duplicate name: DUPLICATE (7,2) | ||
@customfunction tag specifies a duplicate id: DUPLICATE (7,2) | ||
@customfunction tag specifies a duplicate id: DUPLICATE (7,2) | ||
@customfunction tag specifies a duplicate name: DUPLICATE (15,2) |
@@ -16,1 +16,9 @@ /** | ||
} | ||
/** | ||
* the third function | ||
* @customfunction id DUPLICATE | ||
*/ | ||
function duplicateInTag() { | ||
// empty | ||
} |
@@ -16,1 +16,9 @@ /** | ||
} | ||
/** | ||
* the third function | ||
* @customfunction id DUPLICATE | ||
*/ | ||
function duplicateInTag() { | ||
// empty | ||
} |
@@ -51,3 +51,3 @@ /** | ||
* Duplicate function name test set in CustomFunction tag | ||
* @customfunction id testadd | ||
* @customfunction id TESTADD | ||
*/ | ||
@@ -54,0 +54,0 @@ function customNameTest(){ |
@@ -63,2 +63,3 @@ import * as assert from "assert"; | ||
assert.strictEqual(j.functions[18].options.requiresAddress, undefined, "CustomFunctions.StreamingInvocation requiresAddress - should not be present"); | ||
assert.strictEqual(j.functions[19].name, "UPPERCASE", "uppercased function name not created properly"); | ||
}); | ||
@@ -65,0 +66,0 @@ }); |
@@ -174,3 +174,8 @@ /** | ||
/** | ||
* @customfunction | ||
*/ | ||
function UPPERCASE(){} | ||
CustomFunctionMappings.ADD=add; | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155830
88
3251