@figliolia/chalk-animation 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ChalkAnimation_1 = require("../ChalkAnimation");
4
+ const Effects_1 = require("../Effects");
5
+ const InstanceTracker_1 = require("../InstanceTracker");
6
+ const animations = [
7
+ "rainbow",
8
+ "pulse",
9
+ "glitch",
10
+ "radar",
11
+ "neon",
12
+ "karaoke",
13
+ ];
14
+ describe("Chalk Animation", () => {
15
+ afterAll(() => {
16
+ jest.restoreAllMocks();
17
+ });
18
+ describe("Spawn", () => {
19
+ beforeAll(() => {
20
+ jest.spyOn(InstanceTracker_1.InstanceTracker, "LOG").mockImplementation(() => { });
21
+ });
22
+ afterEach(() => {
23
+ InstanceTracker_1.InstanceTracker.clearAll();
24
+ InstanceTracker_1.InstanceTracker.IDs.reset();
25
+ });
26
+ animations.forEach(name => {
27
+ it(`ChalkAnimation.${name} - returns an initialized animation instance`, () => {
28
+ const animation = ChalkAnimation_1.ChalkAnimation[name]("hello");
29
+ expect(animation.effect).toEqual(Effects_1.Effects[name]);
30
+ expect(typeof animation.ID).toEqual("string");
31
+ expect(animation.text).toEqual(["hello"]);
32
+ expect(animation.lines).toEqual(1);
33
+ expect(animation.speed).toEqual(1);
34
+ expect(animation.current).toEqual(1);
35
+ expect(animation.initialized).toEqual(true);
36
+ expect(animation.stopped).toEqual(false);
37
+ expect(animation.controller).not.toEqual(null);
38
+ expect(InstanceTracker_1.InstanceTracker.bucket.size).toEqual(1);
39
+ animation.stop();
40
+ expect(animation.stopped).toEqual(true);
41
+ expect(animation.controller).toEqual(null);
42
+ });
43
+ InstanceTracker_1.InstanceTracker.loggers.forEach(method => {
44
+ it(`ChalkAnimation.${name} - subsequent console.${method} stop the animation`, () => {
45
+ const animation = ChalkAnimation_1.ChalkAnimation[name]("hello");
46
+ expect(animation.stopped).toEqual(false);
47
+ console[method]("");
48
+ expect(animation.stopped).toEqual(true);
49
+ });
50
+ });
51
+ it(`ChalkAnimation.${name} - can be stopped and restarted`, () => {
52
+ const animation = ChalkAnimation_1.ChalkAnimation[name]("hello");
53
+ animation.stop();
54
+ expect(animation.stopped).toEqual(true);
55
+ animation.start();
56
+ expect(animation.current).toEqual(2);
57
+ });
58
+ it(`ChalkAnimation.${name} - can be manually rendered at a desired frame rate`, () => {
59
+ const animation = ChalkAnimation_1.ChalkAnimation[name]("hello").stop();
60
+ expect(animation.current).toEqual(1);
61
+ animation.render();
62
+ expect(animation.current).toEqual(2);
63
+ animation.render();
64
+ expect(animation.current).toEqual(3);
65
+ });
66
+ it(`ChalkAnimation.${name} - text can be replaced`, () => {
67
+ if (name === "radar") {
68
+ return;
69
+ }
70
+ const animation = ChalkAnimation_1.ChalkAnimation[name]("Y Y Y").stop();
71
+ const f1 = animation.nextFrame();
72
+ animation.replace("Z Z Z");
73
+ const f2 = animation.nextFrame();
74
+ expect(f1.includes("Y")).toEqual(true);
75
+ expect(f1.includes("Z")).toEqual(false);
76
+ expect(f2.includes("Y")).toEqual(false);
77
+ expect(f2.includes("Z")).toEqual(true);
78
+ });
79
+ it(`ChalkAnimation.${name} - supports multiline strings`, () => {
80
+ const animation = ChalkAnimation_1.ChalkAnimation[name]("Lorem\nipsum\ndolor\nsit\namet").stop();
81
+ const frame = animation.nextFrame();
82
+ expect(animation.lines).toEqual(5);
83
+ expect(frame.split("\n")).toHaveLength(5);
84
+ });
85
+ it(`ChalkAnimation.${name} - supports 5K+ frames`, () => {
86
+ const animation = ChalkAnimation_1.ChalkAnimation[name]("Lorem\nipsum\ndolor\nsit\namet").stop();
87
+ for (let i = 0; i < 5000; i++) {
88
+ expect(() => {
89
+ animation.nextFrame();
90
+ }).not.toThrow();
91
+ }
92
+ });
93
+ });
94
+ });
95
+ });
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
3
+ }
@@ -1,5 +1,5 @@
1
- import { FrameRate } from "./FrameRate";
2
- import { Decor } from "./Decor";
1
+ import { FrameRate } from "./FrameRate.js";
2
+ import { Decor } from "./Decor.js";
3
3
  export class Animation extends FrameRate {
4
4
  lines;
5
5
  text;
@@ -1,5 +1,5 @@
1
- import { Effects } from "./Effects";
2
- import { Animation } from "./Animation";
1
+ import { Effects } from "./Effects.js";
2
+ import { Animation } from "./Animation.js";
3
3
  /**
4
4
  * Chalk Animation
5
5
  *
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import chalk from "chalk";
8
8
  import gradient from "gradient-string";
9
- import { Decor } from "./Decor";
9
+ import { Decor } from "./Decor.js";
10
10
  export class Effects {
11
11
  static longHsv = { interpolation: "hsv", hsvSpin: "long" };
12
12
  static glitchChars = "x*0987654321[]0-~@#(____!!!!\\|?????....0000\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
@@ -1,4 +1,4 @@
1
- import { InstanceTracker } from "./InstanceTracker";
1
+ import { InstanceTracker } from "./InstanceTracker.js";
2
2
  export class FrameRate extends InstanceTracker {
3
3
  current = 0;
4
4
  speed;
@@ -0,0 +1,93 @@
1
+ import { ChalkAnimation } from "../ChalkAnimation.js";
2
+ import { Effects } from "../Effects.js";
3
+ import { InstanceTracker } from "../InstanceTracker.js";
4
+ const animations = [
5
+ "rainbow",
6
+ "pulse",
7
+ "glitch",
8
+ "radar",
9
+ "neon",
10
+ "karaoke",
11
+ ];
12
+ describe("Chalk Animation", () => {
13
+ afterAll(() => {
14
+ jest.restoreAllMocks();
15
+ });
16
+ describe("Spawn", () => {
17
+ beforeAll(() => {
18
+ jest.spyOn(InstanceTracker, "LOG").mockImplementation(() => { });
19
+ });
20
+ afterEach(() => {
21
+ InstanceTracker.clearAll();
22
+ InstanceTracker.IDs.reset();
23
+ });
24
+ animations.forEach(name => {
25
+ it(`ChalkAnimation.${name} - returns an initialized animation instance`, () => {
26
+ const animation = ChalkAnimation[name]("hello");
27
+ expect(animation.effect).toEqual(Effects[name]);
28
+ expect(typeof animation.ID).toEqual("string");
29
+ expect(animation.text).toEqual(["hello"]);
30
+ expect(animation.lines).toEqual(1);
31
+ expect(animation.speed).toEqual(1);
32
+ expect(animation.current).toEqual(1);
33
+ expect(animation.initialized).toEqual(true);
34
+ expect(animation.stopped).toEqual(false);
35
+ expect(animation.controller).not.toEqual(null);
36
+ expect(InstanceTracker.bucket.size).toEqual(1);
37
+ animation.stop();
38
+ expect(animation.stopped).toEqual(true);
39
+ expect(animation.controller).toEqual(null);
40
+ });
41
+ InstanceTracker.loggers.forEach(method => {
42
+ it(`ChalkAnimation.${name} - subsequent console.${method} stop the animation`, () => {
43
+ const animation = ChalkAnimation[name]("hello");
44
+ expect(animation.stopped).toEqual(false);
45
+ console[method]("");
46
+ expect(animation.stopped).toEqual(true);
47
+ });
48
+ });
49
+ it(`ChalkAnimation.${name} - can be stopped and restarted`, () => {
50
+ const animation = ChalkAnimation[name]("hello");
51
+ animation.stop();
52
+ expect(animation.stopped).toEqual(true);
53
+ animation.start();
54
+ expect(animation.current).toEqual(2);
55
+ });
56
+ it(`ChalkAnimation.${name} - can be manually rendered at a desired frame rate`, () => {
57
+ const animation = ChalkAnimation[name]("hello").stop();
58
+ expect(animation.current).toEqual(1);
59
+ animation.render();
60
+ expect(animation.current).toEqual(2);
61
+ animation.render();
62
+ expect(animation.current).toEqual(3);
63
+ });
64
+ it(`ChalkAnimation.${name} - text can be replaced`, () => {
65
+ if (name === "radar") {
66
+ return;
67
+ }
68
+ const animation = ChalkAnimation[name]("Y Y Y").stop();
69
+ const f1 = animation.nextFrame();
70
+ animation.replace("Z Z Z");
71
+ const f2 = animation.nextFrame();
72
+ expect(f1.includes("Y")).toEqual(true);
73
+ expect(f1.includes("Z")).toEqual(false);
74
+ expect(f2.includes("Y")).toEqual(false);
75
+ expect(f2.includes("Z")).toEqual(true);
76
+ });
77
+ it(`ChalkAnimation.${name} - supports multiline strings`, () => {
78
+ const animation = ChalkAnimation[name]("Lorem\nipsum\ndolor\nsit\namet").stop();
79
+ const frame = animation.nextFrame();
80
+ expect(animation.lines).toEqual(5);
81
+ expect(frame.split("\n")).toHaveLength(5);
82
+ });
83
+ it(`ChalkAnimation.${name} - supports 5K+ frames`, () => {
84
+ const animation = ChalkAnimation[name]("Lorem\nipsum\ndolor\nsit\namet").stop();
85
+ for (let i = 0; i < 5000; i++) {
86
+ expect(() => {
87
+ animation.nextFrame();
88
+ }).not.toThrow();
89
+ }
90
+ });
91
+ });
92
+ });
93
+ });
package/dist/mjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { ChalkAnimation } from "./ChalkAnimation";
2
- export * from "./types";
1
+ export { ChalkAnimation } from "./ChalkAnimation.js";
2
+ export * from "./types.js";
@@ -1,3 +1,4 @@
1
1
  {
2
- "type": "module"
3
- }
2
+ "type": "module",
3
+ "exports": "./index.js"
4
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@figliolia/chalk-animation",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "An ESM/Common.js compatible typescript port of the popular 'chalk-animation' library",
5
5
  "keywords": [
6
6
  "animation",
@@ -30,23 +30,21 @@
30
30
  "exports": {
31
31
  ".": {
32
32
  "import": "./dist/mjs/index.js",
33
- "require": "./dist/cjs/index.js"
33
+ "require": "./dist/cjs/index.js",
34
+ "types": "./dist/types/index.d.ts"
34
35
  }
35
36
  },
36
37
  "main": "dist/cjs/index.js",
37
38
  "module": "dist/mjs/index.js",
38
- "types": "dist/mjs/index.d.ts",
39
+ "types": "dist/types/index.d.ts",
39
40
  "bin": "./cli.js",
40
41
  "files": [
41
42
  "dist",
42
43
  "src/*"
43
44
  ],
44
45
  "scripts": {
45
- "build": "rm -rf dist && yarn build-esm && yarn build-cjs && yarn package-targets",
46
- "build-cjs": "tsc -p cd/tsconfig.cjs.json",
47
- "build-esm": "tsc -p cd/tsconfig.mjs.json",
46
+ "build": "npx ts-packager -e src",
48
47
  "lint": "tsc --noemit && eslint ./ --fix",
49
- "package-targets": "cd/package.sh",
50
48
  "test": "jest"
51
49
  },
52
50
  "dependencies": {
@@ -55,6 +53,7 @@
55
53
  "gradient-string": "^2.0.2"
56
54
  },
57
55
  "devDependencies": {
56
+ "@figliolia/ts-packager": "^1.0.3",
58
57
  "@swc/core": "^1.3.99",
59
58
  "@types/gradient-string": "^1.1.5",
60
59
  "@types/jest": "^29.5.10",
@@ -81,4 +80,4 @@
81
80
  "publishConfig": {
82
81
  "access": "public"
83
82
  }
84
- }
83
+ }
@@ -1,16 +0,0 @@
1
- import type { AnimationFN } from "./types";
2
- import { FrameRate } from "./FrameRate";
3
- export declare class Animation extends FrameRate {
4
- lines: number;
5
- text: string[];
6
- stopped: boolean;
7
- initialized: boolean;
8
- effect: AnimationFN;
9
- static readonly LINE_BREAKS: RegExp;
10
- constructor(effect: AnimationFN, str: string, delay?: number, speed?: number);
11
- render(): void;
12
- nextFrame(): string;
13
- readonly replace: (str: string) => this;
14
- readonly stop: () => this;
15
- readonly start: () => this;
16
- }
@@ -1,21 +0,0 @@
1
- import { Animation } from "./Animation";
2
- /**
3
- * Chalk Animation
4
- *
5
- * Console animations for your CLI tools
6
- *
7
- * ```typescript
8
- * const animation = ChalkAnimation.rainbow("hello!");
9
- * animation.stop();
10
- * animation.start();
11
- * ```
12
- */
13
- export declare class ChalkAnimation {
14
- static readonly neon: (str: string, speed?: number) => Animation;
15
- static readonly radar: (str: string, speed?: number) => Animation;
16
- static readonly pulse: (str: string, speed?: number) => Animation;
17
- static readonly glitch: (str: string, speed?: number) => Animation;
18
- static readonly rainbow: (str: string, speed?: number) => Animation;
19
- static readonly karaoke: (str: string, speed?: number) => Animation;
20
- private static configure;
21
- }
@@ -1,5 +0,0 @@
1
- import type { MethodKeys, MethodLike } from "./types";
2
- export declare class Decor {
3
- static bound<T, K extends MethodKeys<T>>(target: T, _propertyKey: K, descriptor: TypedPropertyDescriptor<MethodLike>): void;
4
- static chainable<I, F extends (...args: any[]) => any>(instance: I, func: F): (...params: Parameters<F>) => I;
5
- }
@@ -1,13 +0,0 @@
1
- export declare class Effects {
2
- static readonly longHsv: {
3
- interpolation: string;
4
- hsvSpin: string;
5
- };
6
- static readonly glitchChars = "x*0987654321[]0-~@#(____!!!!\\|?????....0000\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
7
- static rainbow(str: string, frame: number): string;
8
- static pulse(str: string, frame: number): string;
9
- static glitch(str: string, frame: number): string;
10
- static radar(str: string, frame: number): string;
11
- static neon(str: string, frame: number): string;
12
- static karaoke(str: string, frame: number): string;
13
- }
@@ -1,11 +0,0 @@
1
- import { InstanceTracker } from "./InstanceTracker";
2
- export declare class FrameRate extends InstanceTracker {
3
- current: number;
4
- speed: number;
5
- delay: number;
6
- controller: ReturnType<typeof setTimeout> | null;
7
- constructor(delay: number, speed: number);
8
- schedule<F extends () => any>(func: F): void;
9
- increment(): void;
10
- clearFrames(): void;
11
- }
@@ -1,15 +0,0 @@
1
- import { AutoIncrementingID } from "@figliolia/event-emitter";
2
- import type { Animation } from "./Animation";
3
- export declare class InstanceTracker {
4
- ID: string;
5
- static readonly LOG: {
6
- (...data: any[]): void;
7
- (message?: any, ...optionalParams: any[]): void;
8
- };
9
- static IDs: AutoIncrementingID;
10
- static bucket: Map<string, Animation>;
11
- static loggers: readonly ["log", "warn", "info", "error"];
12
- constructor();
13
- get instance(): Animation;
14
- static clearAll(): void;
15
- }
@@ -1,5 +0,0 @@
1
- export { ChalkAnimation } from "./ChalkAnimation";
2
- export type { Effects } from "./Effects";
3
- export type { Animation } from "./Animation";
4
- export type { InstanceTracker } from "./InstanceTracker";
5
- export * from "./types";
@@ -1,6 +0,0 @@
1
- export type AnimationFN = (str: string, frame: number) => string;
2
- export type AnimationName = "rainbow" | "pulse" | "glitch" | "radar" | "neon" | "karaoke";
3
- export type MethodLike<T = any> = (...args: any[]) => T;
4
- export type MethodKeys<T, R = any> = keyof {
5
- [K in keyof T as Required<T>[K] extends MethodLike<R> ? K : never]: T[K];
6
- };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes