CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
viewutils.js73 linesDownload Raw Back to out
1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.icons = void 0;4exports.formatDate = formatDate;5exports.formatTime = formatTime;6exports.formatDateTime = formatDateTime;7exports.repeatString = repeatString;8exports.ratingStars = ratingStars;9exports.tableView = tableView;10exports.wordWrap = wordWrap;11exports.indentRow = indentRow;12exports.wordTrim = wordTrim;13const fixedLocale = 'en-us';14const format = {15    date: { month: 'long', day: 'numeric', year: 'numeric' },16    time: { hour: 'numeric', minute: 'numeric', second: 'numeric' },17};18const columns = process.stdout.columns ? process.stdout.columns : 80;19// xxx: Windows cmd + powershell standard fonts currently don't support the full20// unicode charset. For now we use fallback icons when on windows.21const useFallbackIcons = process.platform === 'win32';22exports.icons = useFallbackIcons23    ? { download: '\u{2193}', star: '\u{2665}', emptyStar: '\u{2022}' }24    : { download: '\u{2913}', star: '\u{2605}', emptyStar: '\u{2606}' };25function formatDate(date) {26    return date.toLocaleString(fixedLocale, format.date);27}28function formatTime(date) {29    return date.toLocaleString(fixedLocale, format.time);30}31function formatDateTime(date) {32    return date.toLocaleString(fixedLocale, { ...format.date, ...format.time });33}34function repeatString(text, count) {35    let result = '';36    for (let i = 0; i < count; i++) {37        result += text;38    }39    return result;40}41function ratingStars(rating, total = 5) {42    const c = Math.min(Math.round(rating), total);43    return `${repeatString(exports.icons.star + ' ', c)}${repeatString(exports.icons.emptyStar + ' ', total - c)}`;44}45function tableView(table, spacing = 2) {46    const maxLen = {};47    table.forEach(row => row.forEach((cell, i) => (maxLen[i] = Math.max(maxLen[i] || 0, cell.length))));48    return table.map(row => row.map((cell, i) => `${cell}${repeatString(' ', maxLen[i] - cell.length + spacing)}`).join(''));49}50function wordWrap(text, width = columns) {51    const [indent = ''] = text.match(/^\s+/) || [];52    const maxWidth = width - indent.length;53    return text54        .replace(/^\s+/, '')55        .split('')56        .reduce(([out, buffer, pos], ch) => {57        const nl = pos === maxWidth ? `\n${indent}` : '';58        const newPos = nl ? 0 : +pos + 1;59        return / |-|,|\./.test(ch) ? [`${out}${buffer}${ch}${nl}`, '', newPos] : [`${out}${nl}`, buffer + ch, newPos];60    }, [indent, '', 0])61        .slice(0, 2)62        .join('');63}64function indentRow(row) {65    return `  ${row}`;66}67function wordTrim(text, width = columns, indicator = '...') {68    if (text.length > width) {69        return text.substr(0, width - indicator.length) + indicator;70    }71    return text;72}73//# sourceMappingURL=viewutils.js.map
basant307/AI_Governance_Project · CoolFace