Skip to content

Commit cf47cdc

Browse files
committed
V3! Re wrote initCliLoader function to be cleaner and use better data structure for constant time. Returning intervalId to clear the timer.
1 parent 5ed0df6 commit cf47cdc

18 files changed

+323
-257
lines changed

CHANGELOG.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# cli-loaders
22

3+
## 3.0.0
4+
5+
### Major Changes
6+
7+
- - Full and clean re write of initCliLoader function using constant time to access objects + tree shaking.
8+
- Returning the intervalId so users can clear the loader with clearInterval(intervalId).
9+
- Updated website to reflect changes in the examples sections.
10+
- Site changes and loader updates with the current naming convention (permanent) to follow.
11+
312
## 2.3.1
413

514
### Patch Changes
@@ -10,10 +19,10 @@
1019

1120
### Minor Changes
1221

13-
- - Added new loader, 'emojis_10'.
14-
- Some loaders have been renamed to follow the naming convention, final change.
15-
- New loader, initCliLoader which takes in a loader name and optional speed and keyframes parameters for full customization.
16-
- Updated data structure for tree shaking.
22+
- Added new loader, 'emojis_10'.
23+
- Some loaders have been renamed to follow the naming convention, final change.
24+
- New loader, initCliLoader which takes in a loader name and optional speed and keyframes parameters for full customization.
25+
- Updated data structure for tree shaking.
1726

1827
## 2.2.0
1928

README.md

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,71 @@ A collection of cli loaders for your command-line applications.
66

