|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
714 bytes
|
| Rev | Line | |
|---|
| [a762898] | 1 | import { get } from './get.mjs';
|
|---|
| 2 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 3 | import { isString } from '../predicate/isString.mjs';
|
|---|
| 4 |
|
|---|
| 5 | function at(object, ...paths) {
|
|---|
| 6 | if (paths.length === 0) {
|
|---|
| 7 | return [];
|
|---|
| 8 | }
|
|---|
| 9 | const allPaths = [];
|
|---|
| 10 | for (let i = 0; i < paths.length; i++) {
|
|---|
| 11 | const path = paths[i];
|
|---|
| 12 | if (!isArrayLike(path) || isString(path)) {
|
|---|
| 13 | allPaths.push(path);
|
|---|
| 14 | continue;
|
|---|
| 15 | }
|
|---|
| 16 | for (let j = 0; j < path.length; j++) {
|
|---|
| 17 | allPaths.push(path[j]);
|
|---|
| 18 | }
|
|---|
| 19 | }
|
|---|
| 20 | const result = [];
|
|---|
| 21 | for (let i = 0; i < allPaths.length; i++) {
|
|---|
| 22 | result.push(get(object, allPaths[i]));
|
|---|
| 23 | }
|
|---|
| 24 | return result;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | export { at };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.