How to use the deepdash-es/forEachDeep function in deepdash-es

To help you get started, we’ve selected a few deepdash-es examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github panphora / remake / bundle / _remake / lib / get-project-info.js View on Github external
function _getProjectInfo () {
  let baseRoutes = [];
  let usernameRoutes = [];
  let partials = [];
  let bootstrapData = {user: {details: {}, appData: {}}, partials: {}};

  forEachDeep(tree, function (value, key, parent, context) {

    let fileNameWithoutExtension; 
    let currentFilePath;
    if (value.name) {
      fileNameWithoutExtension = value.name.replace(value.extension, ""); // e.g. "todos"
    }
    if (value.path) {
      currentFilePath = path.join(__dirname, "../../", value.path); // e.g. "../../project-files/pages/todos.hbs"
    }

    if (value.extension === ".hbs") {
      let _templateString = fs.readFileSync(currentFilePath, "utf8"); 

      // check if we're in the /pages directory
      if (currentFilePath.includes("/pages/")) {
github panphora / remake / bundle / _remake / lib / init-api-routes.js View on Github external
// default to using inline named partials as opposed to partial files
    let templateRenderFunc = RemakeStore.getNewItemRenderFunction({name: templateName});
    let bootstrapData = getBootstrapData().partials[templateName] || {};

    if (!templateRenderFunc && (!matchingPartial || !matchingPartial.templateString)) {
      showConsoleError(`Error: Couldn't find a template or partial named "${templateName}"`);
      return;
    }

    // use the user-defined partial files only if no render functions are found
    if (!templateRenderFunc) {
      templateRenderFunc = Handlebars.compile(matchingPartial.templateString);
    }

    // add a unique key to every plain object in the bootstrap data
    forEachDeep(bootstrapData, function (value, key, parentValue, context) {
      if (isPlainObject(value)) {
        value.id = getUniqueId();
      }
    });

    // construct referrer url, pathname, params, and query object from referrer url
    let referrerUrl = req.get('Referrer'); // e.g. "http://exampleapp.org/jane/todo-list/123"
    let referrerUrlParsed = new URL(referrerUrl);
    let referrerUrlPath = referrerUrlParsed.pathname; // e.g. "/jane/todo-list/123"
    let params = getParamsFromPathname(referrerUrlPath); // e.g. { username: 'jane', id: '123' }
    
    let query = {};
    for (let searchParamsPair of referrerUrlParsed.searchParams.entries()) {
      query[searchParamsPair[0]] = searchParamsPair[1]; 
    }
github panphora / remake / bundle / _remake / lib / pre-process-data.js View on Github external
export async function preProcessData ({data, user, params, addUniqueIdsToData}) {
  let currentItem;
  let parentItem;
  let someUniqueIdsAdded = false;

  forEachDeep(data, function (value, key, parentValue, context) {

    if (isPlainObject(value)) {

      // generate unique ids for every object item
      if (addUniqueIdsToData) {
        if (!value.id) {
          value.id = getUniqueId();
          someUniqueIdsAdded = true;
        }
      }

      // if an :id is specified in the route, get the data for it (currentItem and its parentItem)
      if (params.id && value.id === params.id) {
        currentItem = value;

        // loop through all parent items (objects & arrays)

deepdash-es

➔ 𝐃eep extension for 𝐋odash-es: ✓ eachDeep ✓ filterDeep ✓ pickDeep ✓ omitDeep ✓ keysDeep ✓ index ✓ condenseDeep ⋮ Parent nodes tracking ⋮ Circular references check ⋮ Leaves only mode ⋮ Path as a valid js string or an array ⋮

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Popular deepdash-es functions