From 8c213ffe23218519c4fdd4407e48dab85d8d6610 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 29 Aug 2021 11:53:41 -0400 Subject: [PATCH 1/5] Fix types library structure --- lib/index.d.ts | 95 ++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index d4f52d2..ea7caf0 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,42 +1,45 @@ // Type definitions for Anser // Project: https://github.com/IonicaBizau/anser -type DecorationName = 'bold' | 'dim' | 'italic' | 'underline' | 'blink' | 'reverse' | 'hidden' | 'strikethrough'; - -export interface AnserJsonEntry { - /** The text. */ - content: string; - /** The foreground color. */ - fg: string; - /** The background color. */ - bg: string; - /** The foreground true color (if 16m color is enabled). */ - fg_truecolor: string; - /** The background true color (if 16m color is enabled). */ - bg_truecolor: string; - /** `true` if a carriageReturn \r was fount at end of line. */ - clearLine: boolean; - /** The decoration last declared before the text. */ - decoration: null | DecorationName; - /** All decorations that apply to the text. */ - decorations: Array; - /** `true` if the colors were processed, `false` otherwise. */ - was_processed: boolean; - /** A function returning `true` if the content is empty, or `false` otherwise. */ - isEmpty(): boolean; +declare namespace Anser { + type DecorationName = 'bold' | 'dim' | 'italic' | 'underline' | 'blink' | 'reverse' | 'hidden' | 'strikethrough'; + + export interface AnserJsonEntry { + /** The text. */ + content: string; + /** The foreground color. */ + fg: string; + /** The background color. */ + bg: string; + /** The foreground true color (if 16m color is enabled). */ + fg_truecolor: string; + /** The background true color (if 16m color is enabled). */ + bg_truecolor: string; + /** `true` if a carriageReturn \r was fount at end of line. */ + clearLine: boolean; + /** The decoration last declared before the text. */ + decoration: null | DecorationName; + /** All decorations that apply to the text. */ + decorations: Array; + /** `true` if the colors were processed, `false` otherwise. */ + was_processed: boolean; + + /** A function returning `true` if the content is empty, or `false` otherwise. */ + isEmpty(): boolean; + } + + export interface AnserOptions { + /** If `true`, the result will be an object. */ + json?: boolean; + /** If `true`, HTML classes will be appended to the HTML output. */ + use_classes?: boolean; + remove_empty?: boolean; + } + + type OptionsWithJson = AnserOptions & { json: true }; } -export interface AnserOptions { - /** If `true`, the result will be an object. */ - json?: boolean; - /** If `true`, HTML classes will be appended to the HTML output. */ - use_classes?: boolean; - remove_empty?: boolean; -} - -type OptionsWithJson = AnserOptions & { json: true }; - -export = class Anser { +declare class Anser { /** * Escape the input HTML. * @@ -83,7 +86,7 @@ export = class Anser { * @param options The options. * @returns The HTML output. */ - static ansiToHtml (txt: string, options?: AnserOptions): string; + static ansiToHtml (txt: string, options?: Anser.AnserOptions): string; /** * Converts ANSI input into JSON output. @@ -92,7 +95,7 @@ export = class Anser { * @param options The options. * @returns The HTML output. */ - static ansiToJson (txt: string, options?: AnserOptions): AnserJsonEntry[]; + static ansiToJson (txt: string, options?: Anser.AnserOptions): Anser.AnserJsonEntry[]; /** * Converts ANSI input into text output. @@ -100,7 +103,7 @@ export = class Anser { * @param txt The input text. * @returns The text output. */ - static ansiToText (txt: string, options?: AnserOptions): string; + static ansiToText (txt: string, options?: Anser.AnserOptions): string; /** * Sets up the palette. @@ -130,7 +133,7 @@ export = class Anser { * @param options The options. * @returns The HTML output. */ - ansiToHtml (txt: string, options?: AnserOptions): string; + ansiToHtml (txt: string, options?: Anser.AnserOptions): string; /** * Converts ANSI input into HTML output. @@ -139,7 +142,7 @@ export = class Anser { * @param options The options. * @returns The JSON output. */ - ansiToJson (txt: string, options?: AnserOptions): AnserJsonEntry[]; + ansiToJson (txt: string, options?: Anser.AnserOptions): Anser.AnserJsonEntry[]; /** * Converts ANSI input into HTML output. @@ -147,7 +150,7 @@ export = class Anser { * @param txt The input text. * @returns The text output. */ - ansiToText (txt: string, options?: AnserOptions): string; + ansiToText (txt: string, options?: Anser.AnserOptions): string; /** * Processes the input. @@ -156,8 +159,8 @@ export = class Anser { * @param options The options. * @param markup If false, the colors will not be parsed. */ - process (txt: string, options: OptionsWithJson, markup?: boolean): AnserJsonEntry[]; - process (txt: string, options?: AnserOptions, markup?: boolean): string; + process (txt: string, options: Anser.OptionsWithJson, markup?: boolean): Anser.AnserJsonEntry[]; + process (txt: string, options?: Anser.AnserOptions, markup?: boolean): string; /** * Processes the current chunk into json output. @@ -167,7 +170,7 @@ export = class Anser { * @param markup If false, the colors will not be parsed. * @return The JSON output. */ - processChunkJson (text: string, options?: AnserOptions, markup?: boolean): AnserJsonEntry; + processChunkJson (text: string, options?: Anser.AnserOptions, markup?: boolean): Anser.AnserJsonEntry; /** * Processes the current chunk of text. @@ -177,6 +180,8 @@ export = class Anser { * @param markup If false, the colors will not be parsed. * @return The result (object if `json` is wanted back or string otherwise). */ - processChunk (text: string, options: OptionsWithJson, markup?: boolean): AnserJsonEntry; - processChunk (text: string, options?: AnserOptions, markup?: boolean): string; + processChunk (text: string, options: Anser.OptionsWithJson, markup?: boolean): Anser.AnserJsonEntry; + processChunk (text: string, options?: Anser.AnserOptions, markup?: boolean): string; } + +export = Anser; From de6b1dc125b853b2deac1ce4e9eab1b6810bc21f Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 29 Aug 2021 11:54:01 -0400 Subject: [PATCH 2/5] Update documentation --- package.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b86c12a..167e04c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ } ], "example": [ - "When using **TypeScript** you can do the following:", + "When using **TypeScript** without --esModuleInterop enabled you can do the following:", { "code": { "content": [ @@ -57,6 +57,18 @@ ], "language": "ts" } + }, + "Or with --esModuleInterop enabled you can do the following:", + { + "code": { + "content": [ + "import Anser from 'anser';", + "const txt = \"\\u001b[38;5;196mHello\\u001b[39m \\u001b[48;5;226mWorld\\u001b[49m\";", + "console.log(Anser.ansiToHtml(txt));", + "// Hello World" + ], + "language": "ts" + } } ], "thanks": "This project is highly based on [`ansi_up`](https://github.com/drudru/ansi_up), by [@drudru](https://github.com/drudru/). Thanks! :cake:" From b70849a9b4dec774d5641cec76d2f27aa6d4cbbf Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 29 Aug 2021 12:07:23 -0400 Subject: [PATCH 3/5] Update import syntax --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 167e04c..7ab02cf 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ { "code": { "content": [ - "import * as Anser from 'anser';", + "import Anser = require('anser');", "const txt = \"\\u001b[38;5;196mHello\\u001b[39m \\u001b[48;5;226mWorld\\u001b[49m\";", "console.log(Anser.ansiToHtml(txt));", "// Hello World" From 80d48861d81b476a2c8f58ca1a8f7bc78102ca11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Tue, 7 Sep 2021 05:36:20 +0300 Subject: [PATCH 4/5] :arrow_up: 2.0.2 :tada: --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b86c12a..0a3b430 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anser", - "version": "2.0.1", + "version": "2.0.2", "description": "A low level parser for ANSI sequences.", "keywords": [ "ansi", @@ -78,4 +78,4 @@ "bloggify.json", "bloggify/" ] -} +} \ No newline at end of file From d0fc213f4c0b4dad365dec18afbed0454fd89cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Tue, 7 Sep 2021 05:37:18 +0300 Subject: [PATCH 5/5] Updated docs --- LICENSE | 2 +- README.md | 48 ++++++++++++++++++++++++++++++++++++++--------- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/LICENSE b/LICENSE index 1a1857f..3f569bb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2012-20 Ionică Bizău (https://ionicabizau.net) +Copyright (c) 2012-21 Ionică Bizău (https://ionicabizau.net) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 02e7742..1a85a5a 100644 --- a/README.md +++ b/README.md @@ -147,9 +147,17 @@ console.log(Anser.ansiToJson(txt)); -When using **TypeScript** you can do the following: +When using **TypeScript** without --esModuleInterop enabled you can do the following: ```ts -import * as Anser from 'anser'; +import Anser = require('anser'); +const txt = "\u001b[38;5;196mHello\u001b[39m \u001b[48;5;226mWorld\u001b[49m"; +console.log(Anser.ansiToHtml(txt)); +// Hello World +``` + +Or with --esModuleInterop enabled you can do the following: +```ts +import Anser from 'anser'; const txt = "\u001b[38;5;196mHello\u001b[39m \u001b[48;5;226mWorld\u001b[49m"; console.log(Anser.ansiToHtml(txt)); // Hello World @@ -418,17 +426,22 @@ This project is highly based on [`ansi_up`](https://github.com/drudru/ansi_up), If you are using this library in one of your projects, add it in this list. :sparkles: - `react-native` - - `react-native-windows` + - `gatsby` - `ansi-to-react` - - `mesh-devtool` + - `react-native-windows` - `@next/react-dev-overlay` + - `@cubejs-client/react` + - `mesh-devtool` - `nuclide-commons-ui` - `@atom-ide-community/nuclide-commons-ui` + - `@redux-devtools/inspector-monitor-trace-tab` + - `@theia/console` - `transformime` - `@viankakrisna/react-dev-utils` - `react-webpack-build-helper` - `ansi-to-json` - `redux-devtools-trace-monitor` + - `@kui-shell/plugin-client-common` - `@axio/react-dev-utils` - `react-error-overlay-dangerous` - `timer-react-dev-utils` @@ -440,13 +453,11 @@ If you are using this library in one of your projects, add it in this list. :spa - `lambda-dev-utils` - `react-error-overlay-canary` - `@classflow/react-dev-utils` - - `nuclide` - `react-native-okhttp-fork` - `@devpodio/console` - `ipynb2html-fix` - `ipynb2html` - `webpack-isomorphic-dev-middleware` - - `@theia/console` - `react-native-macos` - `@ehyland-org/react-error-overlay` - `stack-frame-overlay` @@ -462,7 +473,6 @@ If you are using this library in one of your projects, add it in this list. :spa - `linklog` - `@naze/error` - `react-error-guard` - - `singularityui-tailer` - `@unforgiven/react-native` - `@digibear/socket-bridge` - `ada-pack` @@ -475,18 +485,38 @@ If you are using this library in one of your projects, add it in this list. :spa - `@proteria/react-scripts` - `kunai` - `react-native-kakao-maps` - - `react-ansi` - `@geeky-apo/react-native-advanced-clipboard` - `native-apple-login` - `native-google-login` - `@ryfow/react-native-windows` - - `native-kakao-login` - `@prague-digi/react-error-overlay` - `@hemith/react-native-tnk` - `react-native-sf` - `react-native-contact-list` - `@corelmax/react-native-my2c2p-sdk` + - `singularityui-tailer` + - `react-ansi` + - `react-native-responsive-size` + - `rn-flatlist-fork` + - `react-native-test-module-hhh` + - `react-native-is7` + - `@alloc/react-error-overlay` + - `@openpolitica/matomo-next` + - `@datalogic/react-native-datalogic-module` + - `@blkmarketco/components-library` + - `birken-react-native-community-image-editor` + - `native-kakao-login` + - `react-native-modal-progress-bar` + - `react-native-savv` + - `nuclide` + - `react-native-dsphoto-module` + - `rn-custom-tabview` + - `react-native-dm-player` + - `@felipesimmi/react-native-datalogic-module` - `react-native-tvos` + - `react-native-ytximkit` + - `@mindinventory/rn-top-navbar` + - `react-native-flyy` - `@office-iss/react-native-win32` diff --git a/package-lock.json b/package-lock.json index 8a7da83..bf23df6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "anser", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2a919d0..d166ce2 100644 --- a/package.json +++ b/package.json @@ -90,4 +90,4 @@ "bloggify.json", "bloggify/" ] -} \ No newline at end of file +}