All files / packages/icons/.claude/skills/icons-release/scripts/lib types.js

0% Statements 0/32
0% Branches 0/36
0% Functions 0/3
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                                                                                                     
'use strict'
 
/**
 * Deterministic mapping from the CSV "Icon Type" free-text values to the
 * repo's canonical icon types.
 *
 *   "Standard Object"  -> standard
 *   "Utility"          -> utility
 *   "Action"           -> action
 *   "Doctype"          -> doctype
 *   "Convert existing" -> convert   (carved out of the v1 pipeline)
 *   anything else      -> null      (unmappable -> reported as ineligible)
 */
 
const REPO_TYPES = ['standard', 'utility', 'action', 'doctype']
 
function mapCsvType(rawType) {
  const value = String(rawType || '').toLowerCase().trim()
  if (!value) return null
  if (value.includes('convert existing')) return 'convert'
  if (value.includes('standard')) return 'standard'
  if (value.includes('utility')) return 'utility'
  if (value.includes('action')) return 'action'
  if (value.includes('doctype')) return 'doctype'
  return null
}
 
/**
 * Parse a "Convert existing <source> icon to <target>" CSV type into its
 * source and target repo types. The target is the canonical destination set.
 *
 *   "Convert existing standard icon to utility" -> { source: 'standard', target: 'utility' }
 *
 * Returns null when the value is not a convert row. `source`/`target` are null
 * if not parseable (caller decides how to handle).
 */
function parseConvert(rawType) {
  const value = String(rawType || '').toLowerCase()
  if (!value.includes('convert existing')) return null
  const target = (value.match(/\bto\s+(standard|utility|action|doctype|custom)/) || [])[1] || null
  const source = (value.match(/existing\s+(standard|utility|action|doctype|custom)/) || [])[1] || null
  return { source, target }
}
 
/**
 * Detect a repo type from a gdrive asset folder name, e.g.
 * "Exported Standard Icons" -> standard.
 */
function typeFromFolderName(folderName) {
  const value = String(folderName || '').toLowerCase()
  if (value.includes('standard')) return 'standard'
  if (value.includes('utility')) return 'utility'
  if (value.includes('action')) return 'action'
  if (value.includes('doctype')) return 'doctype'
  return null
}
 
module.exports = { REPO_TYPES, mapCsvType, parseConvert, typeFromFolderName }