77
Visit the [website](https://cliloaders.com) to see all loaders, copy keyframes, and more!
88

9+
## Table of Contents
10+
11+
- [Installation](#installation)
12+
- [Usage](#usage)
13+
- [Importing Loaders](#importing-loaders)
14+
- [Initializing a Loader](#initializing-a-loader)
15+
- [Customizing the Speed](#customizing-the-speed)
16+
- [Customizing Everything](#customizing-everything)
17+
- [Stopping the Loader](#stopping-the-loader)
18+
- [Available Loaders](#available-loaders)
19+
- [Performance](#performance)
20+
- [Contributing](#contributing)
21+
- [License](#license)
22+
- [Special Thanks](#special-thanks)
923

1024
## Installation
1125

1226
To install the package, use npm or yarn:
1327

1428
```bash
15-
npm install cli-loaders
29+
npm install cli-loaders;
1630
# or
17-
yarn add cli-loaders
31+
yarn add cli-loaders;
1832
# or
19-
bun install cli-loaders
33+
bun install cli-loaders;
2034
```
2135

2236
## Usage
2337

2438
### Importing Loaders
2539

26-
Import the loader initializer
40+
Import the loader initializer:
2741

2842
```typescript
29-
import { initLoader } from 'cli-loaders';
43+
import { initCliLoader } from 'cli-loaders';
3044
```
3145

3246
### Initializing a Loader
3347

34-
You can initialize any loader by its name using `initLoader`
48+
You can initialize any loader by its name using `initCliLoader`:
3549

3650
```typescript
37-
import { initLoader } from 'cli-loaders';
51+
import { initCliLoader, dots_1 } from 'cli-loaders';
3852

3953
// Initialize by name
40-
initLoader('dots_1');
54+
initCliLoader('dots_1');
55+
56+
// initCliLoader(dots_1);
4157
```
4258

4359
### Customizing the Speed
4460

4561
You can also customize the speed of the loader:
4662

4763
```typescript
48-
import { initLoader } from 'cli-loaders';
64+
import { initCliLoader, dots_1 } from 'cli-loaders';
4965

5066
// Initialize with custom speed
51-
initLoader('dots_1', 100);
67+
initCliLoader('dots_1', 150);
68+
// initCliLoader(dots_1, 150);
5269
```
5370

54-
### Customizing everything
71+
### Customizing Everything
5572

56-
New to v2.0+, you can import the cli loader initializer, `initCliLoader` for full customization
73+
New in v2.0+, you can import the cli loader initializer, `initCliLoader` for full customization:
5774

5875
```typescript
5976
import { initCliLoader, dots_14 } from 'cli-loaders';
@@ -69,9 +86,62 @@ initCliLoader(dots_14, 100); // Render loader with custom speed
6986
initCliLoader(dots_14, 100, ["","","","","","","","","",""]); // Render loader with speed and keyframes customized
7087
```
7188

72-
### Upgrading versions
89+
Or you could customize it with an object:
90+
91+
```typescript
92+
const myAwesomeLoader = {
93+
speed: 100,
94+
keyframes: ["..", "."]
95+
};
96+
97+
initCliLoader(myAwesomeLoader);
98+
```
99+
100+
### Stopping the Loader
101+
102+
To stop the loader, you can use `clearInterval` with the interval ID returned by `initCliLoader`:
103+
104+
```typescript
105+
import { initCliLoader } from 'cli-loaders';
106+
107+
const intervalId = initCliLoader('dots_1');
108+
109+
// Stop the loader after some time
110+
setTimeout(() => {
111+
clearInterval(intervalId);
112+
}, 5000);
113+
```
73114

74-
Upgrading versions can be breaking. Double check the [website](https://cliloaders.com) first, to see if a loader has moved or is following a new naming convention. The website will always be updated with the most current version of cli-loaders.
115+
## Available Loaders
116+
117+
Here are some of the available loaders you can use:
118+
119+
- `arrows_1`
120+
- `arrows_2`
121+
- `bars_1`
122+
- `bars_2`
123+
- `circles_1`
124+
- `circles_2`
125+
- `dots_1`
126+
- `dots_2`
127+
- `emojis_1`
128+
- `emojis_2`
129+
- `lines_1`
130+
- `lines_2`
131+
- `numbers_1`
132+
- `numbers_2`
133+
- `squares_1`
134+
- `squares_2`
135+
- `symbols_1`
136+
- `symbols_2`
137+
- `togglers_1`
138+
- `togglers_2`
139+
140+
For a full list of available loaders, please refer to the [source code](/src/cli-loaders.ts) or the [website](https://cliloaders.com).
141+
142+
## Performance
143+
144+
cli-loaders is, as it should be, very fast. It's tree shakable, and uses 0(1) time complexity to access the loader objects.
75145

76146
## Contributing
77147

bun.lockb

43.6 KB
Binary file not shown.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cli-loaders",
3-
"version": "2.3.1",
3+
"version": "3.0.0",
44
"author": {
55
"name": "Christian Martinez",
66
"url": "http://christianbmartinez.com"
@@ -16,6 +16,9 @@
1616
"@changesets/cli": "^2.27.11",
1717
"@types/bun": "^1.1.14",
1818
"@types/node": "^22.10.5",
19+
"babel-plugin-react-compiler": "^19.0.0-beta-27714ef-20250124",
20+
"eslint-plugin-react-compiler": "^19.0.0-beta-27714ef-20250124",
21+
"prettier": "^3.4.2",
1922
"tsup": "^8.3.5",
2023
"typescript": "^5.7.2"
2124
},
@@ -51,7 +54,8 @@
5154
"start": "node dist/index.js",
5255
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
5356
"build": "tsup src/index.ts --format cjs,esm --dts --minify",
54-
"lint": "tsc"
57+
"lint": "tsc",
58+
"test": "bun test test/init-cli-loader.test.ts --watch"
5559
},
5660
"type": "module"
5761
}

src/cli-loaders.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,7 @@ export const togglers_14 = {
481481
keyframes: ['❂', '✪'],
482482
};
483483

484-
type CliLoadersProps = {
485-
[key: string]: {
486-
speed: number;
487-
keyframes: string[];
488-
}
489-
};
490-
491-
const cliLoaders: CliLoadersProps = {
484+
const cliLoaders = {
492485
arrows_1,
493486
arrows_2,
494487
arrows_3,

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './cli-loaders';
22
export { default as cliLoaders } from './cli-loaders';
3-
export { default as initCliLoader } from './init-cli-loader';
4-
export { default as initLoader } from './init-loader';
3+
export { default as initLoader } from './init-cli-loader';
54

0 commit comments

Comments
 (0)