CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
1/**2 * @typedef Options3 *   Configuration for `stringify`.4 * @property {boolean} [padLeft=true]5 *   Whether to pad a space before a token.6 * @property {boolean} [padRight=false]7 *   Whether to pad a space after a token.8 */9 10/**11 * @typedef {Options} StringifyOptions12 *   Please use `StringifyOptions` instead.13 */14 15/**16 * Parse comma-separated tokens to an array.17 *18 * @param {string} value19 *   Comma-separated tokens.20 * @returns {Array<string>}21 *   List of tokens.22 */23export function parse(value) {24  /** @type {Array<string>} */25  const tokens = []26  const input = String(value || '')27  let index = input.indexOf(',')28  let start = 029  /** @type {boolean} */30  let end = false31 32  while (!end) {33    if (index === -1) {34      index = input.length35      end = true36    }37 38    const token = input.slice(start, index).trim()39 40    if (token || !end) {41      tokens.push(token)42    }43 44    start = index + 145    index = input.indexOf(',', start)46  }47 48  return tokens49}50 51/**52 * Serialize an array of strings or numbers to comma-separated tokens.53 *54 * @param {Array<string|number>} values55 *   List of tokens.56 * @param {Options} [options]57 *   Configuration for `stringify` (optional).58 * @returns {string}59 *   Comma-separated tokens.60 */61export function stringify(values, options) {62  const settings = options || {}63 64  // Ensure the last empty entry is seen.65  const input = values[values.length - 1] === '' ? [...values, ''] : values66 67  return input68    .join(69      (settings.padRight ? ' ' : '') +70        ',' +71        (settings.padLeft === false ? '' : ' ')72    )73    .trim()74}75 
basant307/AI_Governance_Project · CoolFace