reslop 0.0.1 → 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/CHANGELOG.md +11 -3
- package/LICENSE +1 -1
- package/README.md +83 -3
- package/bin/reslop.js +23 -0
- package/lib/ansi.js +231 -0
- package/lib/api.js +32 -0
- package/lib/cli.js +181 -0
- package/lib/clipboard.js +42 -0
- package/lib/detect.js +84 -0
- package/lib/diff.js +906 -0
- package/lib/editor.js +148 -0
- package/lib/files.js +47 -0
- package/lib/git.js +261 -0
- package/lib/highlight.js +1234 -0
- package/lib/keys.js +208 -0
- package/lib/render.js +964 -0
- package/lib/review.js +687 -0
- package/lib/select.js +218 -0
- package/lib/session.js +1416 -0
- package/lib/wrap.js +118 -0
- package/package.json +33 -22
- package/.editorconfig +0 -12
- package/.gitattributes +0 -1
- package/.prettierignore +0 -2
- package/AUTHORS +0 -1
- package/CONTRIBUTING.md +0 -41
- package/SECURITY.md +0 -16
- package/eslint.config.js +0 -5
- package/main.js +0 -3
- package/prettier.config.js +0 -10
- package/tsconfig.json +0 -11
package/lib/detect.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
const LANG = {
|
|
6
|
+
md: 'md',
|
|
7
|
+
markdown: 'md',
|
|
8
|
+
js: 'js',
|
|
9
|
+
javascript: 'js',
|
|
10
|
+
mjs: 'mjs',
|
|
11
|
+
cjs: 'js',
|
|
12
|
+
ts: 'ts',
|
|
13
|
+
typescript: 'ts',
|
|
14
|
+
json: 'json',
|
|
15
|
+
csv: 'csv',
|
|
16
|
+
html: 'html',
|
|
17
|
+
htm: 'html',
|
|
18
|
+
css: 'css',
|
|
19
|
+
sh: 'bash',
|
|
20
|
+
bash: 'bash',
|
|
21
|
+
shell: 'bash',
|
|
22
|
+
zsh: 'bash',
|
|
23
|
+
txt: 'txt',
|
|
24
|
+
text: 'txt',
|
|
25
|
+
plain: 'txt',
|
|
26
|
+
log: 'log',
|
|
27
|
+
env: 'dot',
|
|
28
|
+
ini: 'dot',
|
|
29
|
+
conf: 'dot',
|
|
30
|
+
cfg: 'dot',
|
|
31
|
+
yaml: 'dot',
|
|
32
|
+
yml: 'dot',
|
|
33
|
+
toml: 'dot',
|
|
34
|
+
py: 'py',
|
|
35
|
+
python: 'py',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const PROSE_BASENAMES = [
|
|
39
|
+
'license',
|
|
40
|
+
'licence',
|
|
41
|
+
'copying',
|
|
42
|
+
'authors',
|
|
43
|
+
'notice',
|
|
44
|
+
'copyright',
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const fileExt = (filePath) => {
|
|
48
|
+
const base = path.basename(filePath || '');
|
|
49
|
+
const i = base.lastIndexOf('.');
|
|
50
|
+
if (i <= 0) return '';
|
|
51
|
+
return base.slice(i + 1).toLowerCase();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const mapLang = (name) => {
|
|
55
|
+
if (!name) return 'txt';
|
|
56
|
+
return LANG[name.toLowerCase()] || 'txt';
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const isProseBasename = (base) => {
|
|
60
|
+
const name = (base || '').toLowerCase();
|
|
61
|
+
if (PROSE_BASENAMES.includes(name)) return true;
|
|
62
|
+
const stem = name.replace(/\.(txt|text|md|markdown)$/i, '');
|
|
63
|
+
return PROSE_BASENAMES.includes(stem);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const LANG_RULES = [
|
|
67
|
+
{ test: (base) => base.endsWith('.d.ts'), lang: 'dts' },
|
|
68
|
+
{ test: isProseBasename, lang: 'md' },
|
|
69
|
+
{ test: (base) => base.endsWith('.log'), lang: 'log' },
|
|
70
|
+
{ test: (base) => base.startsWith('.'), lang: 'dot' },
|
|
71
|
+
{ test: (base) => !base.includes('.'), lang: 'dot' },
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
const detectLang = (filePath) => {
|
|
75
|
+
const base = path.basename(filePath || '').toLowerCase();
|
|
76
|
+
for (const rule of LANG_RULES) {
|
|
77
|
+
if (rule.test(base)) return rule.lang;
|
|
78
|
+
}
|
|
79
|
+
const ext = fileExt(base);
|
|
80
|
+
if (ext) return LANG[ext] || 'txt';
|
|
81
|
+
return 'dot';
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
module.exports = { LANG, mapLang, detectLang, fileExt };
|