PHP 8.2.30
Preview: get.js Size: 2.35 KB
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/lib/utils/flat/get.js

import flat from 'flat';
import { DELIMITER } from './constants.js';
import { selectParams } from './select-params.js';
import { propertyKeyRegex } from './property-key-regex.js';
const TEMP_HOLDING_KEY = 'TEMP_HOLDING_KEY';

/**
 * @load ./get.doc.md
 * @memberof module:flat
 * @param {FlattenParams}   params      flatten params from which property has to be taken
 * @param {string}          [propertyPath]  name of the property
 * @param {GetOptions}      options     options
 * @returns {any}                       when property key exists directly it returns what is inside,
 *                                      otherwise it tries to find any nested objects and returns
 *                                      them
 */
const get = (params = {}, propertyPath, options) => {
  if (!propertyPath) {
    return flat.unflatten(params);
  }

  // when object has this key - simply return it
  // we cannot rely on typeof params[propertyPath !== 'undefined' because params can actually be
  // undefined and in such case if would pass and function would return [undefined]
  if (Object.keys(params).find(key => key === propertyPath)) {
    return params[propertyPath];
  }
  const regex = propertyKeyRegex(propertyPath, options);
  const selectedParams = selectParams(params, propertyPath, options);
  const nestedProperties = Object.keys(selectedParams).reduce((memo, key, index) => {
    let newKey = key.replace(regex, `${TEMP_HOLDING_KEY}${DELIMITER}`);

    // when user wants to take allSiblings we have to fix the indexes so nested items from
    // different siblings don't overlap
    //
    // Example for key `nested.1.el`:
    //  'nested.0.el.0.value': 'val0.0',
    //  'nested.0.el.1.value': 'val0.1',
    //  'nested.1.el.0.value': 'val1',
    //  'nested.1.el.1.value': 'val2',
    //
    // has to be changed to:
    //  'TEMP_HOLDING_KEY.0.value': 'val0.0',
    //  'TEMP_HOLDING_KEY.1.value': 'val0.1',
    //  'TEMP_HOLDING_KEY.2.value': 'val1',
    //  'TEMP_HOLDING_KEY.3.value': 'val2',
    if (options?.includeAllSiblings) {
      newKey = newKey.replace(new RegExp(`${TEMP_HOLDING_KEY}\\${DELIMITER}(\\d*)`), `${TEMP_HOLDING_KEY}${DELIMITER}${index}`);
    }
    memo[newKey] = selectedParams[key];
    return memo;
  }, {});
  if (Object.keys(nestedProperties).length) {
    return flat.unflatten(nestedProperties)[TEMP_HOLDING_KEY];
  }
  return undefined;
};
export { get };

Directory Contents

Dirs: 0 × Files: 26

Name Size Perms Modified Actions
44 B lrw-r--r-- 2026-02-28 00:31:26
Edit Download
448 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
722 B lrw-r--r-- 2026-02-28 00:31:30
Edit Download
1.40 KB lrw-r--r-- 2026-02-28 00:31:30
Edit Download
906 B lrw-r--r-- 2026-02-28 00:31:32
Edit Download
2.74 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
10 B lrw-r--r-- 2026-02-28 00:31:34
Edit Download
587 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
2.35 KB lrw-r--r-- 2026-02-28 00:31:34
Edit Download
2.75 KB lrw-r--r-- 2026-02-28 00:31:34
Edit Download
66 B lrw-r--r-- 2026-02-28 00:31:44
Edit Download
567 B lrw-r--r-- 2026-02-28 00:31:46
Edit Download
2.11 KB lrw-r--r-- 2026-02-28 00:31:46
Edit Download
10 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
730 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
701 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
814 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
1.21 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.34 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
2.47 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
504 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
904 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
1.48 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
639 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.85 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
4.64 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).