write-language 0.1.94 → 0.1.95
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/README.md +3 -6
- package/dist/rewrite-modes.d.ts +10 -0
- package/dist/rewrite-modes.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/rewrite-modes.test.ts +96 -0
- package/src/rewrite-modes.ts +63 -0
package/README.md
CHANGED
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
<br />
|
|
3
3
|
<a href="https://www.npmjs.com/package/write-language"><img src="https://img.shields.io/npm/dm/write-language.svg" alt="NPM Monthly Downloads"></a>
|
|
4
4
|
<a href="https://www.npmjs.com/package/write-language"><img src="https://img.shields.io/npm/v/write-language.svg" alt="npm version"></a>
|
|
5
|
-
<a href="https://
|
|
6
|
-
<img
|
|
7
|
-
|
|
8
|
-
alt="npm bundle size "
|
|
9
|
-
/>
|
|
10
|
-
</a>
|
|
5
|
+
<a href="https://packagephobia.com/result?p=write-language" target="_blank" rel="noopener noreferrer">
|
|
6
|
+
<img src="https://packagephobia.com/badge?p=write-language" alt="install size" />
|
|
7
|
+
</a>
|
|
11
8
|
<a href="https://discord.gg/SJdBqBz3tV">
|
|
12
9
|
<img src="https://img.shields.io/discord/1110227955554209923.svg?label=Chat&logo=Discord&colorB=7289da&style=flat"
|
|
13
10
|
alt="Join Discord" />
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface RewriteMode {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
prompt: string;
|
|
5
|
+
color?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const DEFAULT_REWRITE_MODES: RewriteMode[];
|
|
8
|
+
export declare const getRewriteModes: () => RewriteMode[];
|
|
9
|
+
export declare const saveRewriteModes: (modes: RewriteMode[]) => void;
|
|
10
|
+
export declare const resetRewriteModes: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "write-language",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.95",
|
|
4
4
|
"description": "Multi-provider language generation toolkit using Vercel AI SDK - generate responses with 10+ LLM providers including OpenAI, Anthropic, Google, and more.",
|
|
5
5
|
"author": "vtempest <grokthiscontact@gmail.com>",
|
|
6
6
|
"license": "rights.institute/PROSPER",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_REWRITE_MODES,
|
|
4
|
+
getRewriteModes,
|
|
5
|
+
saveRewriteModes,
|
|
6
|
+
resetRewriteModes,
|
|
7
|
+
type RewriteMode,
|
|
8
|
+
} from './rewrite-modes'
|
|
9
|
+
|
|
10
|
+
const STORAGE_KEY = 'REASON-rewrite-modes'
|
|
11
|
+
|
|
12
|
+
// Minimal in-memory localStorage stub for the node test environment.
|
|
13
|
+
function createLocalStorageStub() {
|
|
14
|
+
const store = new Map<string, string>()
|
|
15
|
+
return {
|
|
16
|
+
getItem: vi.fn((k: string) => (store.has(k) ? store.get(k)! : null)),
|
|
17
|
+
setItem: vi.fn((k: string, v: string) => {
|
|
18
|
+
store.set(k, v)
|
|
19
|
+
}),
|
|
20
|
+
removeItem: vi.fn((k: string) => {
|
|
21
|
+
store.delete(k)
|
|
22
|
+
}),
|
|
23
|
+
clear: vi.fn(() => store.clear()),
|
|
24
|
+
_store: store,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let ls: ReturnType<typeof createLocalStorageStub>
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
ls = createLocalStorageStub()
|
|
32
|
+
vi.stubGlobal('localStorage', ls)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
vi.unstubAllGlobals()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
describe('DEFAULT_REWRITE_MODES', () => {
|
|
40
|
+
it('includes the five built-in modes with unique ids', () => {
|
|
41
|
+
const ids = DEFAULT_REWRITE_MODES.map((m) => m.id)
|
|
42
|
+
expect(ids).toEqual(['clarity', 'concise', 'summarize', 'rephrase', 'expand'])
|
|
43
|
+
expect(new Set(ids).size).toBe(ids.length)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('gives every mode a name and prompt', () => {
|
|
47
|
+
for (const mode of DEFAULT_REWRITE_MODES) {
|
|
48
|
+
expect(mode.name).toBeTruthy()
|
|
49
|
+
expect(mode.prompt.length).toBeGreaterThan(0)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('getRewriteModes', () => {
|
|
55
|
+
it('returns the defaults when nothing is stored', () => {
|
|
56
|
+
expect(getRewriteModes()).toEqual(DEFAULT_REWRITE_MODES)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('returns the stored modes when present', () => {
|
|
60
|
+
const custom: RewriteMode[] = [{ id: 'x', name: 'X', prompt: 'do x' }]
|
|
61
|
+
ls._store.set(STORAGE_KEY, JSON.stringify(custom))
|
|
62
|
+
expect(getRewriteModes()).toEqual(custom)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('falls back to defaults on malformed JSON', () => {
|
|
66
|
+
ls._store.set(STORAGE_KEY, '{not valid json')
|
|
67
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
68
|
+
expect(getRewriteModes()).toEqual(DEFAULT_REWRITE_MODES)
|
|
69
|
+
expect(spy).toHaveBeenCalled()
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('saveRewriteModes', () => {
|
|
74
|
+
it('serialises the modes to localStorage', () => {
|
|
75
|
+
const modes: RewriteMode[] = [{ id: 'y', name: 'Y', prompt: 'do y' }]
|
|
76
|
+
saveRewriteModes(modes)
|
|
77
|
+
expect(JSON.parse(ls._store.get(STORAGE_KEY)!)).toEqual(modes)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('logs but does not throw when storage rejects', () => {
|
|
81
|
+
ls.setItem.mockImplementation(() => {
|
|
82
|
+
throw new Error('quota exceeded')
|
|
83
|
+
})
|
|
84
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
85
|
+
expect(() => saveRewriteModes([])).not.toThrow()
|
|
86
|
+
expect(spy).toHaveBeenCalled()
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('resetRewriteModes', () => {
|
|
91
|
+
it('writes the defaults back to storage', () => {
|
|
92
|
+
ls._store.set(STORAGE_KEY, JSON.stringify([{ id: 'z', name: 'Z', prompt: 'z' }]))
|
|
93
|
+
resetRewriteModes()
|
|
94
|
+
expect(JSON.parse(ls._store.get(STORAGE_KEY)!)).toEqual(DEFAULT_REWRITE_MODES)
|
|
95
|
+
})
|
|
96
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface RewriteMode {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
prompt: string;
|
|
5
|
+
color?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const DEFAULT_REWRITE_MODES: RewriteMode[] = [
|
|
9
|
+
{
|
|
10
|
+
id: 'clarity',
|
|
11
|
+
name: 'Clarity',
|
|
12
|
+
prompt: 'Rewrite this paragraph for maximum clarity and straightforwardness, keeping all original meaning but removing ambiguity and simplifying complex sentences:',
|
|
13
|
+
color: 'blue',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: 'concise',
|
|
17
|
+
name: 'Concise',
|
|
18
|
+
prompt: 'Rewrite this text to be more concise, removing redundancy and filler while preserving all key points and tone. Aim for about 50% of the original length:',
|
|
19
|
+
color: 'purple',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: 'summarize',
|
|
23
|
+
name: 'Summarize',
|
|
24
|
+
prompt: 'Summarize the following text into a shorter paragraph, keeping the main ideas and overall tone but removing details and repetition:',
|
|
25
|
+
color: 'green',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'rephrase',
|
|
29
|
+
name: 'Rephrase',
|
|
30
|
+
prompt: 'Rephrase this paragraph with fresh wording and more engaging style, varying sentence structure and word choice while preserving the core message:',
|
|
31
|
+
color: 'orange',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'expand',
|
|
35
|
+
name: 'Expand',
|
|
36
|
+
prompt: 'Keep the original paragraph as-is, then expand it by adding one additional paragraph that elaborates on the main idea, gives an example, or adds helpful context for the reader:',
|
|
37
|
+
color: 'pink',
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const STORAGE_KEY = 'REASON-rewrite-modes';
|
|
42
|
+
|
|
43
|
+
export const getRewriteModes = (): RewriteMode[] => {
|
|
44
|
+
try {
|
|
45
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
46
|
+
if (stored) return JSON.parse(stored);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error('Failed to load rewrite modes:', e);
|
|
49
|
+
}
|
|
50
|
+
return DEFAULT_REWRITE_MODES;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const saveRewriteModes = (modes: RewriteMode[]): void => {
|
|
54
|
+
try {
|
|
55
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(modes));
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error('Failed to save rewrite modes:', e);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const resetRewriteModes = (): void => {
|
|
62
|
+
saveRewriteModes(DEFAULT_REWRITE_MODES);
|
|
63
|
+
};
|