-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-variable-names.ts
41 lines (38 loc) · 996 Bytes
/
get-variable-names.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use strict";
import { getVariableName } from "./get-variable-name";
/**
* Get the names of a list of variables as an `Array` of string.
*
* @remarks
* You must wrap the variables with an `Array` of object literal, like the
* example below:
*
* ```typescript
* const object = { property: 1337 };
* const { property } = object;
*
* // Should return ["object", "property"]
* getVariableNames(
* [
* { object },
* { property },
* ]);
* ```
*
* @since 0.0.1
*
* @param wrappers The target variables wrapped by an `Array` of object literal
* @return The names of the variables
*/
export function getVariableNames(wrappers: object[]): string[]
{
if (!Array.isArray(wrappers))
{
throw new TypeError(`${ getVariableName({ wrappers }) } is not an Array`);
}
else if (wrappers.length === 0)
{
throw new TypeError(`${ getVariableName({ wrappers }) } has no items`);
}
return wrappers.map(getVariableName);
}