Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
522 bytes
|
Line | |
---|
1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const SAFE_IDENTIFIER = /^[_a-zA-Z$][_a-zA-Z$0-9]*$/;
|
---|
9 |
|
---|
10 | const propertyAccess = (properties, start = 0) => {
|
---|
11 | let str = "";
|
---|
12 | for (let i = start; i < properties.length; i++) {
|
---|
13 | const p = properties[i];
|
---|
14 | if (`${+p}` === p) {
|
---|
15 | str += `[${p}]`;
|
---|
16 | } else if (SAFE_IDENTIFIER.test(p)) {
|
---|
17 | str += `.${p}`;
|
---|
18 | } else {
|
---|
19 | str += `[${JSON.stringify(p)}]`;
|
---|
20 | }
|
---|
21 | }
|
---|
22 | return str;
|
---|
23 | };
|
---|
24 |
|
---|
25 | module.exports = propertyAccess;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.