strc 1.1.0 → 2.0.0-test
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.
- package/LICENSE +1 -1
- package/README.md +92 -22
- package/index.d.ts +57 -6
- package/index.js +794 -160
- package/index.min.js +38 -0
- package/package.json +29 -8
- package/test/index.js +97 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025 JustDeveloper <https://justdeveloper.is-a.dev/>
|
|
3
|
+
Copyright (c) 2025-2026 JustDeveloper <https://justdeveloper.is-a.dev/>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
# JSSC — JavaScript String Compressor
|
|
2
|
+
**JSSC (JavaScript String Compressor)** is an open-source, lossless **string compression algorithm** designed specifically for JavaScript.
|
|
3
|
+
|
|
4
|
+
It operates directly on JavaScript strings (UTF-16) and produces compressed data that is also a valid JavaScript string.
|
|
5
|
+
|
|
6
|
+
JSSC is distributed as a **UMD module** and can be used in browsers, Node.js, Deno, and other JavaScript environments.
|
|
7
|
+
|
|
8
|
+
## Key Features
|
|
9
|
+
- ✨ **Lossless compression**
|
|
10
|
+
- 🗜️ **High compression ratios**
|
|
11
|
+
- up to **8:1** for numeric data
|
|
12
|
+
- strong results for repetitive and structured text
|
|
13
|
+
- 🌍 **Multilingual support**
|
|
14
|
+
- English, Russian, Japanese, Chinese, Hindi, Bengali, and more
|
|
15
|
+
- 📦 **JSON support**
|
|
16
|
+
- JSON is converted to [JUSTC](https://just.js.org/justc) before compression
|
|
17
|
+
- ⚙️ **String → String**
|
|
18
|
+
- no binary buffers
|
|
19
|
+
- no external metadata
|
|
20
|
+
- all required information is embedded into the compressed string itself
|
|
21
|
+
- 🧠 **Self-validating compression**
|
|
22
|
+
- every compression mode is verified by decompression before being accepted
|
|
23
|
+
- 🔁 **Recursive optimization mode**
|
|
24
|
+
- optional multi-pass compression (mode 31)
|
|
25
|
+
- 📜 TypeScript definitions included
|
|
26
|
+
- 🌐 **UMD build** for browsers and static websites
|
|
27
|
+
|
|
28
|
+
## Important Version Compatibility Notice
|
|
29
|
+
⚠️ **Compressed strings produced by JSSC v1.x.x are NOT compatible with v2.x.x**
|
|
30
|
+
|
|
31
|
+
Reasons:
|
|
32
|
+
- The first 16 bits (header layout) were slightly redesigned
|
|
33
|
+
- New compression modes were added
|
|
34
|
+
- Character encoding tables were extended
|
|
35
|
+
|
|
36
|
+
## Character Encoding
|
|
37
|
+
JSSC operates on **JavaScript UTF-16 code units**, not on UTF-8 bytes.
|
|
38
|
+
|
|
39
|
+
This means:
|
|
40
|
+
- Any character representable in a JavaScript string is supported
|
|
41
|
+
- Compression works at the UTF-16 level
|
|
42
|
+
- One JavaScript character = **16 bits**
|
|
43
|
+
- Binary data must be converted to strings before compression
|
|
44
|
+
|
|
45
|
+
## Project Name vs npm Package Name
|
|
46
|
+
The project is called **JSSC** (JavaScript String Compressor).
|
|
47
|
+
|
|
48
|
+
The npm package is published under the name **`strc`**, because the name `jssc` is already occupied on npm by an unrelated Java-based package.
|
|
49
|
+
|
|
50
|
+
Both names refer to the same project.
|
|
8
51
|
|
|
9
52
|
## Installation
|
|
10
53
|
Install via npm
|
|
@@ -12,9 +55,12 @@ Install via npm
|
|
|
12
55
|
npm i strc
|
|
13
56
|
```
|
|
14
57
|
|
|
15
|
-
|
|
58
|
+
> The npm package name is `strc`, but the library itself is **JSSC**.
|
|
59
|
+
|
|
60
|
+
Or you can use it on your website by inserting the following HTML `script` tags.
|
|
16
61
|
```html
|
|
17
|
-
<script
|
|
62
|
+
<script src="https://unpkg.com/justc"></script>
|
|
63
|
+
<script src="https://unpkg.com/strc"></script>
|
|
18
64
|
```
|
|
19
65
|
|
|
20
66
|
## Usage
|
|
@@ -22,33 +68,57 @@ Or you can use it on your website by inserting the following HTML `script` tag.
|
|
|
22
68
|
```js
|
|
23
69
|
const { compress, decompress } = require('strc');
|
|
24
70
|
|
|
25
|
-
const example = compress("Hello, world!");
|
|
26
|
-
decompress(example);
|
|
71
|
+
const example = await compress("Hello, world!");
|
|
72
|
+
await decompress(example);
|
|
27
73
|
```
|
|
28
74
|
|
|
29
75
|
#### TypeScript
|
|
30
76
|
```ts
|
|
31
77
|
import { compress, decompress } from 'strc';
|
|
32
78
|
|
|
33
|
-
const example = compress("Hello, world!");
|
|
34
|
-
decompress(example);
|
|
79
|
+
const example = await compress("Hello, world!");
|
|
80
|
+
await decompress(example);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Deno (server-side)
|
|
84
|
+
```ts
|
|
85
|
+
import JSSC from 'https://jssc.js.org/script.js';
|
|
86
|
+
|
|
87
|
+
const example = await JSSC.compress("Hello, world!");
|
|
88
|
+
await JSSC.decompress(example);
|
|
35
89
|
```
|
|
36
90
|
|
|
37
|
-
#### Browsers/Frontend (
|
|
91
|
+
#### Browsers / Frontend (UMD)
|
|
92
|
+
When using the UMD build via CDN, the library is exposed globally as `JSSC`.
|
|
38
93
|
```html
|
|
39
|
-
<script
|
|
94
|
+
<script src="https://unpkg.com/justc"></script>
|
|
95
|
+
<script src="https://unpkg.com/strc"></script>
|
|
40
96
|
```
|
|
41
97
|
```js
|
|
42
|
-
const compressed = JSSC.compress("Hello, world!");
|
|
43
|
-
const decompressed = JSSC.decompress(compressed);
|
|
98
|
+
const compressed = await JSSC.compress("Hello, world!");
|
|
99
|
+
const decompressed = await JSSC.decompress(compressed);
|
|
44
100
|
```
|
|
45
101
|
|
|
46
102
|
## API
|
|
47
|
-
#### `compress(
|
|
48
|
-
Compresses
|
|
103
|
+
#### `compress(input: string | object | number): Promise<string>`
|
|
104
|
+
Compresses the input and returns a compressed JavaScript string.
|
|
49
105
|
|
|
50
|
-
#### `decompress(
|
|
51
|
-
Decompresses a previously compressed string.
|
|
106
|
+
#### `decompress(input: string, stringify?: boolean): Promise<string | object | number>`
|
|
107
|
+
Decompresses a previously compressed string/object/integer.
|
|
108
|
+
|
|
109
|
+
## Dependencies
|
|
110
|
+
JSSC depends on:
|
|
111
|
+
- <img align="top" src="https://just.js.org/justc/logo-50.svg" alt="JUSTC Logo" width="26" height="26"> [JUSTC](https://just.js.org/justc) by [JustStudio.](https://juststudio.is-a.dev/)
|
|
52
112
|
|
|
53
113
|
## License
|
|
54
|
-
[MIT © 2025 JustDeveloper](https://github.com/JustDeveloper1/JSSC/blob/main/LICENSE)
|
|
114
|
+
[MIT © 2025-2026 JustDeveloper](https://github.com/JustDeveloper1/JSSC/blob/main/LICENSE)
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
## Minified Build
|
|
118
|
+
For `.min.js`, I use [UglifyJS](https://github.com/mishoo/UglifyJS) by [Mihai Bazon](https://github.com/mishoo).
|
|
119
|
+
```bash
|
|
120
|
+
npm i uglify-js
|
|
121
|
+
```
|
|
122
|
+
```bash
|
|
123
|
+
uglifyjs index.js -c -m "reserved=['compress','decompress']" -o index.min.js
|
|
124
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
MIT License
|
|
4
4
|
|
|
5
|
-
Copyright (c) 2025 JustDeveloper <https://justdeveloper.is-a.dev/>
|
|
5
|
+
Copyright (c) 2025-2026 JustDeveloper <https://justdeveloper.is-a.dev/>
|
|
6
6
|
|
|
7
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
8
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -35,30 +35,81 @@ SOFTWARE.
|
|
|
35
35
|
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* JavaScript String Compressor - compress options
|
|
40
|
+
* @license MIT
|
|
41
|
+
* @copyright (c) 2025-2026 JustDeveloper <<https://justdeveloper.is-a.dev>>
|
|
42
|
+
* @since 2.0.0
|
|
43
|
+
*/
|
|
44
|
+
export interface compressOptions {
|
|
45
|
+
JUSTC?: boolean,
|
|
46
|
+
recursiveCompression?: boolean,
|
|
47
|
+
segmentation?: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
38
50
|
/**
|
|
39
51
|
* JavaScript String Compressor - compress function
|
|
40
52
|
* @param str - Input string to compress
|
|
41
53
|
* @returns Compressed string
|
|
42
54
|
* @example
|
|
43
|
-
* compress('Hello, World!');
|
|
55
|
+
* await compress('Hello, World!');
|
|
44
56
|
* @since 1.0.0
|
|
45
57
|
*/
|
|
46
|
-
export function compress(str: string): string
|
|
58
|
+
export function compress(str: string, options?: compressOptions): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* JavaScript String Compressor - compress function
|
|
61
|
+
* @param obj - Input object to compress
|
|
62
|
+
* > **Note: it will `JSON.stringify()` your object so it may lose some data if your object has getters/setters/non-enumerables/etc.!**
|
|
63
|
+
* @returns Compressed string
|
|
64
|
+
* @example
|
|
65
|
+
* await compress({a: "b"});
|
|
66
|
+
* @since 2.0.0
|
|
67
|
+
*/
|
|
68
|
+
export function compress(obj: object, options?: compressOptions): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* JavaScript String Compressor - compress function
|
|
71
|
+
* @param int - Input integer to compress
|
|
72
|
+
* @returns Compressed string
|
|
73
|
+
* @example
|
|
74
|
+
* await compress(10);
|
|
75
|
+
* @since 2.0.0
|
|
76
|
+
*/
|
|
77
|
+
export function compress(int: number, options?: compressOptions): Promise<string>;
|
|
47
78
|
|
|
48
79
|
/**
|
|
49
80
|
* JavaScript String Compressor - decompress function
|
|
50
81
|
* @param str - Compressed string to decompress
|
|
51
82
|
* @returns Decompressed string
|
|
52
83
|
* @example
|
|
53
|
-
* decompress(compressedString);
|
|
84
|
+
* await decompress(compressedString);
|
|
54
85
|
* @since 1.0.0
|
|
55
86
|
*/
|
|
56
|
-
export function decompress(str: string): string
|
|
87
|
+
export function decompress(str: string): Promise<string>;
|
|
88
|
+
/**
|
|
89
|
+
* JavaScript String Compressor - decompress function
|
|
90
|
+
* @param str - Compressed object to decompress
|
|
91
|
+
* @param stringify - Always return string? (`JSON.stringify()` object outputs)
|
|
92
|
+
* @returns Decompressed string
|
|
93
|
+
* @example
|
|
94
|
+
* await decompress(compressedString);
|
|
95
|
+
* @since 2.0.0
|
|
96
|
+
*/
|
|
97
|
+
export function decompress(str: string, stringify?: boolean): Promise<object|string>;
|
|
98
|
+
/**
|
|
99
|
+
* JavaScript String Compressor - decompress function
|
|
100
|
+
* @param str - Compressed object to decompress
|
|
101
|
+
* @param stringify - Always return string? (`.toString()` integer outputs)
|
|
102
|
+
* @returns Decompressed string
|
|
103
|
+
* @example
|
|
104
|
+
* await decompress(compressedString);
|
|
105
|
+
* @since 2.0.0
|
|
106
|
+
*/
|
|
107
|
+
export function decompress(str: string, stringify?: boolean): Promise<number|string>;
|
|
57
108
|
|
|
58
109
|
/**
|
|
59
110
|
* JavaScript String Compressor
|
|
60
111
|
* @license MIT
|
|
61
|
-
* @copyright (c) 2025 JustDeveloper <<https://justdeveloper.is-a.dev>>
|
|
112
|
+
* @copyright (c) 2025-2026 JustDeveloper <<https://justdeveloper.is-a.dev>>
|
|
62
113
|
* @since 1.0.0
|
|
63
114
|
*/
|
|
64
115
|
declare const JSSC: {
|