jotjot 0.1.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 +57 -0
- package/dist/bin/app.js +235 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Maze Heart
|
|
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,57 @@
|
|
|
1
|
+
# JotJot
|
|
2
|
+
|
|
3
|
+
A minimal CLI for quickly jotting down notes.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Requires Node.js 20 or later and pnpm.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm install
|
|
11
|
+
pnpm build
|
|
12
|
+
pnpm link --global
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Create a note:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
jot "This is a test"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
List notes, newest first:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
jot list
|
|
27
|
+
jot ls
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Fuzzy-search notes:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
jot find "test"
|
|
34
|
+
jot f "test"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Edit a note:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
jot edit <id>
|
|
41
|
+
jot edit <id> "Updated text"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Remove a note:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
jot remove <id>
|
|
48
|
+
jot rm <id>
|
|
49
|
+
jot rm <id> --force
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
IDs can be shortened to any unique prefix. If a prefix matches multiple notes,
|
|
53
|
+
JotJot asks you to choose one.
|
|
54
|
+
|
|
55
|
+
## Storage
|
|
56
|
+
|
|
57
|
+
Notes are stored locally as JSON in `~/.jotjot/db.json`.
|
package/dist/bin/app.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// bin/app.ts
|
|
4
|
+
import chalk2 from "chalk";
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
import { confirm, input, select } from "@inquirer/prompts";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import { Command } from "commander";
|
|
10
|
+
import Fuse from "fuse.js";
|
|
11
|
+
import { nanoid } from "nanoid";
|
|
12
|
+
|
|
13
|
+
// package.json
|
|
14
|
+
var package_default = {
|
|
15
|
+
name: "jotjot",
|
|
16
|
+
version: "0.1.0",
|
|
17
|
+
type: "module",
|
|
18
|
+
bin: {
|
|
19
|
+
jot: "dist/bin/app.js"
|
|
20
|
+
},
|
|
21
|
+
main: "dist/bin/app.js",
|
|
22
|
+
files: [
|
|
23
|
+
"dist",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
repository: {
|
|
28
|
+
type: "git",
|
|
29
|
+
url: "git+https://github.com/remvze/jotjot.git"
|
|
30
|
+
},
|
|
31
|
+
homepage: "https://github.com/remvze/jotjot#readme",
|
|
32
|
+
bugs: {
|
|
33
|
+
url: "https://github.com/remvze/jotjot/issues"
|
|
34
|
+
},
|
|
35
|
+
engines: {
|
|
36
|
+
node: ">=20"
|
|
37
|
+
},
|
|
38
|
+
publishConfig: {
|
|
39
|
+
access: "public"
|
|
40
|
+
},
|
|
41
|
+
scripts: {
|
|
42
|
+
lint: "biome check .",
|
|
43
|
+
"lint:fix": "biome lint --write .",
|
|
44
|
+
format: "biome format --write .",
|
|
45
|
+
prepare: "husky",
|
|
46
|
+
commit: "git-cz",
|
|
47
|
+
release: "standard-version --no-verify",
|
|
48
|
+
"release:major": "pnpm run release --release-as major",
|
|
49
|
+
"release:minor": "pnpm run release --release-as minor",
|
|
50
|
+
"release:patch": "pnpm run release --release-as patch",
|
|
51
|
+
build: "tsup-node",
|
|
52
|
+
dev: "tsup-node --watch",
|
|
53
|
+
prepublishOnly: "npm run build"
|
|
54
|
+
},
|
|
55
|
+
keywords: [
|
|
56
|
+
"cli",
|
|
57
|
+
"notes",
|
|
58
|
+
"note-taking",
|
|
59
|
+
"jot",
|
|
60
|
+
"terminal",
|
|
61
|
+
"productivity"
|
|
62
|
+
],
|
|
63
|
+
author: "Maze",
|
|
64
|
+
license: "MIT",
|
|
65
|
+
description: "A minimal CLI for quickly jotting down notes.",
|
|
66
|
+
devDependencies: {
|
|
67
|
+
"@biomejs/biome": "2.0.6",
|
|
68
|
+
"@commitlint/cli": "19.8.1",
|
|
69
|
+
"@commitlint/config-conventional": "19.8.1",
|
|
70
|
+
"@tsconfig/node20": "^20.1.6",
|
|
71
|
+
"@types/node": "^24.0.10",
|
|
72
|
+
commitizen: "4.3.1",
|
|
73
|
+
"cz-conventional-changelog": "3.3.0",
|
|
74
|
+
husky: "9.1.7",
|
|
75
|
+
"lint-staged": "16.1.2",
|
|
76
|
+
"standard-version": "9.5.0",
|
|
77
|
+
tsup: "8.5.0"
|
|
78
|
+
},
|
|
79
|
+
dependencies: {
|
|
80
|
+
"@inquirer/prompts": "8.7.2",
|
|
81
|
+
chalk: "6.0.0",
|
|
82
|
+
commander: "14.0.0",
|
|
83
|
+
"fuse.js": "7.5.0",
|
|
84
|
+
lowdb: "7.0.1",
|
|
85
|
+
nanoid: "6.0.1"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/store.ts
|
|
90
|
+
import { mkdir } from "fs/promises";
|
|
91
|
+
import { homedir } from "os";
|
|
92
|
+
import { dirname, join } from "path";
|
|
93
|
+
import { JSONFilePreset } from "lowdb/node";
|
|
94
|
+
async function createStore() {
|
|
95
|
+
const path = process.env.JOTJOT_DATA_FILE ?? join(homedir(), ".jotjot", "db.json");
|
|
96
|
+
await mkdir(dirname(path), { recursive: true });
|
|
97
|
+
return JSONFilePreset(path, { notes: [] });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/index.ts
|
|
101
|
+
var ID_LENGTH = 8;
|
|
102
|
+
function relativeTime(timestamp) {
|
|
103
|
+
const elapsed = Date.now() - new Date(timestamp).getTime();
|
|
104
|
+
const future = elapsed < 0;
|
|
105
|
+
const seconds = Math.round(Math.abs(elapsed) / 1e3);
|
|
106
|
+
if (seconds < 10) return "just now";
|
|
107
|
+
const units = [
|
|
108
|
+
["year", 60 * 60 * 24 * 365],
|
|
109
|
+
["month", 60 * 60 * 24 * 30],
|
|
110
|
+
["week", 60 * 60 * 24 * 7],
|
|
111
|
+
["day", 60 * 60 * 24],
|
|
112
|
+
["hour", 60 * 60],
|
|
113
|
+
["minute", 60],
|
|
114
|
+
["second", 1]
|
|
115
|
+
];
|
|
116
|
+
const formatter = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
|
|
117
|
+
for (const [unit, size] of units) {
|
|
118
|
+
if (seconds >= size) {
|
|
119
|
+
return formatter.format(
|
|
120
|
+
Math.round(seconds / size) * (future ? 1 : -1),
|
|
121
|
+
unit
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return "just now";
|
|
126
|
+
}
|
|
127
|
+
function printNotes(notes) {
|
|
128
|
+
if (notes.length === 0) {
|
|
129
|
+
console.log(chalk.yellow("No notes found."));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const timeWidth = Math.max(
|
|
133
|
+
...notes.map((note) => relativeTime(note.createdAt).length)
|
|
134
|
+
);
|
|
135
|
+
for (const note of notes) {
|
|
136
|
+
console.log(
|
|
137
|
+
`${chalk.cyan(note.id)} ${chalk.dim(relativeTime(note.createdAt).padEnd(timeWidth))} ${note.text}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function textFrom(words) {
|
|
142
|
+
return words.join(" ").trim();
|
|
143
|
+
}
|
|
144
|
+
function noteLabel(note) {
|
|
145
|
+
const text = note.text.length > 60 ? `${note.text.slice(0, 57)}...` : note.text;
|
|
146
|
+
return `${chalk.cyan(note.id)} ${text}`;
|
|
147
|
+
}
|
|
148
|
+
async function resolveNote(notes, idPrefix) {
|
|
149
|
+
const exact = notes.find((note) => note.id === idPrefix);
|
|
150
|
+
if (exact) return exact;
|
|
151
|
+
const matches = notes.filter((note) => note.id.startsWith(idPrefix));
|
|
152
|
+
if (matches.length === 0) throw new Error(`Note ${idPrefix} was not found.`);
|
|
153
|
+
if (matches.length === 1) return matches[0];
|
|
154
|
+
return select({
|
|
155
|
+
message: `Multiple notes match \u201C${idPrefix}\u201D. Choose one:`,
|
|
156
|
+
choices: matches.map((note) => ({ name: noteLabel(note), value: note }))
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
var program = new Command();
|
|
160
|
+
program.name("jot").description("Jot down a thought, fast.").version(package_default.version).showHelpAfterError();
|
|
161
|
+
program.command("list").alias("ls").description("List notes, newest first").action(async () => {
|
|
162
|
+
const store = await createStore();
|
|
163
|
+
printNotes(
|
|
164
|
+
[...store.data.notes].sort(
|
|
165
|
+
(a, b) => b.createdAt.localeCompare(a.createdAt)
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
program.command("find").alias("f").description("Fuzzy-search notes").argument("<query...>", "words to find").action(async (query) => {
|
|
170
|
+
const store = await createStore();
|
|
171
|
+
const fuse = new Fuse(store.data.notes, {
|
|
172
|
+
keys: ["text"],
|
|
173
|
+
threshold: 0.5,
|
|
174
|
+
ignoreLocation: true
|
|
175
|
+
});
|
|
176
|
+
printNotes(fuse.search(textFrom(query)).map((result) => result.item));
|
|
177
|
+
});
|
|
178
|
+
program.command("edit").description("Edit a note").argument("<id>", "note ID").argument("[text...]", "replacement text").action(async (id, words) => {
|
|
179
|
+
const store = await createStore();
|
|
180
|
+
const note = await resolveNote(store.data.notes, id);
|
|
181
|
+
const suppliedText = textFrom(words);
|
|
182
|
+
const text = suppliedText || await input({ message: "Note:", default: note.text });
|
|
183
|
+
if (!text.trim()) throw new Error("A note cannot be empty.");
|
|
184
|
+
note.text = text.trim();
|
|
185
|
+
note.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
186
|
+
await store.write();
|
|
187
|
+
console.log(
|
|
188
|
+
`${chalk.green("Updated")} ${chalk.dim("\xB7")} ${chalk.cyan(note.id)}`
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
program.command("remove").alias("rm").description("Remove a note").argument("<id>", "note ID").option("-f, --force", "skip confirmation").action(async (id, options) => {
|
|
192
|
+
const store = await createStore();
|
|
193
|
+
const note = await resolveNote(store.data.notes, id);
|
|
194
|
+
if (!options.force) {
|
|
195
|
+
const approved = await confirm({
|
|
196
|
+
message: `Remove \u201C${note.text}\u201D?`
|
|
197
|
+
});
|
|
198
|
+
if (!approved) {
|
|
199
|
+
console.log(chalk.yellow("Kept."));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
store.data.notes.splice(store.data.notes.indexOf(note), 1);
|
|
204
|
+
await store.write();
|
|
205
|
+
console.log(
|
|
206
|
+
`${chalk.green("Removed")} ${chalk.dim("\xB7")} ${chalk.cyan(note.id)}`
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
program.argument("[text...]", "note to create").action(async (words) => {
|
|
210
|
+
const text = textFrom(words);
|
|
211
|
+
if (!text) {
|
|
212
|
+
program.help();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const store = await createStore();
|
|
216
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
217
|
+
const note = {
|
|
218
|
+
id: nanoid(ID_LENGTH),
|
|
219
|
+
text,
|
|
220
|
+
createdAt: now,
|
|
221
|
+
updatedAt: now
|
|
222
|
+
};
|
|
223
|
+
store.data.notes.push(note);
|
|
224
|
+
await store.write();
|
|
225
|
+
console.log(
|
|
226
|
+
`${chalk.green("Jotted")} ${chalk.dim("\xB7")} ${chalk.cyan(note.id)}`
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// bin/app.ts
|
|
231
|
+
program.parseAsync(process.argv).catch((error) => {
|
|
232
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
233
|
+
console.error(chalk2.red(message));
|
|
234
|
+
process.exitCode = 1;
|
|
235
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jotjot",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"jot": "dist/bin/app.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/bin/app.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/remvze/jotjot.git"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/remvze/jotjot#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/remvze/jotjot/issues"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"lint": "biome check .",
|
|
30
|
+
"lint:fix": "biome lint --write .",
|
|
31
|
+
"format": "biome format --write .",
|
|
32
|
+
"prepare": "husky",
|
|
33
|
+
"commit": "git-cz",
|
|
34
|
+
"release": "standard-version --no-verify",
|
|
35
|
+
"release:major": "pnpm run release --release-as major",
|
|
36
|
+
"release:minor": "pnpm run release --release-as minor",
|
|
37
|
+
"release:patch": "pnpm run release --release-as patch",
|
|
38
|
+
"build": "tsup-node",
|
|
39
|
+
"dev": "tsup-node --watch",
|
|
40
|
+
"prepublishOnly": "npm run build"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"cli",
|
|
44
|
+
"notes",
|
|
45
|
+
"note-taking",
|
|
46
|
+
"jot",
|
|
47
|
+
"terminal",
|
|
48
|
+
"productivity"
|
|
49
|
+
],
|
|
50
|
+
"author": "Maze",
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"description": "A minimal CLI for quickly jotting down notes.",
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@biomejs/biome": "2.0.6",
|
|
55
|
+
"@commitlint/cli": "19.8.1",
|
|
56
|
+
"@commitlint/config-conventional": "19.8.1",
|
|
57
|
+
"@tsconfig/node20": "^20.1.6",
|
|
58
|
+
"@types/node": "^24.0.10",
|
|
59
|
+
"commitizen": "4.3.1",
|
|
60
|
+
"cz-conventional-changelog": "3.3.0",
|
|
61
|
+
"husky": "9.1.7",
|
|
62
|
+
"lint-staged": "16.1.2",
|
|
63
|
+
"standard-version": "9.5.0",
|
|
64
|
+
"tsup": "8.5.0"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"@inquirer/prompts": "8.7.2",
|
|
68
|
+
"chalk": "6.0.0",
|
|
69
|
+
"commander": "14.0.0",
|
|
70
|
+
"fuse.js": "7.5.0",
|
|
71
|
+
"lowdb": "7.0.1",
|
|
72
|
+
"nanoid": "6.0.1"
|
|
73
|
+
}
|
|
74
|
+
}
|