PHP 8.2.30
Preview: format.js Size: 1.91 KB
/proc/thread-self/root/proc/self/root/opt/alt/alt-nodejs18/root/lib/node_modules/npm/lib/utils/format.js

const { formatWithOptions: baseFormatWithOptions } = require('node:util')

// These are most assuredly not a mistake
// https://eslint.org/docs/latest/rules/no-control-regex
// \x00 through \x1f, \x7f through \x9f, not including \x09 \x0a \x0b \x0d
/* eslint-disable-next-line no-control-regex */
const HAS_C01 = /[\x00-\x08\x0c\x0e-\x1f\x7f-\x9f]/

// Allows everything up to '[38;5;255m' in 8 bit notation
const ALLOWED_SGR = /^\[[0-9;]{0,8}m/

// '[38;5;255m'.length
const SGR_MAX_LEN = 10

// Strips all ANSI C0 and C1 control characters (except for SGR up to 8 bit)
function STRIP_C01 (str) {
  if (!HAS_C01.test(str)) {
    return str
  }
  let result = ''
  for (let i = 0; i < str.length; i++) {
    const char = str[i]
    const code = char.charCodeAt(0)
    if (!HAS_C01.test(char)) {
      // Most characters are in this set so continue early if we can
      result = `${result}${char}`
    } else if (code === 27 && ALLOWED_SGR.test(str.slice(i + 1, i + SGR_MAX_LEN + 1))) {
      // \x1b with allowed SGR
      result = `${result}\x1b`
    } else if (code <= 31) {
      // escape all other C0 control characters besides \x7f
      result = `${result}^${String.fromCharCode(code + 64)}`
    } else {
      // hasC01 ensures this is now a C1 control character or \x7f
      result = `${result}^${String.fromCharCode(code - 64)}`
    }
  }
  return result
}

const formatWithOptions = ({ prefix: prefixes = [], eol = '\n', ...options }, ...args) => {
  const prefix = prefixes.filter(p => p != null).join(' ')
  const formatted = STRIP_C01(baseFormatWithOptions(options, ...args))
  // Splitting could be changed to only `\n` once we are sure we only emit unix newlines.
  // The eol param to this function will put the correct newlines in place for the returned string.
  const lines = formatted.split(/\r?\n/)
  return lines.reduce((acc, l) => `${acc}${prefix}${prefix && l ? ' ' : ''}${l}${eol}`, '')
}

module.exports = { formatWithOptions }

Directory Contents

Dirs: 0 × Files: 34

Name Size Perms Modified Actions
1.02 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
3.21 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
2.89 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
1.56 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
1.85 KB lrwxr-xr-x 2026-03-09 09:08:36
Edit Download
1.16 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
15.38 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
14.60 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
3.03 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
2.56 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
629 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
4.70 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
1.91 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
802 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
1.71 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
1.10 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
583 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
177 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
7.78 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
2.02 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
2.36 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
767 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
252 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
9.56 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
1.91 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
886 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
5.65 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
5.21 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
4.59 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
3.47 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
2.07 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download
1013 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
1023 B lrw-r--r-- 2026-03-09 09:08:36
Edit Download
11.92 KB lrw-r--r-- 2026-03-09 09:08:36
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).