How to use the array-flatten.depth function in array-flatten

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 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 watson / bonjour / lib / mdns-server.js View on Github external
Server.prototype._recordsFor = function (name, type) {
  var self = this

  type = type ? [type] : Object.keys(this.registry)

  return flatten.depth(type.map(function (type) {
    if (!(type in self.registry)) return []
    if (name) {
      return self.registry[type].filter(function (record) {
        var _name = ~name.indexOf('.') ? record.name : record.name.split('.')[0]
        return dnsEqual(_name, name)
      })
    } else {
      return self.registry[type]
    }
  }), 1)
}
github rstacruz / devhints-engine / packages / devhints-validator / lib / index.js View on Github external
async function run(argv /*: Array */, options /*: RunOptions */ = {}) {
  const filesLists /*: Array> */ = argv.map(spec => glob(spec))
  const files /*: Array */ = flatten(filesLists, 1)
  const results /*: Array */ = await Promise.all(
    files.map(file => {
      return runFile(file, options)
    })
  )

  const all = results
  const fixeds = results.filter(res => res.status === 'fixed')
  const errors = results.filter(res => res.status === 'error')
  const oks = results.filter(res => res.status === 'ok')

  if (all.length === oks.length) {
    return { code: 0, summary: `${all.length} files OK`, messages: [] }
  } else {
    let isSuccess = options.fix && errors.length === 0
    const filenames = fixeds.concat(errors).map(res => res.document.path)

array-flatten

Flatten nested arrays

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis