mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-23 14:21:04 +03:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e113a850e |
No files matched your search
Vendored
+9
-3
@@ -78,6 +78,7 @@ declare module '@vue/runtime-core' {
|
||||
Encryption: typeof import('./src/tools/encryption/encryption.vue')['default']
|
||||
EtaCalculator: typeof import('./src/tools/eta-calculator/eta-calculator.vue')['default']
|
||||
FavoriteButton: typeof import('./src/components/FavoriteButton.vue')['default']
|
||||
FolderStructureDiagram: typeof import('./src/tools/folder-structure-diagram/folder-structure-diagram.vue')['default']
|
||||
FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default']
|
||||
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
|
||||
'GitMemo.content': typeof import('./src/tools/git-memo/git-memo.content.md')['default']
|
||||
@@ -127,18 +128,24 @@ 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']
|
||||
NButton: typeof import('naive-ui')['NButton']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||
NGi: typeof import('naive-ui')['NGi']
|
||||
NGrid: typeof import('naive-ui')['NGrid']
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||
NLabel: typeof import('naive-ui')['NLabel']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSpin: typeof import('naive-ui')['NSpin']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||
@@ -173,7 +180,6 @@ declare module '@vue/runtime-core' {
|
||||
'Tool.layout': typeof import('./src/layouts/tool.layout.vue')['default']
|
||||
ToolCard: typeof import('./src/components/ToolCard.vue')['default']
|
||||
UlidGenerator: typeof import('./src/tools/ulid-generator/ulid-generator.vue')['default']
|
||||
UnicodeFormatter: typeof import('./src/tools/unicode-formatter/unicode-formatter.vue')['default']
|
||||
UrlEncoder: typeof import('./src/tools/url-encoder/url-encoder.vue')['default']
|
||||
UrlParser: typeof import('./src/tools/url-parser/url-parser.vue')['default']
|
||||
UserAgentParser: typeof import('./src/tools/user-agent-parser/user-agent-parser.vue')['default']
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/lodash.defaultsdeep": "^4.6.9",
|
||||
"@types/lodash.flattendeep": "^4.4.9",
|
||||
"@types/lodash.last": "^3.0.9",
|
||||
"@vicons/material": "^0.12.0",
|
||||
"@vicons/tabler": "^0.12.0",
|
||||
"@vueuse/core": "^10.3.0",
|
||||
@@ -68,6 +71,9 @@
|
||||
"jwt-decode": "^3.1.2",
|
||||
"libphonenumber-js": "^1.10.28",
|
||||
"lodash": "^4.17.21",
|
||||
"lodash.defaultsdeep": "^4.6.1",
|
||||
"lodash.flattendeep": "^4.4.0",
|
||||
"lodash.last": "^3.0.0",
|
||||
"marked": "^10.0.0",
|
||||
"mathjs": "^11.9.1",
|
||||
"mime-types": "^2.1.35",
|
||||
|
||||
Generated
+55
-6
@@ -26,6 +26,15 @@ dependencies:
|
||||
'@types/figlet':
|
||||
specifier: ^1.5.8
|
||||
version: 1.5.8
|
||||
'@types/lodash.defaultsdeep':
|
||||
specifier: ^4.6.9
|
||||
version: 4.6.9
|
||||
'@types/lodash.flattendeep':
|
||||
specifier: ^4.4.9
|
||||
version: 4.4.9
|
||||
'@types/lodash.last':
|
||||
specifier: ^3.0.9
|
||||
version: 3.0.9
|
||||
'@vicons/material':
|
||||
specifier: ^0.12.0
|
||||
version: 0.12.0
|
||||
@@ -104,6 +113,15 @@ dependencies:
|
||||
lodash:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
lodash.defaultsdeep:
|
||||
specifier: ^4.6.1
|
||||
version: 4.6.1
|
||||
lodash.flattendeep:
|
||||
specifier: ^4.4.0
|
||||
version: 4.4.0
|
||||
lodash.last:
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0
|
||||
marked:
|
||||
specifier: ^10.0.0
|
||||
version: 10.0.0
|
||||
@@ -2951,6 +2969,24 @@ packages:
|
||||
'@types/lodash': 4.14.192
|
||||
dev: false
|
||||
|
||||
/@types/lodash.defaultsdeep@4.6.9:
|
||||
resolution: {integrity: sha512-pLtCFK0YkHfGtGLYLNMTbFB5/G5+RsmQCIbbHH8GOAXjv+gDkVilY98kILfe8JH2Kev0OCReYxp1AjxEjP8ixA==}
|
||||
dependencies:
|
||||
'@types/lodash': 4.14.200
|
||||
dev: false
|
||||
|
||||
/@types/lodash.flattendeep@4.4.9:
|
||||
resolution: {integrity: sha512-Oacs/ZMuMvVWkhMqvj+Spad457Beln5pnkauif+6s65fE2cSL7J7NoMfwkxjuQsOsr4DUCDH/iDbmuZo81Nypw==}
|
||||
dependencies:
|
||||
'@types/lodash': 4.14.200
|
||||
dev: false
|
||||
|
||||
/@types/lodash.last@3.0.9:
|
||||
resolution: {integrity: sha512-HMIEyk2LJWDumrHsuSh7ZokUs+xyXa0nZO/s3paaKjOvwrjBNoQHsM0UqcpmzEt7CJ29a16XNe3vr8buvHeMCg==}
|
||||
dependencies:
|
||||
'@types/lodash': 4.14.200
|
||||
dev: false
|
||||
|
||||
/@types/lodash@4.14.192:
|
||||
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
||||
|
||||
@@ -3351,7 +3387,7 @@ packages:
|
||||
dependencies:
|
||||
'@unhead/dom': 0.5.1
|
||||
'@unhead/schema': 0.5.1
|
||||
'@vueuse/shared': 10.7.2(vue@3.3.4)
|
||||
'@vueuse/shared': 10.9.0(vue@3.3.4)
|
||||
unhead: 0.5.1
|
||||
vue: 3.3.4
|
||||
transitivePeerDependencies:
|
||||
@@ -3993,10 +4029,10 @@ packages:
|
||||
- vue
|
||||
dev: false
|
||||
|
||||
/@vueuse/shared@10.7.2(vue@3.3.4):
|
||||
resolution: {integrity: sha512-qFbXoxS44pi2FkgFjPvF4h7c9oMDutpyBdcJdMYIMg9XyXli2meFMuaKn+UMgsClo//Th6+beeCgqweT/79BVA==}
|
||||
/@vueuse/shared@10.9.0(vue@3.3.4):
|
||||
resolution: {integrity: sha512-Uud2IWncmAfJvRaFYzv5OHDli+FbOzxiVEQdLCKQKLyhz94PIyFC3CHcH7EDMwIn8NPtD06+PNbC/PiO0LGLtw==}
|
||||
dependencies:
|
||||
vue-demi: 0.14.6(vue@3.3.4)
|
||||
vue-demi: 0.14.7(vue@3.3.4)
|
||||
transitivePeerDependencies:
|
||||
- '@vue/composition-api'
|
||||
- vue
|
||||
@@ -6694,6 +6730,18 @@ packages:
|
||||
resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==}
|
||||
dev: true
|
||||
|
||||
/lodash.defaultsdeep@4.6.1:
|
||||
resolution: {integrity: sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==}
|
||||
dev: false
|
||||
|
||||
/lodash.flattendeep@4.4.0:
|
||||
resolution: {integrity: sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ==}
|
||||
dev: false
|
||||
|
||||
/lodash.last@3.0.0:
|
||||
resolution: {integrity: sha512-14mq7rSkCxG4XMy9lF2FbIOqqgF0aH0NfPuQ3LPR3vIh0kHnUvIYP70dqa1Hf47zyXfQ8FzAg0MYOQeSuE1R7A==}
|
||||
dev: false
|
||||
|
||||
/lodash.merge@4.6.2:
|
||||
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
|
||||
dev: true
|
||||
@@ -9151,8 +9199,8 @@ packages:
|
||||
vue: 3.3.4
|
||||
dev: false
|
||||
|
||||
/vue-demi@0.14.6(vue@3.3.4):
|
||||
resolution: {integrity: sha512-8QA7wrYSHKaYgUxDA5ZC24w+eHm3sYCbp0EzcDwKqN3p6HqtTCGR/GVsPyZW92unff4UlcSh++lmqDWN3ZIq4w==}
|
||||
/vue-demi@0.14.7(vue@3.3.4):
|
||||
resolution: {integrity: sha512-EOG8KXDQNwkJILkx/gPcoL/7vH+hORoBaKgGe+6W7VFMvCYJfmF2dGbvgDroVnI8LU7/kTu8mbjRZGBU1z9NTA==}
|
||||
engines: {node: '>=12'}
|
||||
hasBin: true
|
||||
requiresBuild: true
|
||||
@@ -9442,6 +9490,7 @@ packages:
|
||||
|
||||
/workbox-google-analytics@7.0.0:
|
||||
resolution: {integrity: sha512-MEYM1JTn/qiC3DbpvP2BVhyIH+dV/5BjHk756u9VbwuAhu0QHyKscTnisQuz21lfRpOwiS9z4XdqeVAKol0bzg==}
|
||||
deprecated: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is not longer being maintained
|
||||
dependencies:
|
||||
workbox-background-sync: 7.0.0
|
||||
workbox-core: 7.0.0
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
import { generateTree } from './lib/generate-tree';
|
||||
import { parseInput } from './lib/parse-input';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const inputStructure = ref([
|
||||
'my-app',
|
||||
' src',
|
||||
' index.html',
|
||||
' main.ts',
|
||||
' main.scss',
|
||||
' - build',
|
||||
' - index.html',
|
||||
' main.js',
|
||||
' main.css',
|
||||
'',
|
||||
' ',
|
||||
' .prettierrc.json',
|
||||
' .gitlab-ci.yml',
|
||||
' README.md',
|
||||
'empty dir',
|
||||
].join('\n'));
|
||||
const outputTree = computed(() => withDefaultOnError(() => generateTree(parseInput(inputStructure.value)), ''));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="inputStructure"
|
||||
label="Your indented structure"
|
||||
placeholder="Paste your indented structure here..."
|
||||
rows="20"
|
||||
multiline
|
||||
raw-text
|
||||
monospace
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item label="Your tree-like structure:">
|
||||
<TextareaCopyable :value="outputTree" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Folder } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Folder Structure Diagram',
|
||||
path: '/folder-structure-diagram',
|
||||
description: 'tree-like utility for generating ASCII folder structure diagrams',
|
||||
keywords: ['folder', 'structure', 'diagram', 'tree', 'ascii'],
|
||||
component: () => import('./folder-structure-diagram.vue'),
|
||||
icon: Folder,
|
||||
createdAt: new Date('2024-04-20'),
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Represents a single item in a file system
|
||||
* (i.e. a file or a folder)
|
||||
*/
|
||||
export interface FileStructure {
|
||||
/** The name of the file or folder */
|
||||
name: string
|
||||
|
||||
/** If a folder, the contents of the folder */
|
||||
children: FileStructure[]
|
||||
|
||||
/**
|
||||
* The number of spaces in front of the name
|
||||
* in the original source string
|
||||
*/
|
||||
indentCount: number
|
||||
|
||||
/** The parent directory of this file or folder */
|
||||
parent: FileStructure | null
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { generateTree } from './generate-tree';
|
||||
import { mockInput } from './mock-input';
|
||||
import { parseInput } from './parse-input';
|
||||
|
||||
describe('generateTree', () => {
|
||||
it('returns an UTF-8 representation of the provided FileStructure object', () => {
|
||||
const actual = generateTree(parseInput(mockInput));
|
||||
|
||||
const expected = `
|
||||
.
|
||||
├── my-app
|
||||
│ ├── src
|
||||
│ │ ├── index.html
|
||||
│ │ ├── main.ts
|
||||
│ │ └── main.scss
|
||||
│ ├── build
|
||||
│ │ ├── index.html
|
||||
│ │ ├── main.js
|
||||
│ │ └── main.css
|
||||
│ ├── .prettierrc.json
|
||||
│ ├── .gitlab-ci.yml
|
||||
│ └── README.md
|
||||
└── empty dir
|
||||
|
||||
`.trim();
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('returns an ASCII representation of the provided FileStructure object', () => {
|
||||
const actual = generateTree(parseInput(mockInput), { charset: 'ascii' });
|
||||
|
||||
const expected = `
|
||||
.
|
||||
|-- my-app
|
||||
| |-- src
|
||||
| | |-- index.html
|
||||
| | |-- main.ts
|
||||
| | \`-- main.scss
|
||||
| |-- build
|
||||
| | |-- index.html
|
||||
| | |-- main.js
|
||||
| | \`-- main.css
|
||||
| |-- .prettierrc.json
|
||||
| |-- .gitlab-ci.yml
|
||||
| \`-- README.md
|
||||
\`-- empty dir
|
||||
|
||||
`.trim();
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('does not render lines for parent directories that have already printed all of their children', () => {
|
||||
const input = `
|
||||
|
||||
grandparent
|
||||
parent
|
||||
child
|
||||
parent
|
||||
child
|
||||
grandchild
|
||||
|
||||
`;
|
||||
|
||||
const actual = generateTree(parseInput(input));
|
||||
|
||||
const expected = `
|
||||
.
|
||||
└── grandparent
|
||||
├── parent
|
||||
│ └── child
|
||||
└── parent
|
||||
└── child
|
||||
└── grandchild
|
||||
|
||||
`.trim();
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('appends a trailing slash to directories if trailingDirSlash === true', () => {
|
||||
const input = `
|
||||
|
||||
grandparent
|
||||
parent/
|
||||
child
|
||||
parent//
|
||||
child
|
||||
grandchild
|
||||
|
||||
`;
|
||||
|
||||
const actual = generateTree(parseInput(input), { trailingDirSlash: true });
|
||||
|
||||
const expected = `
|
||||
.
|
||||
└── grandparent/
|
||||
├── parent/
|
||||
│ └── child
|
||||
└── parent//
|
||||
└── child/
|
||||
└── grandchild
|
||||
|
||||
`.trim();
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('prints each items\' full path if fullPath === true', () => {
|
||||
const input = `
|
||||
|
||||
grandparent
|
||||
parent/
|
||||
child
|
||||
parent//
|
||||
child
|
||||
grandchild
|
||||
|
||||
`;
|
||||
|
||||
const actual = generateTree(parseInput(input), { fullPath: true });
|
||||
|
||||
const expected = `
|
||||
.
|
||||
└── ./grandparent
|
||||
├── ./grandparent/parent/
|
||||
│ └── ./grandparent/parent/child
|
||||
└── ./grandparent/parent//
|
||||
└── ./grandparent/parent//child
|
||||
└── ./grandparent/parent//child/grandchild
|
||||
|
||||
`.trim();
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('does not render the root dot if rootDot === false', () => {
|
||||
const input = `
|
||||
|
||||
grandparent
|
||||
parent
|
||||
child
|
||||
parent
|
||||
child
|
||||
grandchild
|
||||
|
||||
`;
|
||||
|
||||
const actual = generateTree(parseInput(input), { rootDot: false });
|
||||
|
||||
const expected = `
|
||||
grandparent
|
||||
├── parent
|
||||
│ └── child
|
||||
└── parent
|
||||
└── child
|
||||
└── grandchild
|
||||
|
||||
`.trim();
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
import type { RecursiveArray } from 'lodash';
|
||||
import defaultsDeep from 'lodash.defaultsdeep';
|
||||
import flattenDeep from 'lodash.flattendeep';
|
||||
import last from 'lodash.last';
|
||||
import type { FileStructure } from './FileStructure';
|
||||
import { LINE_STRINGS } from './line-strings';
|
||||
|
||||
/**
|
||||
* Represents all rendering options available
|
||||
* when calling `generateTree`
|
||||
*/
|
||||
interface GenerateTreeOptions {
|
||||
/**
|
||||
* Which set of characters to use when
|
||||
* rendering directory lines
|
||||
*/
|
||||
charset?: 'ascii' | 'utf-8'
|
||||
|
||||
/**
|
||||
* Whether or not to append trailing slashes
|
||||
* to directories. Items that already include a
|
||||
* trailing slash will not have another appended.
|
||||
*/
|
||||
trailingDirSlash?: boolean
|
||||
|
||||
/**
|
||||
* Whether or not to print the full
|
||||
* path of the item
|
||||
*/
|
||||
fullPath?: boolean
|
||||
|
||||
/**
|
||||
* Whether or not to render a dot as the root of the tree
|
||||
*/
|
||||
rootDot?: boolean
|
||||
}
|
||||
|
||||
/** The default options if no options are provided */
|
||||
const defaultOptions: GenerateTreeOptions = {
|
||||
charset: 'utf-8',
|
||||
trailingDirSlash: false,
|
||||
fullPath: false,
|
||||
rootDot: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates an ASCII tree diagram, given a FileStructure
|
||||
* @param structure The FileStructure object to convert into ASCII
|
||||
* @param options The rendering options
|
||||
*/
|
||||
export function generateTree(structure: FileStructure,
|
||||
options?: GenerateTreeOptions): string {
|
||||
return flattenDeep([
|
||||
getAsciiLine(structure, defaultsDeep({}, options, defaultOptions)),
|
||||
structure.children.map(c => generateTree(c, options)) as RecursiveArray<
|
||||
string
|
||||
>,
|
||||
])
|
||||
// Remove null entries. Should only occur for the very first node
|
||||
// when `options.rootDot === false`
|
||||
.filter(line => line != null)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a line of ASCII that represents
|
||||
* a single FileStructure object
|
||||
* @param structure The file to render
|
||||
* @param options The rendering options
|
||||
*/
|
||||
function getAsciiLine(structure: FileStructure,
|
||||
options: GenerateTreeOptions): string | null {
|
||||
const lines = LINE_STRINGS[options.charset as string];
|
||||
|
||||
// Special case for the root element
|
||||
if (!structure.parent) {
|
||||
return options.rootDot ? structure.name : null;
|
||||
}
|
||||
|
||||
const chunks = [
|
||||
isLastChild(structure) ? lines.LAST_CHILD : lines.CHILD,
|
||||
getName(structure, options),
|
||||
];
|
||||
|
||||
let current = structure.parent;
|
||||
while (current && current.parent) {
|
||||
chunks.unshift(isLastChild(current) ? lines.EMPTY : lines.DIRECTORY);
|
||||
current = current.parent;
|
||||
}
|
||||
|
||||
// Join all the chunks together to create the final line.
|
||||
// If we're not rendering the root `.`, chop off the first 4 characters.
|
||||
return chunks.join('').substring(options.rootDot ? 0 : lines.CHILD.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of a file or folder according to the
|
||||
* rules specified by the rendering rules
|
||||
* @param structure The file or folder to get the name of
|
||||
* @param options The rendering options
|
||||
*/
|
||||
function getName(structure: FileStructure,
|
||||
options: GenerateTreeOptions): string {
|
||||
const nameChunks = [structure.name];
|
||||
|
||||
// Optionally append a trailing slash
|
||||
if (
|
||||
// if the trailing slash option is enabled
|
||||
options.trailingDirSlash
|
||||
// and if the item has at least one child
|
||||
&& structure.children.length > 0
|
||||
// and if the item doesn't already have a trailing slash
|
||||
&& !/\/\s*$/.test(structure.name)
|
||||
) {
|
||||
nameChunks.push('/');
|
||||
}
|
||||
|
||||
// Optionally prefix the name with its full path
|
||||
if (options.fullPath && structure.parent && structure.parent) {
|
||||
nameChunks.unshift(
|
||||
getName(
|
||||
structure.parent,
|
||||
defaultsDeep({}, { trailingDirSlash: true }, options),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return nameChunks.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility function do determine if a file or folder
|
||||
* is the last child of its parent
|
||||
* @param structure The file or folder to test
|
||||
*/
|
||||
function isLastChild(structure: FileStructure): boolean {
|
||||
return Boolean(structure.parent && last(structure.parent.children) === structure);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Represents an object that contains the
|
||||
* actual strings used to render the tree
|
||||
*/
|
||||
export interface LineStringSet {
|
||||
/** The string to render immediately before non-last children */
|
||||
CHILD: string
|
||||
|
||||
/** The string to render immediately before the last child */
|
||||
LAST_CHILD: string
|
||||
|
||||
/** The string to render for parent directories */
|
||||
DIRECTORY: string
|
||||
|
||||
/** The string to render for empty space */
|
||||
EMPTY: string
|
||||
}
|
||||
|
||||
/** Contains all strings for tree rendering */
|
||||
export const LINE_STRINGS: { [charset: string]: LineStringSet } = {
|
||||
'ascii': {
|
||||
CHILD: '|-- ',
|
||||
LAST_CHILD: '`-- ',
|
||||
DIRECTORY: '| ',
|
||||
EMPTY: ' ',
|
||||
},
|
||||
'utf-8': {
|
||||
CHILD: '├── ',
|
||||
LAST_CHILD: '└── ',
|
||||
DIRECTORY: '│ ',
|
||||
EMPTY: ' ',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
// not using a template string in order
|
||||
// to have more control over whitespace
|
||||
export const mockInput = [
|
||||
'my-app',
|
||||
' src',
|
||||
' index.html',
|
||||
' main.ts',
|
||||
' main.scss',
|
||||
' - build',
|
||||
' - index.html',
|
||||
' main.js',
|
||||
' main.css',
|
||||
'',
|
||||
' ',
|
||||
' .prettierrc.json',
|
||||
' .gitlab-ci.yml',
|
||||
' README.md',
|
||||
'empty dir',
|
||||
].join('\n');
|
||||
@@ -0,0 +1,147 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { FileStructure } from './FileStructure';
|
||||
import { mockInput } from './mock-input';
|
||||
import { parseInput, splitInput } from './parse-input';
|
||||
|
||||
describe('parse-input', () => {
|
||||
it('parses plain text input into a FileStructure object', () => {
|
||||
const actual = parseInput(mockInput);
|
||||
|
||||
const root: FileStructure = {
|
||||
name: '.',
|
||||
children: [],
|
||||
indentCount: -1,
|
||||
parent: null,
|
||||
};
|
||||
|
||||
const myApp: FileStructure = {
|
||||
name: 'my-app',
|
||||
children: [],
|
||||
indentCount: 0,
|
||||
parent: root,
|
||||
};
|
||||
root.children.push(myApp);
|
||||
|
||||
const src: FileStructure = {
|
||||
name: 'src',
|
||||
children: [],
|
||||
indentCount: 2,
|
||||
parent: myApp,
|
||||
};
|
||||
myApp.children.push(src);
|
||||
|
||||
const srcIndexHtml: FileStructure = {
|
||||
name: 'index.html',
|
||||
children: [],
|
||||
indentCount: 4,
|
||||
parent: src,
|
||||
};
|
||||
src.children.push(srcIndexHtml);
|
||||
|
||||
const mainTs: FileStructure = {
|
||||
name: 'main.ts',
|
||||
children: [],
|
||||
indentCount: 4,
|
||||
parent: src,
|
||||
};
|
||||
src.children.push(mainTs);
|
||||
|
||||
const mainScss: FileStructure = {
|
||||
name: 'main.scss',
|
||||
children: [],
|
||||
indentCount: 3,
|
||||
parent: src,
|
||||
};
|
||||
src.children.push(mainScss);
|
||||
|
||||
const build: FileStructure = {
|
||||
name: 'build',
|
||||
children: [],
|
||||
indentCount: 2,
|
||||
parent: myApp,
|
||||
};
|
||||
myApp.children.push(build);
|
||||
|
||||
const buildIndexHtml: FileStructure = {
|
||||
name: 'index.html',
|
||||
children: [],
|
||||
indentCount: 4,
|
||||
parent: build,
|
||||
};
|
||||
build.children.push(buildIndexHtml);
|
||||
|
||||
const mainJs: FileStructure = {
|
||||
name: 'main.js',
|
||||
children: [],
|
||||
indentCount: 4,
|
||||
parent: build,
|
||||
};
|
||||
build.children.push(mainJs);
|
||||
|
||||
const mainCss: FileStructure = {
|
||||
name: 'main.css',
|
||||
children: [],
|
||||
indentCount: 4,
|
||||
parent: build,
|
||||
};
|
||||
build.children.push(mainCss);
|
||||
|
||||
const prettierRcJson: FileStructure = {
|
||||
name: '.prettierrc.json',
|
||||
children: [],
|
||||
indentCount: 2,
|
||||
parent: myApp,
|
||||
};
|
||||
myApp.children.push(prettierRcJson);
|
||||
|
||||
const gitlabCiYml: FileStructure = {
|
||||
name: '.gitlab-ci.yml',
|
||||
children: [],
|
||||
indentCount: 2,
|
||||
parent: myApp,
|
||||
};
|
||||
myApp.children.push(gitlabCiYml);
|
||||
|
||||
const readmeMd: FileStructure = {
|
||||
name: 'README.md',
|
||||
children: [],
|
||||
indentCount: 2,
|
||||
parent: myApp,
|
||||
};
|
||||
myApp.children.push(readmeMd);
|
||||
|
||||
const emptyDir: FileStructure = {
|
||||
name: 'empty dir',
|
||||
children: [],
|
||||
indentCount: 0,
|
||||
parent: root,
|
||||
};
|
||||
root.children.push(emptyDir);
|
||||
|
||||
expect(actual).toEqual(root);
|
||||
});
|
||||
});
|
||||
|
||||
describe('splitInput', () => {
|
||||
it('splits plain text into an array of File Structure objects', () => {
|
||||
const actual = splitInput(mockInput);
|
||||
|
||||
const expected = [
|
||||
{ name: 'my-app', children: [], indentCount: 0, parent: null },
|
||||
{ name: 'src', children: [], indentCount: 2, parent: null },
|
||||
{ name: 'index.html', children: [], indentCount: 4, parent: null },
|
||||
{ name: 'main.ts', children: [], indentCount: 4, parent: null },
|
||||
{ name: 'main.scss', children: [], indentCount: 3, parent: null },
|
||||
{ name: 'build', children: [], indentCount: 2, parent: null },
|
||||
{ name: 'index.html', children: [], indentCount: 4, parent: null },
|
||||
{ name: 'main.js', children: [], indentCount: 4, parent: null },
|
||||
{ name: 'main.css', children: [], indentCount: 4, parent: null },
|
||||
{ name: '.prettierrc.json', children: [], indentCount: 2, parent: null },
|
||||
{ name: '.gitlab-ci.yml', children: [], indentCount: 2, parent: null },
|
||||
{ name: 'README.md', children: [], indentCount: 2, parent: null },
|
||||
{ name: 'empty dir', children: [], indentCount: 0, parent: null },
|
||||
];
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
import last from 'lodash.last';
|
||||
import type { FileStructure } from './FileStructure';
|
||||
|
||||
/**
|
||||
* Matches the whitespace in front of a file name.
|
||||
* Also will match a markdown bullet point if included.
|
||||
* For example, testing against " - hello" will return
|
||||
* a positive match with the first capturing group
|
||||
* with " - " and a second with " "
|
||||
*/
|
||||
const leadingWhitespaceAndBulletRegex = /^((\s*)(?:-\s)?)/;
|
||||
|
||||
/** Matches lines that only contain whitespace */
|
||||
const onlyWhitespaceRegex = /^\s*$/;
|
||||
|
||||
/** Used to split a block of text into individual lines */
|
||||
const newlineSplitterRegex = /[^\r\n]+/g;
|
||||
|
||||
/**
|
||||
* Translates a block of user-created text into
|
||||
* a nested FileStructure structure
|
||||
* @param input The plain-text input from the user
|
||||
*/
|
||||
export function parseInput(input: string): FileStructure {
|
||||
const structures = splitInput(input);
|
||||
|
||||
const root: FileStructure = {
|
||||
name: '.',
|
||||
children: [],
|
||||
indentCount: -1,
|
||||
parent: null,
|
||||
};
|
||||
|
||||
const path = [root];
|
||||
for (const s of structures) {
|
||||
while (last(path)!.indentCount >= s.indentCount) {
|
||||
path.pop();
|
||||
}
|
||||
|
||||
const parent = last(path) as FileStructure;
|
||||
parent.children.push(s);
|
||||
s.parent = parent;
|
||||
|
||||
path.push(s);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a block of user-created text into
|
||||
* individual, un-nested FileStructure objects.
|
||||
* Used internally as part of `parseInput`.
|
||||
* @param input The plain-text input from the user
|
||||
*/
|
||||
export function splitInput(input: string): FileStructure[] {
|
||||
let lines = input.match(newlineSplitterRegex)?.map(m => m) || [];
|
||||
|
||||
// filter out empty lines
|
||||
lines = lines.filter(l => !onlyWhitespaceRegex.test(l));
|
||||
|
||||
return lines.map((l) => {
|
||||
const matchResult = leadingWhitespaceAndBulletRegex.exec(l);
|
||||
|
||||
if (!matchResult) {
|
||||
throw new Error(
|
||||
`Unable to execute leadingWhitespaceAndBulletRegex against string: "${l}"`,
|
||||
);
|
||||
}
|
||||
|
||||
const name = l.replace(matchResult[1], '');
|
||||
const indentCount = matchResult[2].length;
|
||||
|
||||
return {
|
||||
name,
|
||||
children: [],
|
||||
indentCount,
|
||||
parent: null,
|
||||
};
|
||||
});
|
||||
}
|
||||
+2
-2
@@ -6,7 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
import { tool as textToUnicode } from './text-to-unicode';
|
||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
||||
import { tool as unicodeFormatter } from './unicode-formatter';
|
||||
import { tool as folderStructureDiagram } from './folder-structure-diagram';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -129,6 +129,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
httpStatusCodes,
|
||||
jsonDiff,
|
||||
safelinkDecoder,
|
||||
folderStructureDiagram,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -173,7 +174,6 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
textDiff,
|
||||
numeronymGenerator,
|
||||
asciiTextDrawer,
|
||||
unicodeFormatter,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Edit } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Unicode Formatter',
|
||||
path: '/unicode-formatter',
|
||||
description: 'Format text using Unicode fonts',
|
||||
keywords: ['unicode', 'formatter', 'fonts'],
|
||||
component: () => import('./unicode-formatter.vue'),
|
||||
icon: Edit,
|
||||
createdAt: new Date('2024-04-07'),
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"normal": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",
|
||||
"sans": "\"\\ !#$%&'()*+,-./𝟢𝟣𝟤𝟥𝟦𝟧𝟨𝟩𝟪𝟫:;<=>?@𝖠𝖡𝖢𝖣𝖤𝖥𝖦𝖧𝖨𝖩𝖪𝖫𝖬𝖭𝖮𝖯𝖰𝖱𝖲𝖳𝖴𝖵𝖶𝖷𝖸𝖹[]^_`𝖺𝖻𝖼𝖽𝖾𝖿𝗀𝗁𝗂𝗃𝗄𝗅𝗆𝗇𝗈𝗉𝗊𝗋𝗌𝗍𝗎𝗏𝗐𝗑𝗒𝗓{|}~",
|
||||
"sansBold": "\"\\ !#$%&'()*+,-./𝟬𝟭𝟮𝟯𝟰𝟱𝟲𝟳𝟴𝟵:;<=>?@𝗔𝗕𝗖𝗗𝗘𝗙𝗚𝗛𝗜𝗝𝗞𝗟𝗠𝗡𝗢𝗣𝗤𝗥𝗦𝗧𝗨𝗩𝗪𝗫𝗬𝗭[]^_`𝗮𝗯𝗰𝗱𝗲𝗳𝗴𝗵𝗶𝗷𝗸𝗹𝗺𝗻𝗼𝗽𝗾𝗿𝘀𝘁𝘂𝘃𝘄𝘅𝘆𝘇{|}~",
|
||||
"sansItalic": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@𝘈𝘉𝘊𝘋𝘌𝘍𝘎𝘏𝘐𝘑𝘒𝘓𝘔𝘕𝘖𝘗𝘘𝘙𝘚𝘛𝘜𝘝𝘞𝘟𝘠𝘡[]^_`𝘢𝘣𝘤𝘥𝘦𝘧𝘨𝘩𝘪𝘫𝘬𝘭𝘮𝘯𝘰𝘱𝘲𝘳𝘴𝘵𝘶𝘷𝘸𝘹𝘺𝘻{|}~",
|
||||
"sansBoldItalic": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@𝘼𝘽𝘾𝘿𝙀𝙁𝙂𝙃𝙄𝙅𝙆𝙇𝙈𝙉𝙊𝙋𝙌𝙍𝙎𝙏𝙐𝙑𝙒𝙓𝙔𝙕[]^_`𝙖𝙗𝙘𝙙𝙚𝙛𝙜𝙝𝙞𝙟𝙠𝙡𝙢𝙣𝙤𝙥𝙦𝙧𝙨𝙩𝙪𝙫𝙬𝙭𝙮𝙯{|}~",
|
||||
"monospace": "\"\\ !#$%&'()*+,-./𝟶𝟷𝟸𝟹𝟺𝟻𝟼𝟽𝟾𝟿:;<=>?@𝙰𝙱𝙲𝙳𝙴𝙵𝙶𝙷𝙸𝙹𝙺𝙻𝙼𝙽𝙾𝙿𝚀𝚁𝚂𝚃𝚄𝚅𝚆𝚇𝚈𝚉[]^_`𝚊𝚋𝚌𝚍𝚎𝚏𝚐𝚑𝚒𝚓𝚔𝚕𝚖𝚗𝚘𝚙𝚚𝚛𝚜𝚝𝚞𝚟𝚠𝚡𝚢𝚣{|}~",
|
||||
"fullwidth": "\"\ !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~",
|
||||
"fraktur": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@𝔄𝔅ℭ𝔇𝔈𝔉𝔊ℌℑ𝔍𝔎𝔏𝔐𝔑𝔒𝔓𝔔ℜ𝔖𝔗𝔘𝔙𝔚𝔛𝔜ℨ[]^_`𝔞𝔟𝔠𝔡𝔢𝔣𝔤𝔥𝔦𝔧𝔨𝔩𝔪𝔫𝔬𝔭𝔮𝔯𝔰𝔱𝔲𝔳𝔴𝔵𝔶𝔷{|}~",
|
||||
"boldFraktur": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@𝕬𝕭𝕮𝕯𝕰𝕱𝕲𝕳𝕴𝕵𝕶𝕷𝕸𝕹𝕺𝕻𝕼𝕽𝕾𝕿𝖀𝖁𝖂𝖃𝖄𝖅[]^_`𝖆𝖇𝖈𝖉𝖊𝖋𝖌𝖍𝖎𝖏𝖐𝖑𝖒𝖓𝖔𝖕𝖖𝖗𝖘𝖙𝖚𝖛𝖜𝖝𝖞𝖟{|}~",
|
||||
"serifBold": "\"\\ !#$%&'()*+,-./𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗:;<=>?@𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙[]^_`𝐚𝐛𝐜𝐝𝐞𝐟𝐠𝐡𝐢𝐣𝐤𝐥𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐭𝐮𝐯𝐰𝐱𝐲𝐳{|}~",
|
||||
"serifItalic": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@𝐴𝐵𝐶𝐷𝐸𝐹𝐺𝐻𝐼𝐽𝐾𝐿𝑀𝑁𝑂𝑃𝑄𝑅𝑆𝑇𝑈𝑉𝑊𝑋𝑌𝑍[]^_`𝑎𝑏𝑐𝑑𝑒𝑓𝑔ℎ𝑖𝑗𝑘𝑙𝑚𝑛𝑜𝑝𝑞𝑟𝑠𝑡𝑢𝑣𝑤𝑥𝑦𝑧{|}~",
|
||||
"serifBoldItalic": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@𝑨𝑩𝑪𝑫𝑬𝑭𝑮𝑯𝑰𝑱𝑲𝑳𝑴𝑵𝑶𝑷𝑸𝑹𝑺𝑻𝑼𝑽𝑾𝑿𝒀𝒁[]^_`𝒂𝒃𝒄𝒅𝒆𝒇𝒈𝒉𝒊𝒋𝒌𝒍𝒎𝒏𝒐𝒑𝒒𝒓𝒔𝒕𝒖𝒗𝒘𝒙𝒚𝒛{|}~",
|
||||
"doubleStruck": "\"\\ !#$%&'()*+,-./𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡:;<=>?@𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ[]^_`𝕒𝕓𝕔𝕕𝕖𝕗𝕘𝕙𝕚𝕛𝕜𝕝𝕞𝕟𝕠𝕡𝕢𝕣𝕤𝕥𝕦𝕧𝕨𝕩𝕪𝕫{|}~",
|
||||
"script": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@𝒜ℬ𝒞𝒟ℰℱ𝒢ℋℐ𝒥𝒦ℒℳ𝒩𝒪𝒫𝒬ℛ𝒮𝒯𝒰𝒱𝒲𝒳𝒴𝒵[]^_`𝒶𝒷𝒸𝒹ℯ𝒻ℊ𝒽𝒾𝒿𝓀𝓁𝓂𝓃ℴ𝓅𝓆𝓇𝓈𝓉𝓊𝓋𝓌𝓍𝓎𝓏{|}~",
|
||||
"boldScript": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@𝓐𝓑𝓒𝓓𝓔𝓕𝓖𝓗𝓘𝓙𝓚𝓛𝓜𝓝𝓞𝓟𝓠𝓡𝓢𝓣𝓤𝓥𝓦𝓧𝓨𝓩[]^_`𝓪𝓫𝓬𝓭𝓮𝓯𝓰𝓱𝓲𝓳𝓴𝓵𝓶𝓷𝓸𝓹𝓺𝓻𝓼𝓽𝓾𝓿𝔀𝔁𝔂𝔃{|}~",
|
||||
"circled": "\"⦸ !#$%&'()⊛⊕,⊖⨀⊘⓪①②③④⑤⑥⑦⑧⑨:;⧀⊜⧁?@ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ[]^_`ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ{⦶}~",
|
||||
"circledNegative": "\"\\ !#$%&'()*+,-./⓿❶❷❸❹❺❻❼❽❾:;<=>?@🅐🅑🅒🅓🅔🅕🅖🅗🅘🅙🅚🅛🅜🅝🅞🅟🅠🅡🅢🅣🅤🅥🅦🅧🅨🅩[]^_`🅐🅑🅒🅓🅔🅕🅖🅗🅘🅙🅚🅛🅜🅝🅞🅟🅠🅡🅢🅣🅤🅥🅦🅧🅨🅩{|}~",
|
||||
"squared": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@🄰🄱🄲🄳🄴🄵🄶🄷🄸🄹🄺🄻🄼🄽🄾🄿🅀🅁🅂🅃🅄🅅🅆🅇🅈🅉[]^_`🄰🄱🄲🄳🄴🄵🄶🄷🄸🄹🄺🄻🄼🄽🄾🄿🅀🅁🅂🅃🅄🅅🅆🅇🅈🅉{|}~",
|
||||
"squaredNegative": "\"⧅ !#$%&'()⧆⊞,⊟⊡⧄0123456789:;<=>?@🅰🅱🅲🅳🅴🅵🅶🅷🅸🅹🅺🅻🅼🅽🅾🅿🆀🆁🆂🆃🆄🆅🆆🆇🆈🆉[]^_`🅰🅱🅲🅳🅴🅵🅶🅷🅸🅹🅺🅻🅼🅽🅾🅿🆀🆁🆂🆃🆄🆅🆆🆇🆈🆉{|}~",
|
||||
"parenthesized": "\"\\ !#$%&'()*+,-./0⑴⑵⑶⑷⑸⑹⑺⑻⑼:;<=>?@⒜⒝⒞⒟⒠⒡⒢⒣⒤⒥⒦⒧⒨⒩⒪⒫⒬⒭⒮⒯⒰⒱⒲⒳⒴⒵[]^_`⒜⒝⒞⒟⒠⒡⒢⒣⒤⒥⒦⒧⒨⒩⒪⒫⒬⒭⒮⒯⒰⒱⒲⒳⒴⒵{|}~",
|
||||
"smallCaps": "\"\\ !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴩꞯʀꜱᴛᴜᴠᴡxʏᴢ{|}~",
|
||||
"subscript": "\"\\ !#$%&'₍₎*₊,₋./₀₁₂₃₄₅₆₇₈₉:;<₌>?@ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘ🇶ʀꜱᴛᴜᴠᴡxʏᴢ[]^_`ₐᵦ𝒸𝒹ₑ𝒻𝓰ₕᵢⱼₖₗₘₙₒₚᵩᵣₛₜᵤᵥ𝓌ₓᵧ𝓏{|}~",
|
||||
"superscript": "\"\\ !#$%&'⁽⁾*⁺,⁻./⁰¹²³⁴⁵⁶⁷⁸⁹:;<⁼>?@ᴬᴮᶜᴰᴱᶠᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᵠᴿˢᵀᵁⱽᵂˣʸᶻ[]^_`ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖᵠʳˢᵗᵘᵛʷˣʸᶻ{|}~",
|
||||
"inverted": "„\\ ¡#$%⅋,)(*+‘-˙/0ƖՇƐᔭϛ9𝘓86:;<=>¿@∀ꓭↃꓷƎℲ⅁HIſꓘ⅂WNOԀῸꓤS⊥∩ꓥMX⅄Z][^‾`ɐqɔpǝɟƃɥıɾʞןɯuodbɹsʇnʌʍxʎz}|{~",
|
||||
"mirrored": "\"/ !#$%&')(*+,-.\\0߁ςƐ߂टმ٢8୧:;<=>⸮@AꓭↃꓷƎꟻӘHIႱꓘ⅃MИOꟼϘЯꙄTUVWXYZ][^_`ɒdↄbɘʇϱʜiįʞlmᴎoqpᴙꙅɈυvwxγz}|{~",
|
||||
"rotatedLeft": "=/ !#$%&-⏝⏜*+`ǀ∙\\ⴰ↽വ𝈐ፓහமΓꝏᓂ⠒;˅𝄥∧ᣇ@ᗉߘ𝈱⌓ш𝈯ᘎ⌶𝄩⥟𝈎⨼∑Zⴰᓇⵚᓚᔕ⊢⊃𝈷ᕒ×⤚𝇙⎵⎴‹|`ơᓄ𝈱ᓀш𝈯თ𝈦𝄩ᓜ𝈎⨼ᗴ⊂ⴰᓇᓂᓚᔕ𝀏⊃𝈷З×⤚𝇙⏟_⏞ಽ",
|
||||
"rotatedRight": "=/ !#$%&-⏜⏝*+`ǀ∙\\ⴰ⇀ᘚω𝈦හの⨼ꝏᓄ⠒;∧𝄥˅?@ᗆϖᴒᗜጠ╖ᘏ⌶𝄩ᓚ⌤⌐ᕒZⴰᓀᓄᓓᔕ⊣⊂<ᓬ×⤙𝇙⎴⎵›|`⌕ᓂᴒ௨ጠ╖மፓ𝄩ᓚ⌤⌐ᴟᴝⴰᓀᓄᓓᔕ𝀏⊂<ᓬ×⤙𝇙⏞_⏟ಽ"
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatTextPart } from './unicode-formatter.service';
|
||||
|
||||
describe('unicode-formatter', () => {
|
||||
it('formatTextPart applies correct style/font on text part', async () => {
|
||||
expect(formatTextPart('The quick fox', 4, 9, 'sansBold')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The 𝗾𝘂𝗶𝗰𝗸 fox',
|
||||
to: 14,
|
||||
});
|
||||
expect(formatTextPart('The quick fox', 4, 13, 'boldScript')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The 𝓺𝓾𝓲𝓬𝓴 𝓯𝓸𝔁',
|
||||
to: 21,
|
||||
});
|
||||
expect(formatTextPart('The quick fox', 4, 6, 'smallCaps')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The ꞯᴜick fox',
|
||||
to: 6,
|
||||
});
|
||||
expect(formatTextPart('The quick fox', 4, 8, 'inverted')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The bnıɔk fox',
|
||||
to: 8,
|
||||
});
|
||||
expect(formatTextPart('The quick fox', 4, 10, 'mirrored')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The pυiↄʞ fox',
|
||||
to: 10,
|
||||
});
|
||||
expect(formatTextPart('The quick fox', 4, 11, 'serifBoldItalic')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The 𝒒𝒖𝒊𝒄𝒌 𝒇ox',
|
||||
to: 17,
|
||||
});
|
||||
});
|
||||
|
||||
it('formatTextPart un-applies correct style/font on text part', async () => {
|
||||
expect(formatTextPart('The 𝗾𝘂𝗶𝗰𝗸 fox', 4, 14, 'sansBold')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The quick fox',
|
||||
to: 9,
|
||||
});
|
||||
expect(formatTextPart('The 𝓺𝓾𝓲𝓬𝓴 𝓯𝓸𝔁', 4, 18, 'boldScript')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The quick f𝓸𝔁',
|
||||
to: 12,
|
||||
});
|
||||
expect(formatTextPart('The 𝓺𝓾𝓲𝓬𝓴 𝓯𝓸𝔁', 4, 14, 'boldScript')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The quick 𝓯𝓸𝔁',
|
||||
to: 9,
|
||||
});
|
||||
expect(formatTextPart('The 𝓺𝓾𝓲𝓬𝓴 fox', 4, 15, 'boldScript')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The quick fox',
|
||||
to: 10,
|
||||
});
|
||||
expect(formatTextPart('The pυiↄʞ fox', 4, 10, 'mirrored')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The puick fox', // can't be fully restored
|
||||
to: 10,
|
||||
});
|
||||
expect(formatTextPart('The bnıɔk fox', 4, 10, 'inverted')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The quıɔʞ fox',
|
||||
to: 10,
|
||||
});
|
||||
expect(formatTextPart('The 𝒒𝒖𝒊𝒄𝒌 𝒇ox', 4, 17, 'serifBoldItalic')).to.deep.equal({
|
||||
from: 4,
|
||||
text: 'The quick fox',
|
||||
to: 11,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,103 +0,0 @@
|
||||
// prettier-ignore
|
||||
import fonts from './unicode-fonts.json';
|
||||
|
||||
export type AllFontNames = keyof typeof fonts;
|
||||
export interface AllOptions {
|
||||
remove?: string
|
||||
append?: string
|
||||
reverse?: boolean
|
||||
clear?: boolean
|
||||
};
|
||||
|
||||
// list of font characters for checking if character is formatted
|
||||
const allCharacters = new Set(Object.values(fonts).join(''));
|
||||
|
||||
// check if text is already formatted with a certain font
|
||||
function alreadyFormatted(text: string, font: AllFontNames) {
|
||||
const fontCharacters = new Set(fonts[font]);
|
||||
// flag as already formatted if all characters are in font or not in any other font
|
||||
return Array.from(text).every(char => fontCharacters.has(char) || !allCharacters.has(char));
|
||||
}
|
||||
|
||||
// check if text is already formatted with a certain font
|
||||
function alreadyAppended(text: string, append: string) {
|
||||
// check if at least half the characters are the append character
|
||||
return Array.from(text).filter(char => char === append).length >= text.length / 2;
|
||||
}
|
||||
|
||||
// format text into selected font
|
||||
function formatText(text: string, font: AllFontNames | undefined, options?: AllOptions) {
|
||||
// set font to normal if already formatted with selected font
|
||||
if (font && fonts[font] && alreadyFormatted(text, font)) {
|
||||
font = 'normal';
|
||||
}
|
||||
// remove and don't append if character is already appended
|
||||
if (options?.append) {
|
||||
options.remove = options.append;
|
||||
options.append = !alreadyAppended(text, options.append) ? options.append : '';
|
||||
}
|
||||
// Array.from() splits the string by symbol and not by code points
|
||||
let newText = Array.from(text);
|
||||
// exchange font symbols
|
||||
if (font && fonts[font]) {
|
||||
const targetFont = Array.from(fonts[font]);
|
||||
const charLists = Object.values(fonts);
|
||||
// map characters to new font
|
||||
newText = newText.map((char) => {
|
||||
let index = -1;
|
||||
// find the index of the character in some font
|
||||
const found = charLists.some((charList) => {
|
||||
index = Array.from(charList).indexOf(char);
|
||||
return index > -1;
|
||||
});
|
||||
// if found, replace with the corresponding character in the target font
|
||||
// if not found, keep the character the same
|
||||
return found ? targetFont[index] : char;
|
||||
});
|
||||
}
|
||||
// reverse text if reverse option is set
|
||||
newText = options?.reverse ? newText.reverse() : newText;
|
||||
// remove appended symbol of specific type from the end
|
||||
newText = options?.remove
|
||||
? newText.map(char => char.replace(new RegExp(`${options.remove}$`, 'u'), ''))
|
||||
: newText;
|
||||
// append symbol (underline, strikethrough, etc.) to end of each character if append is set
|
||||
newText = options?.append ? newText.map(char => char + options.append) : newText;
|
||||
// remove appended symbols (underline, strikethrough, etc.) if using eraser
|
||||
// \u035f = Underline, \u0333 = Double Underline, \u0335 = Short Strikethrough \u0336 = Strikethrough
|
||||
newText = options?.clear ? newText.map(char => char.replace(/\u035F|\u0333|\u0335|\u0336/gu, '')) : newText;
|
||||
// set textarea content and select text around the replacement
|
||||
return newText.join('');
|
||||
}
|
||||
|
||||
export function formatTextPart(
|
||||
text: string,
|
||||
selectionStart: number, selectionEnd: number,
|
||||
font: AllFontNames | undefined,
|
||||
options?: AllOptions) {
|
||||
const regexSpaces = /^(\s*)(.+?)(\s*)$/g; // NOSONAR
|
||||
const [_, spaceBefore, selection, spaceAfter] = regexSpaces.exec(text.substring(selectionStart, selectionEnd) || '') || [];
|
||||
|
||||
const prefix = text.substring(0, selectionStart);
|
||||
const newSelection = formatText(selection, font, options);
|
||||
const suffix = text.substring(selectionEnd);
|
||||
return {
|
||||
text: `${prefix}${spaceBefore}${newSelection}${spaceAfter}${suffix}`,
|
||||
from: selectionStart,
|
||||
to: selectionStart + (spaceBefore?.length || 0) + newSelection.length + (spaceAfter?.length || 0),
|
||||
};
|
||||
}
|
||||
|
||||
// format selected text
|
||||
export function formatSelection(textArea: HTMLTextAreaElement, font: AllFontNames | undefined, options?: AllOptions) {
|
||||
const selectionStart = textArea.selectionStart;
|
||||
const selectionEnd = textArea.selectionEnd;
|
||||
const oldText = textArea.value;
|
||||
|
||||
const { text: newText, from, to } = formatTextPart(oldText, selectionStart, selectionEnd, font, options);
|
||||
|
||||
textArea.value = newText;
|
||||
textArea.setSelectionRange(from, to);
|
||||
|
||||
textArea.focus();
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
// import {AllFontNames,AllOptions, bold,italic,monospace,strikethrough,underline,superscript,subscript,formatSelections} from './unicod'
|
||||
import { Copy } from '@vicons/tabler';
|
||||
import type { AllFontNames, AllOptions } from './unicode-formatter.service';
|
||||
import { formatSelection } from './unicode-formatter.service';
|
||||
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const textArea = ref<HTMLTextAreaElement>();
|
||||
function formatTextAreaSelection(format: AllFontNames | undefined, options: AllOptions) {
|
||||
if (!textArea.value) {
|
||||
return;
|
||||
}
|
||||
formatSelection(textArea.value, format, options);
|
||||
}
|
||||
|
||||
const formattedText = ref('Type your text here and 𝗳𝗼𝗿𝗺𝗮𝘁 it by highlighting the text you want to format and clicking one of the buttons above. Click "More fonts" to show more Unicode fonts. The eraser button will convert your selection back to normal text.');
|
||||
|
||||
const { copy: copyFormattedText } = useCopy({ source: formattedText, text: 'Formatted text copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Google Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
|
||||
|
||||
<div
|
||||
max-w-600
|
||||
style="font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;"
|
||||
>
|
||||
<!-- First set of buttons -->
|
||||
<n-form-item label="Fonts:" mb-3 mt-3 w-full>
|
||||
<n-button title="Normal" @click="formatTextAreaSelection('normal', { clear: true })">
|
||||
<!-- Eraser Icon -->
|
||||
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M2.586,15.408l4.299,4.299C7.072,19.895,7.326,20,7.592,20h0.001h2h0.4h9.6v-2h-6.958l7.222-7.222 c0.78-0.779,0.78-2.049,0-2.828L14.906,3c-0.779-0.779-2.049-0.779-2.828,0l-4.75,4.749l-4.754,4.843 C1.809,13.371,1.813,14.634,2.586,15.408z M13.492,4.414l4.95,4.95l-2.586,2.586L10.906,7L13.492,4.414z M8.749,9.156l0.743-0.742 l4.95,4.95l-4.557,4.557C9.86,17.946,9.838,17.973,9.816,18H9.593H8.006l-4.005-4.007L8.749,9.156z" />
|
||||
</svg>
|
||||
</n-button>
|
||||
<n-button title="Bold" @click="formatTextAreaSelection('sansBold', { })">
|
||||
𝗕
|
||||
</n-button>
|
||||
<n-button title="Italic" @click="formatTextAreaSelection('sansItalic', { })">
|
||||
𝘐
|
||||
</n-button>
|
||||
<n-button title="Monospace" @click="formatTextAreaSelection('monospace', { })">
|
||||
𝙼
|
||||
</n-button>
|
||||
<n-button style="text-decoration: underline" @click="formatTextAreaSelection(undefined, { append: '͟' })">
|
||||
U
|
||||
</n-button>
|
||||
<n-button style="text-decoration: line-through" @click="formatTextAreaSelection(undefined, { append: '̶' })">
|
||||
S
|
||||
</n-button>
|
||||
</n-form-item>
|
||||
|
||||
<!-- Collapsible section with more buttons -->
|
||||
<details style="display:block" borders mb-3 w-full>
|
||||
<summary>More fonts</summary>
|
||||
<n-space mt-3 w-full>
|
||||
<n-button title="Math Sans" @click="formatTextAreaSelection('sans', { })">
|
||||
𝖬
|
||||
</n-button>
|
||||
<n-button title="Sans Bold italic" @click="formatTextAreaSelection('sansBoldItalic', { })">
|
||||
𝘽𝙄
|
||||
</n-button>
|
||||
<n-button title="Serif bold" @click="formatTextAreaSelection('serifBold', { })">
|
||||
𝐁
|
||||
</n-button>
|
||||
<n-button title="Serif italic" @click="formatTextAreaSelection('serifItalic', { })">
|
||||
𝐼
|
||||
</n-button>
|
||||
<n-button title="Serif bold italic" @click="formatTextAreaSelection('serifBoldItalic', { })">
|
||||
𝑩𝑰
|
||||
</n-button>
|
||||
<n-button title="Double Underline" @click="formatTextAreaSelection(undefined, { append: '̳' })">
|
||||
U̳
|
||||
</n-button>
|
||||
<n-button title="Short Strikethrough" style="text-decoration: line-through" @click="formatTextAreaSelection(undefined, { append: '̵' })">
|
||||
S̵
|
||||
</n-button>
|
||||
<n-button title="Math double-struck" @click="formatTextAreaSelection('doubleStruck', { })">
|
||||
𝔻
|
||||
</n-button>
|
||||
<n-button title="Fullwidth" @click="formatTextAreaSelection('fullwidth', { })">
|
||||
F
|
||||
</n-button>
|
||||
<n-button title="Math Fraktur" @click="formatTextAreaSelection('fraktur', { })">
|
||||
𝔉
|
||||
</n-button>
|
||||
<n-button title="Math Fraktur bold" @click="formatTextAreaSelection('boldFraktur', { })">
|
||||
𝕱
|
||||
</n-button>
|
||||
<n-button title="Script" @click="formatTextAreaSelection('script', { })">
|
||||
𝒮
|
||||
</n-button>
|
||||
<n-button title="Bold script" @click="formatTextAreaSelection('boldScript', { })">
|
||||
𝓢
|
||||
</n-button>
|
||||
<n-button title="Circled" @click="formatTextAreaSelection('circled', { })">
|
||||
Ⓒ
|
||||
</n-button>
|
||||
<n-button title="Circled negative" @click="formatTextAreaSelection('circledNegative', { })">
|
||||
🅒
|
||||
</n-button>
|
||||
<n-button title="Squared" @click="formatTextAreaSelection('squared', { })">
|
||||
🅂
|
||||
</n-button>
|
||||
<n-button title="Squared negative" @click="formatTextAreaSelection('squaredNegative', { })">
|
||||
🆂
|
||||
</n-button>
|
||||
<n-button title="Parenthesized" @click="formatTextAreaSelection('parenthesized', { })">
|
||||
⒫
|
||||
</n-button>
|
||||
<n-button title="Small caps" @click="formatTextAreaSelection('smallCaps', { })">
|
||||
Aʙ
|
||||
</n-button>
|
||||
<n-button title="Subscript" @click="formatTextAreaSelection('subscript', { })">
|
||||
ₛᵤᵦ
|
||||
</n-button>
|
||||
<n-button title="Superscript" @click="formatTextAreaSelection('superscript', { })">
|
||||
ˢᵘᵖ
|
||||
</n-button>
|
||||
<n-button title="Inverted" @click="formatTextAreaSelection('inverted', { })">
|
||||
∀
|
||||
</n-button>
|
||||
<n-button title="Rotated Left" @click="formatTextAreaSelection('rotatedLeft', { })">
|
||||
ᗉ
|
||||
</n-button>
|
||||
<n-button title="Rotated Right" @click="formatTextAreaSelection('rotatedRight', { })">
|
||||
ᗆ
|
||||
</n-button>
|
||||
<n-button title="Mirrored" @click="formatTextAreaSelection('mirrored', { })">
|
||||
Я
|
||||
</n-button>
|
||||
<n-button title="Reverse" @click="formatTextAreaSelection(undefined, { reverse: true })">
|
||||
<!-- Left/Right Arrow Icon -->
|
||||
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M0 168v-16c0-13.255 10.745-24 24-24h360V80c0-21.367 25.899-32.042 40.971-16.971l80 80c9.372 9.373 9.372 24.569 0 33.941l-80 80C409.956 271.982 384 261.456 384 240v-48H24c-13.255 0-24-10.745-24-24zm488 152H128v-48c0-21.314-25.862-32.08-40.971-16.971l-80 80c-9.372 9.373-9.372 24.569 0 33.941l80 80C102.057 463.997 128 453.437 128 432v-48h360c13.255 0 24-10.745 24-24v-16c0-13.255-10.745-24-24-24z" />
|
||||
</svg>
|
||||
</n-button>
|
||||
<n-button title="Inverted Reverse" @click="formatTextAreaSelection('inverted', { reverse: true })">
|
||||
∀
|
||||
<!-- Left/Right Arrow Icon -->
|
||||
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M377.941 169.941V216H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 239.029c-9.373 9.373-9.373 24.568 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296h243.882v46.059c0 21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.568 0-33.941l-86.059-86.059c-15.119-15.12-40.971-4.412-40.971 16.97z" />
|
||||
</svg>
|
||||
</n-button>
|
||||
<n-button title="Rotated Right Reverse" @click="formatTextAreaSelection('rotatedRight', { reverse: true })">
|
||||
ᗆ
|
||||
<!-- Left/Right Arrow Icon -->
|
||||
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M377.941 169.941V216H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 239.029c-9.373 9.373-9.373 24.568 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296h243.882v46.059c0 21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.568 0-33.941l-86.059-86.059c-15.119-15.12-40.971-4.412-40.971 16.97z" />
|
||||
</svg>
|
||||
</n-button>
|
||||
<n-button title="Mirrored Reverse" @click="formatTextAreaSelection('mirrored', { reverse: true })">
|
||||
Я
|
||||
<!-- Left/Right Arrow Icon -->
|
||||
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M377.941 169.941V216H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 239.029c-9.373 9.373-9.373 24.568 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296h243.882v46.059c0 21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.568 0-33.941l-86.059-86.059c-15.119-15.12-40.971-4.412-40.971 16.97z" />
|
||||
</svg>
|
||||
</n-button>
|
||||
</n-space>
|
||||
</details>
|
||||
|
||||
<textarea
|
||||
ref="textArea" :value="formattedText" rows="12" mb-3 mt-3 w-full
|
||||
spellcheck="false"
|
||||
style="font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;"
|
||||
/>
|
||||
|
||||
<div text-center>
|
||||
<c-button @click="copyFormattedText()">
|
||||
<n-icon size="22">
|
||||
<Copy />
|
||||
</n-icon>
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user