mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 06:40:20 +03:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fdb31b55b | ||
|
|
67094980c9 | ||
|
|
87984e2081 |
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.8 KiB |
@@ -1,4 +1,8 @@
|
||||

|
||||
<picture>
|
||||
<source srcset="./.github/logo-dark.png" media="(prefers-color-scheme: light)">
|
||||
<source srcset="./.github/logo-white.png" media="(prefers-color-scheme: dark)">
|
||||
<img src="./.github/logo-dark.png" alt="logo">
|
||||
</picture>
|
||||
|
||||
Useful tools for developer and people working in IT. [Have a look !](https://it-tools.tech).
|
||||
|
||||
|
||||
Vendored
+2
-3
@@ -121,6 +121,7 @@ declare module '@vue/runtime-core' {
|
||||
LoremIpsumGenerator: typeof import('./src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue')['default']
|
||||
MacAddressGenerator: typeof import('./src/tools/mac-address-generator/mac-address-generator.vue')['default']
|
||||
MacAddressLookup: typeof import('./src/tools/mac-address-lookup/mac-address-lookup.vue')['default']
|
||||
MarkdownToHtml: typeof import('./src/tools/markdown-to-html/markdown-to-html.vue')['default']
|
||||
MathEvaluator: typeof import('./src/tools/math-evaluator/math-evaluator.vue')['default']
|
||||
MenuBar: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar.vue')['default']
|
||||
MenuBarItem: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar-item.vue')['default']
|
||||
@@ -129,7 +130,7 @@ declare module '@vue/runtime-core' {
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NButton: typeof import('naive-ui')['NButton']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
@@ -144,8 +145,6 @@ declare module '@vue/runtime-core' {
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSpin: typeof import('naive-ui')['NSpin']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@types/utf8": "^3.0.3",
|
||||
"@unicode/unicode-15.1.0": "^1.6.0",
|
||||
"@vicons/material": "^0.12.0",
|
||||
"@vicons/tabler": "^0.12.0",
|
||||
"@vueuse/core": "^10.3.0",
|
||||
@@ -70,6 +73,7 @@
|
||||
"jwt-decode": "^3.1.2",
|
||||
"libphonenumber-js": "^1.10.28",
|
||||
"lodash": "^4.17.21",
|
||||
"markdown-it": "^14.0.0",
|
||||
"marked": "^10.0.0",
|
||||
"mathjs": "^11.9.1",
|
||||
"mime-types": "^2.1.35",
|
||||
@@ -87,6 +91,7 @@
|
||||
"ulid": "^2.3.0",
|
||||
"unicode-emoji-json": "^0.4.0",
|
||||
"unplugin-auto-import": "^0.16.4",
|
||||
"utf8": "^3.0.0",
|
||||
"uuid": "^9.0.0",
|
||||
"vue": "^3.3.4",
|
||||
"vue-i18n": "^9.9.1",
|
||||
@@ -134,6 +139,7 @@
|
||||
"unplugin-icons": "^0.17.0",
|
||||
"unplugin-vue-components": "^0.25.0",
|
||||
"vite": "^4.4.9",
|
||||
"vite-plugin-node-polyfills": "^0.22.0",
|
||||
"vite-plugin-pwa": "^0.16.0",
|
||||
"vite-plugin-vue-markdown": "^0.23.5",
|
||||
"vite-svg-loader": "^4.0.0",
|
||||
|
||||
Generated
+698
-10
File diff suppressed because it is too large.
Load diff
@@ -7,6 +7,7 @@ import sqlHljs from 'highlight.js/lib/languages/sql';
|
||||
import xmlHljs from 'highlight.js/lib/languages/xml';
|
||||
import yamlHljs from 'highlight.js/lib/languages/yaml';
|
||||
import iniHljs from 'highlight.js/lib/languages/ini';
|
||||
import markdownHljs from 'highlight.js/lib/languages/markdown';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const props = withDefaults(
|
||||
@@ -30,6 +31,7 @@ hljs.registerLanguage('html', xmlHljs);
|
||||
hljs.registerLanguage('xml', xmlHljs);
|
||||
hljs.registerLanguage('yaml', yamlHljs);
|
||||
hljs.registerLanguage('toml', iniHljs);
|
||||
hljs.registerLanguage('markdown', markdownHljs);
|
||||
|
||||
const { value, language, followHeightOf, copyPlacement, copyMessage } = toRefs(props);
|
||||
const { height } = followHeightOf.value ? useElementSize(followHeightOf) : { height: ref(null) };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation, computeUmaskRepresentation } from './chmod-calculator.service';
|
||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation } from './chmod-calculator.service';
|
||||
|
||||
describe('chmod-calculator', () => {
|
||||
describe('computeChmodOctalRepresentation', () => {
|
||||
@@ -10,7 +10,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('777');
|
||||
@@ -21,7 +20,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('000');
|
||||
@@ -32,7 +30,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('235');
|
||||
@@ -43,7 +40,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('421');
|
||||
@@ -54,7 +50,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('124');
|
||||
@@ -65,57 +60,11 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('222');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('7222');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('4222');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: true, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('2222');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('1222');
|
||||
});
|
||||
});
|
||||
describe('computeChmodSymbolicRepresentation', () => {
|
||||
|
||||
it('get the symbolic representation from permissions', () => {
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
@@ -123,7 +72,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('rwxrwxrwx');
|
||||
@@ -134,7 +82,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('---------');
|
||||
@@ -145,7 +92,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('-w--wxr-x');
|
||||
@@ -156,7 +102,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('r---w---x');
|
||||
@@ -167,7 +112,6 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('--x-w-r--');
|
||||
@@ -178,382 +122,9 @@ describe('chmod-calculator', () => {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('-w--w--w-');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('--x-w-r-t');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('--x-wsr-t');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('--s-wsr-t');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: false, execute: true },
|
||||
group: { read: true, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('r-xrw-r--');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('rwsrwsrwt');
|
||||
});
|
||||
});
|
||||
describe('computePermissionsFromChmodOctalRepresentation', () => {
|
||||
it('throws on invalid octal values', () => {
|
||||
expect(() => computePermissionsFromChmodOctalRepresentation('12')).to.throw();
|
||||
expect(() => computePermissionsFromChmodOctalRepresentation('12345')).to.throw();
|
||||
expect(() => computePermissionsFromChmodOctalRepresentation('999')).to.throw();
|
||||
expect(() => computePermissionsFromChmodOctalRepresentation('9999')).to.throw();
|
||||
});
|
||||
|
||||
it('get permissions from octal representation', () => {
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('777'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('000'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('235'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('421'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('124'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('7222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('4222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('2222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: true, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('1222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: true },
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('computePermissionsFromChmodSymbolicRepresentation', () => {
|
||||
it('throws on invalid symbolic values', () => {
|
||||
expect(() => computePermissionsFromChmodSymbolicRepresentation('rr---')).to.throw();
|
||||
expect(() => computePermissionsFromChmodSymbolicRepresentation('rwxrwx--w')).to.throw();
|
||||
});
|
||||
|
||||
it('get permissions from symbolic representation', () => {
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('dr-xr-xr-x'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: false, execute: true },
|
||||
group: { read: true, write: false, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('-rw-r--r--'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: true, execute: false },
|
||||
group: { read: true, write: false, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('rwxrwxrwx'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('---------'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('r---wxr-x'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('r---w---x'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('--x-w-r--'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('-w--w--w-'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('-ws-ws-wt'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: true },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: false, write: true, execute: true },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('-ws-w--w-'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('-w--ws-w-'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: true, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodSymbolicRepresentation('-w--w--wt'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: true },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('computeUmaskRepresentation', () => {
|
||||
it('get the umask from permissions', () => {
|
||||
expect(
|
||||
computeUmaskRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.deep.eq({
|
||||
octal: '000',
|
||||
symbolic: 'umask u=rwx,g=rwx,o=rwx',
|
||||
});
|
||||
|
||||
expect(
|
||||
computeUmaskRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.deep.eq({
|
||||
octal: '777',
|
||||
symbolic: 'umask u=,g=,o=',
|
||||
});
|
||||
|
||||
expect(
|
||||
computeUmaskRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.deep.eq({
|
||||
octal: '542',
|
||||
symbolic: 'umask u=w,g=wx,o=rx',
|
||||
});
|
||||
|
||||
expect(
|
||||
computeUmaskRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.deep.eq({
|
||||
octal: '356',
|
||||
symbolic: 'umask u=r,g=w,o=x',
|
||||
});
|
||||
|
||||
expect(
|
||||
computeUmaskRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.deep.eq({
|
||||
octal: '653',
|
||||
symbolic: 'umask u=x,g=w,o=r',
|
||||
});
|
||||
|
||||
expect(
|
||||
computeUmaskRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.deep.eq({
|
||||
octal: '555',
|
||||
symbolic: 'umask u=w,g=w,o=w',
|
||||
});
|
||||
|
||||
expect(
|
||||
computeUmaskRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.deep.eq({
|
||||
octal: '653',
|
||||
symbolic: 'umask u=x,g=w,o=r',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,21 +1,15 @@
|
||||
import _ from 'lodash';
|
||||
import type { GroupPermissions, Permissions, SpecialPermissions } from './chmod-calculator.types';
|
||||
import type { GroupPermissions, Permissions } from './chmod-calculator.types';
|
||||
|
||||
export { computeUmaskRepresentation, computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation };
|
||||
export { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation };
|
||||
|
||||
function computeChmodOctalRepresentation({ permissions }: { permissions: Permissions }): string {
|
||||
const permissionValue = { read: 4, write: 2, execute: 1 };
|
||||
const specialPermissionValue = { setuid: 4, setgid: 2, stickybit: 1 };
|
||||
|
||||
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
||||
_.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(permissionValue, key, 0) : 0), 0);
|
||||
const getSpecialPermissionValue = (permission: SpecialPermissions) => {
|
||||
const octalValue = _.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(specialPermissionValue, key, 0) : 0), 0);
|
||||
return octalValue > 0 ? octalValue.toString() : '';
|
||||
};
|
||||
|
||||
return [
|
||||
getSpecialPermissionValue(permissions.flags || { setuid: false, setgid: false, stickybit: false }),
|
||||
getGroupPermissionValue(permissions.owner),
|
||||
getGroupPermissionValue(permissions.group),
|
||||
getGroupPermissionValue(permissions.public),
|
||||
@@ -24,92 +18,13 @@ function computeChmodOctalRepresentation({ permissions }: { permissions: Permiss
|
||||
|
||||
function computeChmodSymbolicRepresentation({ permissions }: { permissions: Permissions }): string {
|
||||
const permissionValue = { read: 'r', write: 'w', execute: 'x' };
|
||||
const specialFlagPermission = 'execute';
|
||||
|
||||
const getGroupPermissionValue = (permission: GroupPermissions, specialFlag: null | 's' | 't') =>
|
||||
_.reduce(permission, (acc, isPermSet, key) => acc + ((key === specialFlagPermission ? specialFlag : undefined)
|
||||
|| (isPermSet ? _.get(permissionValue, key, '') : '-')), '');
|
||||
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
||||
_.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(permissionValue, key, '') : '-'), '');
|
||||
|
||||
return [
|
||||
getGroupPermissionValue(permissions.owner, permissions.flags?.setuid ? 's' : null),
|
||||
getGroupPermissionValue(permissions.group, permissions.flags?.setgid ? 's' : null),
|
||||
getGroupPermissionValue(permissions.public, permissions.flags?.stickybit ? 't' : null),
|
||||
getGroupPermissionValue(permissions.owner),
|
||||
getGroupPermissionValue(permissions.group),
|
||||
getGroupPermissionValue(permissions.public),
|
||||
].join('');
|
||||
}
|
||||
|
||||
function computePermissionsFromChmodOctalRepresentation(octalPermissions: string): Permissions {
|
||||
const permissionValue = { read: 4, write: 2, execute: 1 };
|
||||
const specialPermissionValue = { setuid: 4, setgid: 2, stickybit: 1 };
|
||||
|
||||
if (!octalPermissions || !octalPermissions.match(/^[0-7]{3,4}$/)) {
|
||||
throw new Error(`Invalid octal permissions (must be 3 or 4 octal digits): ${octalPermissions}`);
|
||||
}
|
||||
const fullOctalPermissions = octalPermissions.length === 3 ? `0${octalPermissions}` : octalPermissions;
|
||||
|
||||
const hasSet = (position: number, flagValue: number) => (Number(fullOctalPermissions[position]) & flagValue) === flagValue;
|
||||
function computePermissionObject<T>(permissionSet: object, position: number): T {
|
||||
return _.reduce(permissionSet, (acc, flag, key) => ({ ...acc, [key]: hasSet(position, flag) }), {}) as T;
|
||||
}
|
||||
const flagsPosition = 0;
|
||||
const ownerPosition = 1;
|
||||
const groupPosition = 2;
|
||||
const publicPosition = 3;
|
||||
return {
|
||||
owner: computePermissionObject(permissionValue, ownerPosition),
|
||||
group: computePermissionObject(permissionValue, groupPosition),
|
||||
public: computePermissionObject(permissionValue, publicPosition),
|
||||
flags: computePermissionObject(specialPermissionValue, flagsPosition),
|
||||
};
|
||||
}
|
||||
|
||||
function computePermissionsFromChmodSymbolicRepresentation(symbolicPermissions: string): Permissions {
|
||||
const formatRegex = /^[-dlbcsp]?([r-])([w-])([xs-])([r-])([w-])([xs-])([r-])([w-])([xt-])$/;
|
||||
if (!symbolicPermissions || !symbolicPermissions.match(formatRegex)) {
|
||||
throw new Error(`Invalid string permissions (must be in form 'rwxrwxrwx'): ${symbolicPermissions}`);
|
||||
}
|
||||
|
||||
const [_, rOwner, wOwner, xOwner, rGroup, wGroup, xGroup, rAll, wAll, xAll] = formatRegex.exec(symbolicPermissions) || [];
|
||||
const getOctal = (flag: string, flagLetter: string, flagValue: number) => flag === flagLetter ? flagValue : 0;
|
||||
const owner = getOctal(rOwner, 'r', 4)
|
||||
+ getOctal(wOwner, 'w', 2)
|
||||
+ getOctal(xOwner, 'x', 1) + getOctal(xOwner, 's', 1);
|
||||
const groups = getOctal(rGroup, 'r', 4)
|
||||
+ getOctal(wGroup, 'w', 2)
|
||||
+ getOctal(xGroup, 'x', 1) + getOctal(xGroup, 's', 1);
|
||||
const all = getOctal(rAll, 'r', 4)
|
||||
+ getOctal(wAll, 'w', 2)
|
||||
+ getOctal(xAll, 'x', 1) + getOctal(xAll, 't', 1);
|
||||
const flags = getOctal(xOwner, 's', 4)
|
||||
+ getOctal(xGroup, 's', 2)
|
||||
+ getOctal(xAll, 't', 1);
|
||||
const octalString = `${(flags > 0 ? flags : '')}${owner}${groups}${all}`;
|
||||
|
||||
return computePermissionsFromChmodOctalRepresentation(octalString);
|
||||
}
|
||||
|
||||
function computeUmaskRepresentation({ permissions }: { permissions: Permissions }): {
|
||||
octal: string
|
||||
symbolic: string
|
||||
} {
|
||||
const permissionValue = { read: 'r', write: 'w', execute: 'x' };
|
||||
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
||||
_.reduce(permission, (acc, isPermSet, key) => acc + ((isPermSet ? _.get(permissionValue, key, '') : '')), '');
|
||||
|
||||
const symbolic = `umask u=${getGroupPermissionValue(permissions.owner)},g=${getGroupPermissionValue(permissions.group)},o=${getGroupPermissionValue(permissions.public)}`;
|
||||
const octal = (0o777 - Number.parseInt(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions:
|
||||
{
|
||||
owner: permissions.owner,
|
||||
group: permissions.group,
|
||||
public: permissions.public,
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}), 8))
|
||||
.toString(8)
|
||||
.padStart(3, '0');
|
||||
|
||||
return {
|
||||
symbolic, octal,
|
||||
};
|
||||
}
|
||||
@@ -1,17 +1,10 @@
|
||||
export type Scope = 'read' | 'write' | 'execute';
|
||||
export type Group = 'owner' | 'group' | 'public';
|
||||
export type SpecialFlags = 'setuid' | 'setgid' | 'stickybit';
|
||||
|
||||
export type GroupPermissions = {
|
||||
[k in Scope]: boolean;
|
||||
};
|
||||
|
||||
export type SpecialPermissions = {
|
||||
[k in SpecialFlags]: boolean;
|
||||
};
|
||||
|
||||
export type Permissions = {
|
||||
[k in Group]: GroupPermissions;
|
||||
} & {
|
||||
flags: SpecialPermissions
|
||||
};
|
||||
@@ -2,10 +2,9 @@
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
|
||||
import InputCopyable from '../../components/InputCopyable.vue';
|
||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation, computeUmaskRepresentation } from './chmod-calculator.service';
|
||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation } from './chmod-calculator.service';
|
||||
|
||||
import type { Group, Scope } from './chmod-calculator.types';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
|
||||
@@ -20,92 +19,14 @@ const permissions = ref({
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
const octalPermissionsInput = ref('000');
|
||||
const octalPermissionsInputValidation = useValidation({
|
||||
source: octalPermissionsInput,
|
||||
rules: [
|
||||
{
|
||||
message: 'Invalid octal permission string',
|
||||
validator: (value) => {
|
||||
try {
|
||||
computePermissionsFromChmodOctalRepresentation(value.trim());
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
watch(
|
||||
octalPermissionsInput,
|
||||
(newPermissions) => {
|
||||
if (!octalPermissionsInputValidation.isValid) {
|
||||
return;
|
||||
}
|
||||
permissions.value = computePermissionsFromChmodOctalRepresentation(newPermissions.trim());
|
||||
},
|
||||
);
|
||||
|
||||
const symbolicPermissionsInput = ref('---------');
|
||||
const symbolicPermissionsInputValidation = useValidation({
|
||||
source: symbolicPermissionsInput,
|
||||
rules: [
|
||||
{
|
||||
message: 'Invalid symbolic permission string',
|
||||
validator: (value) => {
|
||||
try {
|
||||
computePermissionsFromChmodSymbolicRepresentation(value.trim());
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
watch(
|
||||
symbolicPermissionsInput,
|
||||
(newPermissions) => {
|
||||
if (!symbolicPermissionsInputValidation.isValid) {
|
||||
return;
|
||||
}
|
||||
permissions.value = computePermissionsFromChmodSymbolicRepresentation(newPermissions.trim());
|
||||
},
|
||||
);
|
||||
|
||||
const octal = computed(() => computeChmodOctalRepresentation({ permissions: permissions.value }));
|
||||
const symbolic = computed(() => computeChmodSymbolicRepresentation({ permissions: permissions.value }));
|
||||
const umask = computed(() => computeUmaskRepresentation({ permissions: permissions.value }));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="octalPermissionsInput"
|
||||
placeholder="Put your octal permissions here..."
|
||||
label="Copy your octal permissions"
|
||||
:validation="octalPermissionsInputValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<c-input-text
|
||||
v-model:value="symbolicPermissionsInput"
|
||||
placeholder="Put your symbolic permissions here..."
|
||||
label="Copy your symbolic permissions"
|
||||
:validation="symbolicPermissionsInputValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-table :bordered="false" :bottom-bordered="false" single-column class="permission-table">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -131,20 +52,6 @@ const umask = computed(() => computeUmaskRepresentation({ permissions: permissio
|
||||
<n-checkbox v-model:checked="permissions[group][scope]" size="large" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="line-header">
|
||||
Flags
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<n-checkbox v-model:checked="permissions.flags.setuid" size="large" />
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<n-checkbox v-model:checked="permissions.flags.setgid" size="large" />
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<n-checkbox v-model:checked="permissions.flags.stickybit" size="large" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</n-table>
|
||||
|
||||
@@ -156,11 +63,6 @@ const umask = computed(() => computeUmaskRepresentation({ permissions: permissio
|
||||
</div>
|
||||
|
||||
<InputCopyable :value="`chmod ${octal} path`" readonly />
|
||||
|
||||
<c-card title="Umask">
|
||||
<InputCopyable :value="umask.octal" readonly />
|
||||
<InputCopyable :value="umask.symbolic" readonly />
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { FileInvoice } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Chmod calculator',
|
||||
name: translate('tools.chmod-calculator.title'),
|
||||
path: '/chmod-calculator',
|
||||
description: 'Compute your chmod permissions and commands with this online chmod calculator.',
|
||||
description: translate('tools.chmod-calculator.description'),
|
||||
keywords: [
|
||||
'chmod',
|
||||
'calculator',
|
||||
@@ -16,7 +17,6 @@ export const tool = defineTool({
|
||||
'recursive',
|
||||
'generator',
|
||||
'octal',
|
||||
'umask',
|
||||
],
|
||||
component: () => import('./chmod-calculator.vue'),
|
||||
icon: FileInvoice,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
|
||||
import { tool as base64StringConverter } from './base64-string-converter';
|
||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
import { tool as emailNormalizer } from './email-normalizer';
|
||||
import { tool as unicodeSearch } from './unicode-search';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -9,6 +10,7 @@ import { tool as textToUnicode } from './text-to-unicode';
|
||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
||||
import { tool as xmlToJson } from './xml-to-json';
|
||||
import { tool as jsonToXml } from './json-to-xml';
|
||||
import { tool as markdownToHtml } from './markdown-to-html';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -112,6 +114,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
tomlToYaml,
|
||||
xmlToJson,
|
||||
jsonToXml,
|
||||
markdownToHtml,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -133,6 +136,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
httpStatusCodes,
|
||||
jsonDiff,
|
||||
safelinkDecoder,
|
||||
unicodeSearch,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Markdown } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Markdown to HTML',
|
||||
path: '/markdown-to-html',
|
||||
description: 'Convert Markdown to Html and allow to print (as PDF)',
|
||||
keywords: ['markdown', 'html', 'converter', 'pdf'],
|
||||
component: () => import('./markdown-to-html.vue'),
|
||||
icon: Markdown,
|
||||
createdAt: new Date('2024-08-25'),
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
import markdownit from 'markdown-it';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
|
||||
const inputMarkdown = ref('');
|
||||
const outputHtml = computed(() => {
|
||||
const md = markdownit();
|
||||
return md.render(inputMarkdown.value);
|
||||
});
|
||||
|
||||
function printHtml() {
|
||||
const w = window.open();
|
||||
if (w === null) {
|
||||
return;
|
||||
}
|
||||
w.document.body.innerHTML = outputHtml.value;
|
||||
w.print();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="inputMarkdown"
|
||||
multiline raw-text
|
||||
placeholder="Your Markdown content..."
|
||||
rows="8"
|
||||
autofocus
|
||||
label="Your Markdown to convert:"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item label="Output HTML:">
|
||||
<TextareaCopyable :value="outputHtml" :word-wrap="true" language="html" />
|
||||
</n-form-item>
|
||||
|
||||
<div flex justify-center>
|
||||
<n-button @click="printHtml">
|
||||
Print as PDF
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { FileText } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Unicode Search',
|
||||
path: '/unicode-search',
|
||||
description: 'Search in Unicode Characters',
|
||||
keywords: ['unicode', 'search'],
|
||||
component: () => import('./unicode-search.vue'),
|
||||
icon: FileText,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -0,0 +1,122 @@
|
||||
<script setup lang="ts">
|
||||
import unicodeNames from '@unicode/unicode-15.1.0/Names/index.js';
|
||||
import unicodeCategories from '@unicode/unicode-15.1.0/General_Category';
|
||||
import utf8 from 'utf8';
|
||||
|
||||
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
||||
import useDebouncedRef from '@/composable/debouncedref';
|
||||
|
||||
function toPaddedHex(num: number) {
|
||||
return num.toString(16).padStart(4, '0').toUpperCase();
|
||||
}
|
||||
|
||||
function toUTF8(codePoint: number) {
|
||||
const utf8String = utf8.encode(String.fromCodePoint(codePoint));
|
||||
return [...utf8String].map(c => `\\x${c.codePointAt(0)?.toString(16).toUpperCase()}`);
|
||||
}
|
||||
|
||||
const searchQuery = useDebouncedRef('', 500);
|
||||
const parsedSearchQuery = computed(() => {
|
||||
const parsedRegex = /^\s*(?:\&#x(?<hex1>[\da-f]+);|\&#(?<dec>\d+);|(?:U\+|\\u)?\s*(?<hex2>[\da-f]+))\s*$/gi; // NOSONAR
|
||||
const parsedQuery = parsedRegex.exec(searchQuery.value);
|
||||
if (parsedQuery) {
|
||||
if (parsedQuery.groups?.hex1 || parsedQuery.groups?.hex2) {
|
||||
return `=${toPaddedHex(Number.parseInt(parsedQuery.groups.hex1 || parsedQuery.groups.hex2, 16))}`;
|
||||
}
|
||||
if (parsedQuery.groups?.dec) {
|
||||
return `=${toPaddedHex(Number.parseInt(parsedQuery.groups.dec, 10))}`;
|
||||
}
|
||||
}
|
||||
return searchQuery.value;
|
||||
});
|
||||
|
||||
const unicodeSearchData = [...unicodeNames].map(([codePoint, characterName]) => {
|
||||
const hex = toPaddedHex(codePoint);
|
||||
return {
|
||||
codePoint,
|
||||
characterName: `${characterName} (U+${hex})`,
|
||||
hex,
|
||||
};
|
||||
});
|
||||
|
||||
const { searchResult } = useFuzzySearch({
|
||||
search: parsedSearchQuery,
|
||||
data: unicodeSearchData,
|
||||
options: {
|
||||
keys: ['characterName', 'hex'],
|
||||
threshold: 0.2,
|
||||
isCaseSensitive: false,
|
||||
minMatchCharLength: 3,
|
||||
useExtendedSearch: true,
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div mx-auto max-w-2400px important:flex-1>
|
||||
<div flex items-center gap-3>
|
||||
<c-input-text
|
||||
v-model:value="searchQuery"
|
||||
placeholder="Search Unicode by name (e.g. 'zero width') or code point..."
|
||||
mx-auto max-w-600px
|
||||
>
|
||||
<template #prefix>
|
||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||
</template>
|
||||
</c-input-text>
|
||||
</div>
|
||||
|
||||
<div v-if="searchQuery.trim().length > 0">
|
||||
<div
|
||||
v-if="searchResult.length === 0"
|
||||
mt-4
|
||||
text-20px
|
||||
font-bold
|
||||
>
|
||||
No results
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<div mt-4 text-20px font-bold>
|
||||
Search result
|
||||
</div>
|
||||
|
||||
<n-table>
|
||||
<thead>
|
||||
<th>UCOD</th>
|
||||
<th>Display/UTF8</th>
|
||||
<th style="width:30%">
|
||||
Category
|
||||
</th>
|
||||
<th>Html</th>
|
||||
<th style="width:30%">
|
||||
Name
|
||||
</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(result, ix) in searchResult" :key="ix">
|
||||
<td>
|
||||
<input-copyable :value="`U+${toPaddedHex(result.codePoint)}`" mb-1 />
|
||||
<!-- //NOSONAR --><n-a :href="`https://unicodeplus.com/U+${toPaddedHex(result.codePoint)}`" target="_blank">
|
||||
> More info
|
||||
</n-a>
|
||||
</td>
|
||||
<td>
|
||||
<input-copyable :value="String.fromCodePoint(result.codePoint)" mb-1 />
|
||||
<input-copyable :value="toUTF8(result.codePoint)" />
|
||||
</td>
|
||||
<td>
|
||||
<input-copyable :value="unicodeCategories.get(result.codePoint)" />
|
||||
</td>
|
||||
<td>
|
||||
<input-copyable :value="`\&\#x${toPaddedHex(result.codePoint)};`" mb-1 />
|
||||
<input-copyable :value="`\&\#${result.codePoint};`" />
|
||||
</td>
|
||||
<td><input-copyable :value="result.characterName" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</n-table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
declare module '@unicode/unicode-15.1.0/Names/index.js'{
|
||||
const unicode: HashSet<number, string>;
|
||||
export default unicode;
|
||||
}
|
||||
|
||||
declare module '@unicode/unicode-15.1.0/General_Category'{
|
||||
const unicode: HashSet<number, string>;
|
||||
export default unicode;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import { VitePWA } from 'vite-plugin-pwa';
|
||||
import markdown from 'vite-plugin-vue-markdown';
|
||||
import svgLoader from 'vite-svg-loader';
|
||||
import { configDefaults } from 'vitest/config';
|
||||
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
||||
|
||||
const baseUrl = process.env.BASE_URL ?? '/';
|
||||
|
||||
@@ -97,6 +98,7 @@ export default defineConfig({
|
||||
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
|
||||
}),
|
||||
Unocss(),
|
||||
nodePolyfills(),
|
||||
],
|
||||
base: baseUrl,
|
||||
resolve: {
|
||||
|
||||
Reference in new issue
Block a user