How to use array-flatten - 10 common examples

To help you get started, we’ve selected a few array-flatten 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 obahareth / are-you-es5 / src / modules-checker.ts View on Github external
return !leafFolderName.startsWith('.')
        })
        .map(entry => {
          // If this is a scope (folder starts with @), return all
          // folders inside it (scoped packages)
          if (/@.*$/.test(entry)) {
            return getDirectories(entry)
          } else {
            return entry
          }
        })

      // Remove path from all strings
      // e.g. turn bla/bla/node_modules/@babel/core
      // into @babel/core
      nodeModules = flatten(nodeModules).map((entry: string) =>
        getLeafFolderName(entry)
      )

      return nodeModules
    }

    console.error(`Failed to find node_modules at ${this.dir}`)
    return null
  }
}
github r-murphy / babel-plugin-transform-modules-ui5 / packages / plugin / src / utils / ast.js View on Github external
export function getPropertiesOfObjectAssignOrExtendHelper(
  node,
  blockScopeNode
) {
  // Check all the args and recursively try to get props of identifiers (although they may be imported)
  return flatten(
    node.arguments.map(arg => {
      if (t.isObjectExpression(arg)) {
        return arg.properties;
      } else if (t.isIdentifier(arg)) {
        // Recursive, although props will be empty if arg is an imported object
        return getOtherPropertiesOfIdentifier(blockScopeNode, arg.name);
      }
    })
  );
}
github r-murphy / babel-plugin-transform-modules-ui5 / packages / plugin / src / utils / ast.js View on Github external
export function getOtherPropertiesOfIdentifier(blockScopeNode, idName) {
  return flatten(
    blockScopeNode.body
      .map(node => {
        if (t.isExpressionStatement(node)) {
          // ID = value | ID.key = value | ID.key.nested = value
          const { left, right } = node.expression;
          if (t.isAssignmentExpression(node.expression)) {
            if (t.isIdentifier(left) && left.name === idName) {
              // ID = value
              if (t.isObjectExpression(right)) {
                // ID = {}
                return right.properties; // Array
              }
            } else {
              const { object, property: key } = left;
              if (t.isIdentifier(object) && object.name === idName) {
                // ID.key = value
github sprut666666 / com.sprut.homekit / node_modules / bonjour / lib / mdns-server.js View on Github external
query.questions.forEach(function (question) {
    var type = question.type
    var name = question.name

    // generate the answers section
    var answers = type === 'ANY'
      ? flatten.depth(Object.keys(self.registry).map(self._recordsFor.bind(self, name)), 1)
      : self._recordsFor(name, type)

    if (answers.length === 0) return

    // generate the additionals section
    var additionals = []
    if (type !== 'ANY') {
      answers.forEach(function (answer) {
        if (answer.type !== 'PTR') return
        additionals = additionals
          .concat(self._recordsFor(answer.data, 'SRV'))
          .concat(self._recordsFor(answer.data, 'TXT'))
      })

      // to populate the A and AAAA records, we need to get a set of unique
      // targets from the SRV record
github sx1989827 / DOClever / Desktop / node_modules / bonjour / lib / registry.js View on Github external
function teardown (server, services, cb) {
  if (!Array.isArray(services)) services = [services]

  services = services.filter(function (service) {
    return service._activated // ignore services not currently starting or started
  })

  var records = flatten.depth(services.map(function (service) {
    service._activated = false
    var records = service._records()
    records.forEach(function (record) {
      record.ttl = 0 // prepare goodbye message
    })
    return records
  }), 1)

  if (records.length === 0) return cb && cb()

  server.unregister(records)

  // send goodbye message
  server.mdns.respond(records, function () {
    services.forEach(function (service) {
      service.published = false
github watson / bonjour / lib / mdns-server.js View on Github external
query.questions.forEach(function (question) {
    var type = question.type
    var name = question.name

    // generate the answers section
    var answers = type === 'ANY'
      ? flatten.depth(Object.keys(self.registry).map(self._recordsFor.bind(self, name)), 1)
      : self._recordsFor(name, type)

    if (answers.length === 0) return

    // generate the additionals section
    var additionals = []
    if (type !== 'ANY') {
      answers.forEach(function (answer) {
        if (answer.type !== 'PTR') return
        additionals = additionals
          .concat(self._recordsFor(answer.data, 'SRV'))
          .concat(self._recordsFor(answer.data, 'TXT'))
      })
    }

    self.mdns.respond({ answers: answers, additionals: additionals }, function (err) {
github watson / bonjour / lib / registry.js View on Github external
function teardown (server, services, cb) {
  if (!Array.isArray(services)) services = [services]

  services = services.filter(function (service) {
    return service._activated // ignore services not currently starting or started
  })

  var records = flatten.depth(services.map(function (service) {
    service._activated = false
    var records = service._records()
    records.forEach(function (record) {
      record.ttl = 0 // prepare goodbye message
    })
    return records
  }), 1)

  if (records.length === 0) return cb && cb()

  server.unregister(records)

  // send goodbye message
  server.mdns.respond(records, function () {
    services.forEach(function (service) {
      service.published = false
github sx1989827 / DOClever / Desktop / node_modules / bonjour / lib / mdns-server.js View on Github external
query.questions.forEach(function (question) {
    var type = question.type
    var name = question.name

    // generate the answers section
    var answers = type === 'ANY'
      ? flatten.depth(Object.keys(self.registry).map(self._recordsFor.bind(self, name)), 1)
      : self._recordsFor(name, type)

    if (answers.length === 0) return

    // generate the additionals section
    var additionals = []
    if (type !== 'ANY') {
      answers.forEach(function (answer) {
        if (answer.type !== 'PTR') return
        additionals = additionals
          .concat(self._recordsFor(answer.data, 'SRV'))
          .concat(self._recordsFor(answer.data, 'TXT'))
      })

      // to populate the A and AAAA records, we need to get a set of unique
      // targets from the SRV record
github nearform / node-clinic-bubbleprof / visualizer / layout / positioning.js View on Github external
}

      const parentClump = this.clumpById[layoutNodeLeaf.parent ? layoutNodeLeaf.parent.id : 0]

      // TODO: find out why at aggregateNode level sometimes there's a node on its own like this
      if (!parentClump) continue

      if (parentClump.orientation !== 'center') {
        insertAtSide = this.orientationToInsertionSide[parentClump.orientation]
      }
      parentClump[insertAtSide](leaf.id)
      const updateSide = leaf === this.leadingLeaf ? 'center' : this.insertionSideToOrientation[insertAtSide]
      this.leavesOnSide[updateSide]++
    }

    this.order = arrayFlatten(roots.map(rootId => arrayFlatten(this.clumpById[rootId])))
  }
}
github airbnb / react-with-styles-interface-aphrodite / src / utils / resolveWithRTL.js View on Github external
export default function resolveWithRTL(css, styles) {
  const flattenedStyles = flatten(styles);

  const {
    aphroditeStyles,
    hasInlineStyles,
    inlineStyles,
  } = separateStyles(flattenedStyles);

  aphroditeStyles.forEach((stylesObj) => {
    // The _definition key is an implementation detail of aphrodite. If aphrodite
    // changes it in the future, this code will need to be updated.
    const definition = stylesObj._definition;
    const directionalStyles = generateDirectionalStyles(definition);

    if (!directionalStyles) return;

    stylesObj._definition = directionalStyles; // eslint-disable-line no-param-reassign

array-flatten

Flatten nested arrays

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis