Skip to content

Commit 02ac79f

Browse files
committed
feat(common): export secret utility functions
1 parent 0069af2 commit 02ac79f

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ catalogs:
1818
vitest: ^3.2.3
1919

2020
docs:
21-
'@ryanuo/utils': ^1.3.6
21+
'@ryanuo/utils': latest
2222
typedoc-vitepress-theme: ^1.1.2
2323
vitepress: ^1.6.3
2424
typedoc-plugin-markdown: ^4.6.3

src/common/secret.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @param key - The encryption key, defaults to `'ryanuo'`.
1212
* @returns The XOR-transformed string.
1313
*/
14-
function xor(str: string, key = 'ryanuo') {
14+
export function xor(str: string, key = 'ryanuo') {
1515
return Array.from(str)
1616
.map((c, i) =>
1717
String.fromCharCode(c.charCodeAt(0) ^ key.charCodeAt(i % key.length)),
@@ -31,7 +31,7 @@ function xor(str: string, key = 'ryanuo') {
3131
* @param key - Optional encryption key, defaults to `'ryanuo'`.
3232
* @returns The encrypted, URI-safe string.
3333
*/
34-
function encrypt(str: string, key?: string): string {
34+
export function encrypt(str: string, key?: string): string {
3535
return encodeURIComponent(btoa(xor(str, key)))
3636
}
3737

@@ -46,7 +46,7 @@ function encrypt(str: string, key?: string): string {
4646
* @param str - The string to compress.
4747
* @returns The compressed, Base64-encoded string.
4848
*/
49-
function compress(str: string): string {
49+
export function compress(str: string): string {
5050
const bytes = new TextEncoder().encode(str)
5151
const base64 = btoa(String.fromCharCode(...bytes))
5252
return encodeURIComponent(base64)
@@ -63,7 +63,7 @@ function compress(str: string): string {
6363
* @param str - The compressed Base64 string.
6464
* @returns The original decompressed string.
6565
*/
66-
function decompress(str: string): string {
66+
export function decompress(str: string): string {
6767
try {
6868
const decodedBase64 = decodeURIComponent(str)
6969
const binary = atob(decodedBase64)
@@ -90,7 +90,7 @@ function decompress(str: string): string {
9090
* @param key - Optional decryption key (must match the encryption key).
9191
* @returns The decrypted plain text string.
9292
*/
93-
function decrypt(str: string, key?: string): string {
93+
export function decrypt(str: string, key?: string): string {
9494
try {
9595
const decoded = atob(decodeURIComponent(str))
9696
return xor(decoded, key)
@@ -100,11 +100,3 @@ function decrypt(str: string, key?: string): string {
100100
return ''
101101
}
102102
}
103-
104-
export {
105-
xor,
106-
encrypt,
107-
decrypt,
108-
compress,
109-
decompress,
110-
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from './common/base'
55
export * from './common/is'
66
export * from './common/tools'
77
export * from './common/date'
8+
export * from './common/secret'
89

910
/**
1011
* @module browser

0 commit comments

Comments
 (0)