Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@alcalzone/ansi-tokenize

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alcalzone/ansi-tokenize - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

6

build/ansiCodes.d.ts
import type { AnsiCode } from "./tokenize.js";
export declare const ESCAPES: Set<number>;
export declare const endCodesSet: Set<string>;
export declare const linkStartCodePrefix = "\u001B]8;;";
export declare const linkStartCodePrefixCharCodes: number[];
export declare const linkCodeSuffix = "\u0007";
export declare const linkCodeSuffixCharCode: number;
export declare const linkEndCode: string;
export declare function getLinkStartCode(url: string): string;
export declare function getEndCode(code: string): string;
export declare function ansiCodesToString(codes: AnsiCode[]): string;

@@ -9,2 +9,12 @@ import ansiStyles from "ansi-styles";

}
export const linkStartCodePrefix = "\x1B]8;;";
export const linkStartCodePrefixCharCodes = linkStartCodePrefix
.split("")
.map((char) => char.charCodeAt(0));
export const linkCodeSuffix = "\x07";
export const linkCodeSuffixCharCode = linkCodeSuffix.charCodeAt(0);
export const linkEndCode = `\x1B]8;;${linkCodeSuffix}`;
export function getLinkStartCode(url) {
return `${linkStartCodePrefix}${url}${linkCodeSuffix}`;
}
export function getEndCode(code) {

@@ -15,2 +25,4 @@ if (endCodesSet.has(code))

return endCodesMap.get(code);
if (code.startsWith(linkStartCodePrefix))
return linkEndCode;
code = code.slice(2);

@@ -17,0 +29,0 @@ if (code.includes(";")) {

18

build/tokenize.js
import isFullwidthCodePoint from "is-fullwidth-code-point";
import { ESCAPES, getEndCode } from "./ansiCodes.js";
import { ESCAPES, getEndCode, linkStartCodePrefix, linkStartCodePrefixCharCodes, } from "./ansiCodes.js";
function findNumberIndex(str) {

@@ -12,2 +12,15 @@ for (let index = 0; index < str.length; index++) {

}
function parseLinkCode(string, offset) {
string = string.slice(offset);
for (let index = 1; index < linkStartCodePrefixCharCodes.length; index++) {
if (string.charCodeAt(index) !== linkStartCodePrefixCharCodes[index]) {
return undefined;
}
}
// This is a link code (with or without the URL part). Find the end of it.
const endIndex = string.indexOf("\x07", linkStartCodePrefix.length);
if (endIndex === -1)
return undefined;
return string.slice(0, endIndex + 1);
}
function parseAnsiCode(string, offset) {

@@ -31,3 +44,4 @@ string = string.slice(offset, offset + 19);

if (ESCAPES.has(codePoint)) {
const code = parseAnsiCode(str, index);
// TODO: We should probably decide on the next character ("[" or "]") which code path to take.
const code = parseLinkCode(str, index) || parseAnsiCode(str, index);
if (code) {

@@ -34,0 +48,0 @@ ret.push({

10

package.json
{
"name": "@alcalzone/ansi-tokenize",
"version": "0.1.2",
"version": "0.1.3",
"description": "Efficiently modify strings containing ANSI escape codes",

@@ -43,2 +43,3 @@ "publishConfig": {

"ts-node": "^10.9.1",
"tsx": "^3.12.8",
"typescript": "^5.0.2"

@@ -53,3 +54,3 @@ },

"build": "tsc -p tsconfig.build.json",
"test": "ava",
"test": "NODE_OPTIONS='--loader tsx' ava",
"lint": "eslint .",

@@ -61,8 +62,5 @@ "release": "release-script"

"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm"
]
}
},
"packageManager": "yarn@3.5.0"
}

@@ -234,2 +234,6 @@ # @alcalzone/ansi-tokenize

-->
### 0.1.3 (2023-09-07)
- Fix: Support links
### 0.1.2 (2023-08-07)

@@ -236,0 +240,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc