-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quote module names if they are invalid identifiers (#63)
Fixes #61.
- Loading branch information
Showing
4 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** @module array-to-object-keys | ||
*/ | ||
declare module "array-to-object-keys" { | ||
/** | ||
* @typedef valueGenerator | ||
* @type {function} | ||
* @param {string} value The original array entry | ||
* @param {number} index The index of the array entry (starts at 0) | ||
* @returns {*} | ||
*/ | ||
type valueGenerator = (value: string, index: number) => any; | ||
/** | ||
* Converts an array to an object with static keys and customizable values | ||
* @example | ||
* arrayToObjectKeys(["a", "b"]) | ||
* // {a: null, b: null} | ||
* @example | ||
* arrayToObjectKeys(["a", "b"], "value") | ||
* // {a: "value", b: "value"} | ||
* @example | ||
* arrayToObjectKeys(["a", "b"], (key, index) => `value for ${key} #${index + 1}`) | ||
* // {a: "value for a #1", b: "value for b #2"} | ||
* @param {string[]} array Keys for the generated object | ||
* @param {valueGenerator|*} [valueGenerator=null] Optional function that sets the object values based on key and index | ||
* @returns {Object<string, *>} A generated object based on the array input | ||
*/ | ||
function arrayToObjectKeys(array: string[], valueGenerator?: valueGenerator | any): { | ||
[key: string]: any; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** @module array-to-object-keys */ | ||
|
||
/** | ||
* @typedef valueGenerator | ||
* @type {function} | ||
* @param {string} value The original array entry | ||
* @param {number} index The index of the array entry (starts at 0) | ||
* @returns {*} | ||
*/ | ||
|
||
/** | ||
* Converts an array to an object with static keys and customizable values | ||
* @example | ||
* arrayToObjectKeys(["a", "b"]) | ||
* // {a: null, b: null} | ||
* @example | ||
* arrayToObjectKeys(["a", "b"], "value") | ||
* // {a: "value", b: "value"} | ||
* @example | ||
* arrayToObjectKeys(["a", "b"], (key, index) => `value for ${key} #${index + 1}`) | ||
* // {a: "value for a #1", b: "value for b #2"} | ||
* @param {string[]} array Keys for the generated object | ||
* @param {valueGenerator|*} [valueGenerator=null] Optional function that sets the object values based on key and index | ||
* @returns {Object<string, *>} A generated object based on the array input | ||
*/ | ||
const arrayToObjectKeys = (array, valueGenerator = null) => { | ||
} | ||
|
||
export default arrayToObjectKeys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { expectJsDoc } from '../lib'; | ||
|
||
suite('Module Checks', () => { | ||
test('All', () => { | ||
expectJsDoc('module'); | ||
}); | ||
}); |