How to use the flat 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 LessWrong2 / Lesswrong2 / packages / vulcan-lib / lib / modules / settings.js View on Github external
export const getAllSettings = () => {

  const settingsObject = {};

  let rootSettings = _.clone(Meteor.settings);
  delete rootSettings.public;
  delete rootSettings.private;

  // root settings & private settings are both private
  rootSettings = flatten(rootSettings, {safe: true});
  const privateSettings = flatten(Meteor.settings.private || {}, {safe: true});

  // public settings
  const publicSettings = flatten(Meteor.settings.public || {}, {safe: true});

  // registered default values
  const registeredSettings = Settings;

  const allSettingKeys = _.union(_.keys(rootSettings), _.keys(publicSettings), _.keys(privateSettings), _.keys(registeredSettings));

  allSettingKeys.sort().forEach(key => {

    settingsObject[key] = {};

    if (typeof rootSettings[key] !== 'undefined') {
      settingsObject[key].value = rootSettings[key];
    } else if (typeof privateSettings[key] !== 'undefined') {
      settingsObject[key].value = privateSettings[key];
    } else if (typeof publicSettings[key] !== 'undefined') {
      settingsObject[key].value = publicSettings[key];
github ngneat / transloco / projects / ngneat / transloco / src / lib / helpers.ts View on Github external
export function flatten(obj: Translation): Translation {
  return flat(obj, { safe: true });
}
github bigbluebutton / bigbluebutton / bigbluebutton-html5 / imports / api / presentations / server / modifiers / addPresentation.js View on Github external
},
    ],
    downloadable: Boolean,
  });

  const selector = {
    meetingId,
    id: presentation.id,
  };

  const modifier = {
    $set: Object.assign({
      meetingId,
      'conversion.done': true,
      'conversion.error': false,
    }, flat(presentation, { safe: true })),
  };

  const cb = (err, numChanged) => {
    if (err) {
      return Logger.error(`Adding presentation2x to collection: ${err}`);
    }

    addSlides(meetingId, presentation.id, presentation.pages);

    const { insertedId } = numChanged;
    if (insertedId) {
      if (presentation.current) {
        setCurrentPresentation(meetingId, presentation.id);
      }

      return Logger.info(`Added presentation2x id=${presentation.id} meeting=${meetingId}`);
github nuxt-community / blog-module / src / build / index.js View on Github external
export function defineOptions(options, context) {
  const flattened = flat(Object.assign({}, options))
  const define = {}
  Object.keys(flattened).forEach(key => {
    define[`process.env.__NUXT_BLOG__.${key}`] = JSON.stringify(flattened[key])
  })
  context.options.build.plugins.push(new DefinePlugin(define))
}
github hashicorp / consul / ui-v2 / app / services / state.js View on Github external
guards: function(chart) {
    return Object.entries(flat(chart)).filter(([key]) => key.endsWith('.cond'));
  },
});
github broskoski / mac.are.na / src / lib / validator.js View on Github external
reportNaiveValidity() {
    let isValid = true
    const state = { ...this.validationState }
    delete state['sanitizers']
    const flat = flatten(state, { maxDepth: 2 })
    const rejects = Object.values(flat).filter(item => item.isValid === false)
    isValid = rejects.length > 0 ? false : true
    this.setState({ isValid: isValid })
  }
github jondot / storybook-cartesian / src / index.ts View on Github external
const renderWithLegend = (legend: any) => (f: any) => (props: any) =>
  f(
    unflatten(
      mapValues(
        (p: any) => legend[p != null ? p.toString() : 'null'] || p,
        flatten(props)
      )
    )
  )
github hymm / squid-tracks / src / components / result-detail-card.js View on Github external
getGeneral(result) {
    const fields = getGeneralFields();
    const picked = pick(result, fields);
    const flattened = flatten(picked);

    const map = {
      'my_team_result.key': 'my_team_result',
      'other_team_result.key': 'other_team_result',
      'game_mode.key': 'game_mode',
      'rule.key': 'rule'
    };

    const mapped = mapKeys(flattened, (value, key) => {
      return map[key] || key;
    });

    return mapped;
  }
github Canner / canner / docs / schema / locale.js View on Github external
name: 'Name',
      phone: 'Phone',
      email: 'Email',
      address: 'Address',
      consignees: 'Consignees',
      filter: {
        name: {
          label: 'Search Customer Name',
        },
        phone: {
          label: 'Search Customer Phone',
        }
      }
    }
  }),
  zh: flatten({
    share: {
      logo: '商標',
      title: '標題'
    },
    dashboard: {
      title: '總覽',
      products: '總產品數',
      orders: '總訂單數',
      customers: '總顧客數'
    },
    home: {
      title: '首頁設定',
      description: '在這裡設定你的首頁。',
      entry: {
        layoutTitle: '進場頁面',
        title: '網站標題',
github instructure / instructure-ui / lib / util / cssUtils.js View on Github external
const namespaceVariables = function (namespace, variables) {
  if (variables && Object.keys(variables).length >= 1) {
    return flat({ ['--' + namespace]: variables }, { delimiter: '-' })
  } else {
    return {}
  }
}

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