ansi-truncate
Advanced tools
Comparing version 1.1.1 to 1.1.2
declare const ANSI_RE: RegExp; | ||
declare const ELLIPSIS = "\u2026"; | ||
declare const ELLIPSIS_WIDTH = 1; | ||
declare const RESET = "\u001B[0m"; | ||
export { ANSI_RE, ELLIPSIS, RESET }; | ||
export { ANSI_RE, ELLIPSIS, ELLIPSIS_WIDTH, RESET }; |
/* MAIN */ | ||
const ANSI_RE = /[\x1B\x9B]/; | ||
const ELLIPSIS = '…'; | ||
const ELLIPSIS_WIDTH = 1; | ||
const RESET = '\x1B[0m'; | ||
/* EXPORT */ | ||
export { ANSI_RE, ELLIPSIS, RESET }; | ||
export { ANSI_RE, ELLIPSIS, ELLIPSIS_WIDTH, RESET }; |
import type { Options } from './types'; | ||
declare const truncate: (input: string, width: number, options?: { | ||
ellipsis?: string; | ||
ellipsisWidth?: number; | ||
}) => string; | ||
export default truncate; | ||
export type { Options }; |
/* IMPORT */ | ||
import fastStringTruncatedWidth from 'fast-string-truncated-width'; | ||
import { ANSI_RE, ELLIPSIS, RESET } from './constants.js'; | ||
import { ANSI_RE, ELLIPSIS, ELLIPSIS_WIDTH, RESET } from './constants.js'; | ||
/* MAIN */ | ||
@@ -9,3 +9,4 @@ //TODO: Maybe detect where "RESET" is necessary more precisely | ||
const ellipsis = options?.ellipsis ?? ELLIPSIS; | ||
const { index, ellipsed, truncated } = fastStringTruncatedWidth(input, { limit, ellipsis }); | ||
const ellipsisWidth = options?.ellipsisWidth ?? (ellipsis === ELLIPSIS ? ELLIPSIS_WIDTH : undefined); | ||
const { index, ellipsed, truncated } = fastStringTruncatedWidth(input, { limit, ellipsis, ellipsisWidth }); | ||
if (!truncated) | ||
@@ -12,0 +13,0 @@ return input; |
@@ -5,3 +5,3 @@ { | ||
"description": "A tiny function for truncating a string that may contain ANSI escape sequences.", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"type": "module", | ||
@@ -24,3 +24,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"fast-string-truncated-width": "^1.0.4" | ||
"fast-string-truncated-width": "^1.1.0" | ||
}, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
@@ -5,3 +5,6 @@ | ||
const ANSI_RE = /[\x1B\x9B]/; | ||
const ELLIPSIS = '…'; | ||
const ELLIPSIS_WIDTH = 1; | ||
const RESET = '\x1B[0m'; | ||
@@ -11,2 +14,2 @@ | ||
export {ANSI_RE, ELLIPSIS, RESET}; | ||
export {ANSI_RE, ELLIPSIS, ELLIPSIS_WIDTH, RESET}; |
@@ -5,3 +5,3 @@ | ||
import fastStringTruncatedWidth from 'fast-string-truncated-width'; | ||
import {ANSI_RE, ELLIPSIS, RESET} from './constants'; | ||
import {ANSI_RE, ELLIPSIS, ELLIPSIS_WIDTH, RESET} from './constants'; | ||
import type {Options} from './types'; | ||
@@ -13,7 +13,8 @@ | ||
const truncate = ( input: string, width: number, options?: { ellipsis?: string } ): string => { | ||
const truncate = ( input: string, width: number, options?: { ellipsis?: string, ellipsisWidth?: number } ): string => { | ||
const limit = width; | ||
const ellipsis = options?.ellipsis ?? ELLIPSIS; | ||
const {index, ellipsed, truncated} = fastStringTruncatedWidth ( input, { limit, ellipsis } ); | ||
const ellipsisWidth = options?.ellipsisWidth ?? ( ellipsis === ELLIPSIS ? ELLIPSIS_WIDTH : undefined ); | ||
const {index, ellipsed, truncated} = fastStringTruncatedWidth ( input, { limit, ellipsis, ellipsisWidth } ); | ||
@@ -20,0 +21,0 @@ if ( !truncated ) return input; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6353
110