lib/manifest.js
function generateManifest (manifest = {}) {
  var { url, title, description, type, author, links, web_root, fallback_page } = manifest
  if (isString(url)) manifest.url = url
  else delete manifest.url
  if (isString(title)) manifest.title = title
  else delete manifest.title
  if (isString(description)) manifest.description = description
  else delete manifest.description
  if (isString(type)) type = type.split(' ')
  if (isArrayOfStrings(type)) manifest.type = type
  else delete manifest.type
  if (isObject(links)) manifest.links = massageLinks(links)
  else delete manifest.links
  if (isString(web_root)) manifest.web_root = web_root
  else delete manifest.web_root
  if (isString(fallback_page)) manifest.fallback_page = fallback_page
  else delete manifest.fallback_page
  if (isString(author)) {
    if (author.startsWith('dat://') || DAT_HASH_REGEX.test(author)) {
      author = {url: author}
    } else {
      author = {name: author}
    }
  }
  if (isObject(author)) {
    manifest.author = {}
    if (isString(author.name)) manifest.author.name = author.name
    if (isString(author.url) && (author.url.startsWith('dat://') || DAT_HASH_REGEX.test(author.url))) {
      manifest.author.url = author.url
    }
  } else {
    delete manifest.author
  }
  return manifest
}
function generateManifest (manifest = {}) {
  var { url, title, description, type, author, links, web_root, fallback_page } = manifest
  if (isString(url)) manifest.url = url
  else delete manifest.url
  if (isString(title)) manifest.title = title
  else delete manifest.title
  if (isString(description)) manifest.description = description
  else delete manifest.description
  if (isString(type)) type = type.split(' ')
  if (isArrayOfStrings(type)) manifest.type = type
  else delete manifest.type
  if (isObject(links)) manifest.links = massageLinks(links)
  else delete manifest.links
  if (isString(web_root)) manifest.web_root = web_root
  else delete manifest.web_root
  if (isString(fallback_page)) manifest.fallback_page = fallback_page
  else delete manifest.fallback_page
  if (isString(author)) {
    if (author.startsWith('dat://') || DAT_HASH_REGEX.test(author)) {
      author = {url: author}
    } else {
      author = {name: author}
    }
  }
  if (isObject(author)) {
    manifest.author = {}
    if (isString(author.name)) manifest.author.name = author.name
    if (isString(author.url) && (author.url.startsWith('dat://') || DAT_HASH_REGEX.test(author.url))) {
      manifest.author.url = author.url
    }
  } else {
    delete manifest.author
  }
  return manifest
}
function generateManifest ( manifest = { } ) { var { url , title , description , type , author , links , web_root , fallback_page } = manifest if ( isString ( url ) ) manifest . url = url else delete manifest . url if ( isString ( title ) ) manifest . title = title else delete manifest . title if ( isString ( description ) ) manifest . description = description else delete manifest . description if ( isString ( type ) ) type = type . split ( ' ' ) if ( isArrayOfStrings ( type ) ) manifest . type = type else delete manifest . type if ( isObject ( links ) ) manifest . links = massageLinks ( links ) else delete manifest . links if ( isString ( web_root ) ) manifest . web_root = web_root else delete manifest . web_root if ( isString ( fallback_page ) ) manifest . fallback_page = fallback_page else delete manifest . fallback_page if ( isString ( author ) ) { if ( author . startsWith ( 'dat://' ) || DAT_HASH_REGEX . test ( author ) ) { author = { url : author } } else { author = { name : author } } } if ( isObject ( author ) ) { manifest . author = { } if ( isString ( author . name ) ) manifest . author . name = author . name if ( isString ( author . url ) && ( author . url . startsWith ( 'dat://' ) || DAT_HASH_REGEX . test ( author . url ) ) ) { manifest . author . url = author . url } } else { delete manifest . author } return manifest }
helper to generate a new dat.json object
helper to generate a new dat . json object