format-prompt 1.0.0
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 +21 -0
- package/README.md +90 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Khánh Hoàng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# format-prompt! [](https://www.npmjs.com/package/format-prompt) [](https://jsr.io/@hckhanh/format-prompt)
|
|
2
|
+
|
|
3
|
+
A utility to format prompts for a cleaner presentation and optimal token usage. Removes unused spaces and line breaks, and supports template literals.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/hckhanh/format-prompt/actions/workflows/test.yml)
|
|
6
|
+
[](https://codecov.io/github/hckhanh/format-prompt)
|
|
7
|
+
[](https://sonarcloud.io/summary/new_code?id=hckhanh_format-prompt)
|
|
8
|
+
[](https://bundlephobia.com/result?p=format-prompt)
|
|
9
|
+
[](https://codspeed.io/hckhanh/format-prompt?utm_source=badge)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Using npm
|
|
15
|
+
npm install format-prompt
|
|
16
|
+
|
|
17
|
+
# Using bun
|
|
18
|
+
bun add format-prompt
|
|
19
|
+
|
|
20
|
+
# Using JSR (recommended for Deno)
|
|
21
|
+
deno add jsr:@hckhanh/format-prompt
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
It can convert a prompt from:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
You are a security guard that analyze the given email for spam/scam/toxicity/business relevance:
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Score each category and provide recommendation. Focus on:
|
|
37
|
+
* Spam: unsolicited bulk/promotional content
|
|
38
|
+
* Scam: phishing, fraud, identity theft attempts
|
|
39
|
+
* Toxicity: hate speech, threats, harassment
|
|
40
|
+
* Business relevance: legitimate business inquiries, job opportunities
|
|
41
|
+
* Suspicious patterns: urgent language, poor grammar, suspicious URLs, sensitive info requests
|
|
42
|
+
* Advertisement: explicit promotional content, product/service offers, marketing campaigns
|
|
43
|
+
|
|
44
|
+
If you are not sure about any links, emails or any information, use tools.
|
|
45
|
+
|
|
46
|
+
${encode({ demo: 1, array: [1, 2, 3], nested: { a: 'b' } })}
|
|
47
|
+
|
|
48
|
+
If you are not sure about any links, emails or any information, use tools.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
${encode({ demo: 1, array: [1, 2, 3], nested: { a: 'b' } })}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
into this:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
You are a security guard that analyze the given email for spam/scam/toxicity/business relevance:
|
|
64
|
+
|
|
65
|
+
Score each category and provide recommendation. Focus on:
|
|
66
|
+
* Spam: unsolicited bulk/promotional content
|
|
67
|
+
* Scam: phishing, fraud, identity theft attempts
|
|
68
|
+
* Toxicity: hate speech, threats, harassment
|
|
69
|
+
* Business relevance: legitimate business inquiries, job opportunities
|
|
70
|
+
* Suspicious patterns: urgent language, poor grammar, suspicious URLs, sensitive info requests
|
|
71
|
+
* Advertisement: explicit promotional content, product/service offers, marketing campaigns
|
|
72
|
+
|
|
73
|
+
If you are not sure about any links, emails or any information, use tools.
|
|
74
|
+
|
|
75
|
+
demo: 1
|
|
76
|
+
array[3]: 1,2,3
|
|
77
|
+
nested:
|
|
78
|
+
a: b
|
|
79
|
+
|
|
80
|
+
If you are not sure about any links, emails or any information, use tools.
|
|
81
|
+
|
|
82
|
+
demo: 1
|
|
83
|
+
array[3]: 1,2,3
|
|
84
|
+
nested:
|
|
85
|
+
a: b
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
It will allow you to have a prettier prompt in your code without worrying about extra spaces or line breaks affecting the prompt quality.
|
|
89
|
+
|
|
90
|
+

|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "format-prompt",
|
|
3
|
+
"description": "A utility to format prompts for a cleaner presentation and optimal token usage",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Khánh Hoàng",
|
|
7
|
+
"email": "hi@khanh.id",
|
|
8
|
+
"url": "https://www.khanh.id"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/hckhanh/format-prompt",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/hckhanh/format-prompt.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/hckhanh/format-prompt/issues",
|
|
17
|
+
"email": "hi@khanh.id"
|
|
18
|
+
},
|
|
19
|
+
"private": false,
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/index.js",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"bench": "vitest bench",
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"format": "biome check --write",
|
|
36
|
+
"release": "bun run build && changeset publish",
|
|
37
|
+
"test": "vitest"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"string-collapse-leading-whitespace": "^7.1.0",
|
|
41
|
+
"string-collapse-white-space": "^11.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@biomejs/biome": "2.3.10",
|
|
45
|
+
"@changesets/cli": "2.29.8",
|
|
46
|
+
"@changesets/config": "3.1.2",
|
|
47
|
+
"@codspeed/vitest-plugin": "5.0.1",
|
|
48
|
+
"@toon-format/toon": "2.1.0",
|
|
49
|
+
"@types/bun": "1.3.5",
|
|
50
|
+
"@types/node": "24.10.4",
|
|
51
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
52
|
+
"knip": "5.71.0",
|
|
53
|
+
"syncpack": "14.0.0-alpha.32",
|
|
54
|
+
"tsdown": "0.18.2",
|
|
55
|
+
"typescript": "5.9.3",
|
|
56
|
+
"vitest": "3.2.4"
|
|
57
|
+
},
|
|
58
|
+
"workspaces": [
|
|
59
|
+
".",
|
|
60
|
+
"docs"
|
|
61
|
+
],
|
|
62
|
+
"files": [
|
|
63
|
+
"dist"
|
|
64
|
+
],
|
|
65
|
+
"keywords": [
|
|
66
|
+
"prompt",
|
|
67
|
+
"format",
|
|
68
|
+
"llm",
|
|
69
|
+
"ai",
|
|
70
|
+
"template",
|
|
71
|
+
"string",
|
|
72
|
+
"whitespace",
|
|
73
|
+
"typescript"
|
|
74
|
+
],
|
|
75
|
+
"license": "MIT"
|
|
76
|
+
}
|