How to use the flat.unflatten function in flat

To help you get started, we’ve selected a few flat 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 kvz / metriks / lib / plugin.js View on Github external
)));
    }

    // Parse comment header
    var flat         = {};
    var commentLines = stdout.match(/^#(.*)$/img);
    if (commentLines && commentLines.length) {
      commentLines.forEach(function(line) {
        var cfgKey   = line.match(/^#\s*([^:]+)\s*/)[1];
        var cfgVal   = line.match(/:\s*(.*)\s*$/)[1];
        flat[cfgKey] = cfgVal;
      });
    }

    // Convert flat -> structure to recursive
    var nested = unflatten(flat, {
      delimiter: '->',
      object   : true,
    });

    // Apply defaults to said config
    _.extend(self, self.defaultConfig, nested.config);

    // Fixed plugin options
    self.name       = path.basename(self.pluginFile, '.sh');
    self.executable = !!(1 & parseInt ((fs.statSync(self.pluginFile).mode & parseInt('777', 8)).toString(8)[0]));

    if (self.enabled === 'false') {
      self.enabled = false;
    } else {
      self.enabled = true;
    }
github jondot / storybook-cartesian / dist / index.js View on Github external
        const rows = fp.map(p => flatten.unflatten(fp.fromPairs(fp.zip(fields, p))), xproduct(fp.map(v => (isChoice(v) ? nodeValue(v) : [v]), fp.values(compiledData))));
        // filter rows (remove empty and nonvalid)
github Boulangerie / angular-translate-extract / lib / translations.js View on Github external
// Feed empty translation (null or "")
        returnTranslations[k] = self.params.nullEmpty ? null : "";
      }
    });
  }

  if (!_.isUndefined(useDefault) && useDefault) {
    returnTranslations = this.getDefaultTranslations(returnTranslations);
  }

  this.computeStats(obj, translations, returnTranslations);

  // Case namespace (tree representation)
  if (this.params.tree) {
    // We need to remove parent NS
    returnTranslations = flat.unflatten(Translations.cleanParents(returnTranslations));
  }

  return returnTranslations;
};
github kazupon / vue-cli-plugin-i18n / ui.js View on Github external
api.onAction('edit-message-action', ({ path, value, locale }) => {
      debug('edit-message-action onAction', path, value, locale)
      if (!currentProject || !currentConfig || !path) {
        console.error('edit-message-action: invalid pre-condition !!')
        return
      }

      const localePath = `${currentProject.path}/src/${currentConfig.localeDir}`
      const locales = getLocales(localePath)
      const localeMessages = getLocaleMessages(localePath, locales)
      const orderData = getSharedData('order')

      const messages = localeMessages[locale]
      const flattendMessage = flatten(messages)
      flattendMessage[path] = value
      localeMessages[locale] = unflatten(flattendMessage)
      writeLocaleMessages(localePath, locale, localeMessages[locale], orderData.value)

      setSharedData('localeMessages', localeMessages)
      setSharedData('localePaths', getLocalePaths(localeMessages))
    })
github wix-incubator / corvid / packages / corvid-fake-local-mode-editor / src / editor.js View on Github external
const unflatten = data => flat.unflatten(data, { delimiter: "/", safe: true });
github samtecspg / articulate / api / modules / intent / controllers / updateScenario.intent.controller.js View on Github external
redis.hmset(`scenario:${intentId}`, flatScenario, (err) => {

            if (err){
                const error = Boom.badImplementation('An error occurred adding the scenario data.');
                return cb(error);
            }
            return cb(null, Flat.unflatten(flatScenario));
        });
    });
github SoftwareBrothers / admin-bro / src / frontend / components / property-type / array / edit.tsx View on Github external
const normalizeParams = (params: RecordJSON['params']): RecordJSON['params'] => (
  flatten(unflatten(params, { overwrite: true }))
)
github hughsk / file-tree / index.js View on Github external
}, function(err, object) {
    if (err) return callback(err)

    object = flat.unflatten(object, { delimiter: path.sep })

    callback(null, clean(reformat(object, 'name')))
  })
}
github okta / okta-sdk-nodejs / src / config-loader.js View on Github external
var flatEnvValues = Object.keys(flattendDefaultConfig)
      .reduce((envVarMap, key) => {
        var envKey = prefix + delimiter + key.toUpperCase();

        var value = process.env[envKey];

        if (value !== undefined) {
          envVarMap[key] = typeof flattendDefaultConfig[key] === 'number' ?
            parseInt(value, 10) : value;
        }

        return envVarMap;
      }, {});

    const envConfig = flat.unflatten(flatEnvValues, flatConfig);

    this.apply(envConfig);
  }
github samtecspg / articulate / api / modules / entity / controllers / updateById.entity.controller.js View on Github external
redis.hmset(`entity:${entityId}`, RemoveBlankArray(flatEntity), (err) => {

            if (err){
                const error = Boom.badImplementation('An error occurred adding the entity data.');
                return cb(error);
            }
            return cb(null, Flat.unflatten(flatEntity));
        });
    });

flat

Take a nested Javascript object and flatten it, or unflatten an object with delimited keys

BSD-3-Clause
Latest version published 8 months ago

Package Health Score

80 / 100
Full package analysis