mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 14:50:17 +03:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8371d208b1 | ||
|
|
3f7745de2c | ||
|
|
cb37d5837f | ||
|
|
786991433a | ||
|
|
d92a285cb2 | ||
|
|
4c014a63e1 | ||
|
|
dbfe5113b0 | ||
|
|
e32d38c057 |
No files matched your search
@@ -286,9 +286,6 @@
|
||||
"watchTriggerable": true,
|
||||
"watchWithFilter": true,
|
||||
"whenever": true,
|
||||
"toValue": true,
|
||||
"injectLocal": true,
|
||||
"provideLocal": true,
|
||||
"useClipboardItems": true
|
||||
"toValue": true
|
||||
}
|
||||
}
|
||||
Vendored
-9
@@ -36,7 +36,6 @@ declare global {
|
||||
const h: typeof import('vue')['h']
|
||||
const ignorableWatch: typeof import('@vueuse/core')['ignorableWatch']
|
||||
const inject: typeof import('vue')['inject']
|
||||
const injectLocal: typeof import('@vueuse/core')['injectLocal']
|
||||
const isDefined: typeof import('@vueuse/core')['isDefined']
|
||||
const isProxy: typeof import('vue')['isProxy']
|
||||
const isReactive: typeof import('vue')['isReactive']
|
||||
@@ -66,7 +65,6 @@ declare global {
|
||||
const onUpdated: typeof import('vue')['onUpdated']
|
||||
const pausableWatch: typeof import('@vueuse/core')['pausableWatch']
|
||||
const provide: typeof import('vue')['provide']
|
||||
const provideLocal: typeof import('@vueuse/core')['provideLocal']
|
||||
const reactify: typeof import('@vueuse/core')['reactify']
|
||||
const reactifyObject: typeof import('@vueuse/core')['reactifyObject']
|
||||
const reactive: typeof import('vue')['reactive']
|
||||
@@ -130,7 +128,6 @@ declare global {
|
||||
const useBrowserLocation: typeof import('@vueuse/core')['useBrowserLocation']
|
||||
const useCached: typeof import('@vueuse/core')['useCached']
|
||||
const useClipboard: typeof import('@vueuse/core')['useClipboard']
|
||||
const useClipboardItems: typeof import('@vueuse/core')['useClipboardItems']
|
||||
const useCloned: typeof import('@vueuse/core')['useCloned']
|
||||
const useColorMode: typeof import('@vueuse/core')['useColorMode']
|
||||
const useConfirmDialog: typeof import('@vueuse/core')['useConfirmDialog']
|
||||
@@ -329,7 +326,6 @@ declare module 'vue' {
|
||||
readonly h: UnwrapRef<typeof import('vue')['h']>
|
||||
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
|
||||
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
||||
readonly injectLocal: UnwrapRef<typeof import('@vueuse/core')['injectLocal']>
|
||||
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
|
||||
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
||||
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
||||
@@ -359,7 +355,6 @@ declare module 'vue' {
|
||||
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
||||
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
|
||||
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
||||
readonly provideLocal: UnwrapRef<typeof import('@vueuse/core')['provideLocal']>
|
||||
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
|
||||
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
|
||||
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
|
||||
@@ -423,7 +418,6 @@ declare module 'vue' {
|
||||
readonly useBrowserLocation: UnwrapRef<typeof import('@vueuse/core')['useBrowserLocation']>
|
||||
readonly useCached: UnwrapRef<typeof import('@vueuse/core')['useCached']>
|
||||
readonly useClipboard: UnwrapRef<typeof import('@vueuse/core')['useClipboard']>
|
||||
readonly useClipboardItems: UnwrapRef<typeof import('@vueuse/core')['useClipboardItems']>
|
||||
readonly useCloned: UnwrapRef<typeof import('@vueuse/core')['useCloned']>
|
||||
readonly useColorMode: UnwrapRef<typeof import('@vueuse/core')['useColorMode']>
|
||||
readonly useConfirmDialog: UnwrapRef<typeof import('@vueuse/core')['useConfirmDialog']>
|
||||
@@ -616,7 +610,6 @@ declare module '@vue/runtime-core' {
|
||||
readonly h: UnwrapRef<typeof import('vue')['h']>
|
||||
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
|
||||
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
||||
readonly injectLocal: UnwrapRef<typeof import('@vueuse/core')['injectLocal']>
|
||||
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
|
||||
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
||||
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
||||
@@ -646,7 +639,6 @@ declare module '@vue/runtime-core' {
|
||||
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
||||
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
|
||||
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
||||
readonly provideLocal: UnwrapRef<typeof import('@vueuse/core')['provideLocal']>
|
||||
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
|
||||
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
|
||||
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
|
||||
@@ -710,7 +702,6 @@ declare module '@vue/runtime-core' {
|
||||
readonly useBrowserLocation: UnwrapRef<typeof import('@vueuse/core')['useBrowserLocation']>
|
||||
readonly useCached: UnwrapRef<typeof import('@vueuse/core')['useCached']>
|
||||
readonly useClipboard: UnwrapRef<typeof import('@vueuse/core')['useClipboard']>
|
||||
readonly useClipboardItems: UnwrapRef<typeof import('@vueuse/core')['useClipboardItems']>
|
||||
readonly useCloned: UnwrapRef<typeof import('@vueuse/core')['useCloned']>
|
||||
readonly useColorMode: UnwrapRef<typeof import('@vueuse/core')['useColorMode']>
|
||||
readonly useConfirmDialog: UnwrapRef<typeof import('@vueuse/core')['useConfirmDialog']>
|
||||
|
||||
Vendored
+8
-7
@@ -23,7 +23,6 @@ declare module '@vue/runtime-core' {
|
||||
CAlert: typeof import('./src/ui/c-alert/c-alert.vue')['default']
|
||||
'CAlert.demo': typeof import('./src/ui/c-alert/c-alert.demo.vue')['default']
|
||||
CameraRecorder: typeof import('./src/tools/camera-recorder/camera-recorder.vue')['default']
|
||||
CardPicker: typeof import('./src/tools/card-picker/card-picker.vue')['default']
|
||||
CaseConverter: typeof import('./src/tools/case-converter/case-converter.vue')['default']
|
||||
CButton: typeof import('./src/ui/c-button/c-button.vue')['default']
|
||||
'CButton.demo': typeof import('./src/ui/c-button/c-button.demo.vue')['default']
|
||||
@@ -51,7 +50,6 @@ declare module '@vue/runtime-core' {
|
||||
'CModal.demo': typeof import('./src/ui/c-modal/c-modal.demo.vue')['default']
|
||||
CModalValue: typeof import('./src/ui/c-modal-value/c-modal-value.vue')['default']
|
||||
'CModalValue.demo': typeof import('./src/ui/c-modal-value/c-modal-value.demo.vue')['default']
|
||||
CoinFlipper: typeof import('./src/tools/coin-flipper/coin-flipper.vue')['default']
|
||||
CollapsibleToolMenu: typeof import('./src/components/CollapsibleToolMenu.vue')['default']
|
||||
ColorConverter: typeof import('./src/tools/color-converter/color-converter.vue')['default']
|
||||
ColoredCard: typeof import('./src/components/ColoredCard.vue')['default']
|
||||
@@ -70,7 +68,6 @@ declare module '@vue/runtime-core' {
|
||||
'DemoHome.page': typeof import('./src/ui/demo/demo-home.page.vue')['default']
|
||||
DemoWrapper: typeof import('./src/ui/demo/demo-wrapper.vue')['default']
|
||||
DeviceInformation: typeof import('./src/tools/device-information/device-information.vue')['default']
|
||||
DiceRoller: typeof import('./src/tools/dice-roller/dice-roller.vue')['default']
|
||||
DiffViewer: typeof import('./src/tools/json-diff/diff-viewer/diff-viewer.vue')['default']
|
||||
DockerRunToDockerComposeConverter: typeof import('./src/tools/docker-run-to-docker-compose-converter/docker-run-to-docker-compose-converter.vue')['default']
|
||||
DynamicValues: typeof import('./src/tools/benchmark-builder/dynamic-values.vue')['default']
|
||||
@@ -83,7 +80,6 @@ declare module '@vue/runtime-core' {
|
||||
EtaCalculator: typeof import('./src/tools/eta-calculator/eta-calculator.vue')['default']
|
||||
FavoriteButton: typeof import('./src/components/FavoriteButton.vue')['default']
|
||||
FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default']
|
||||
FortuneWheel: typeof import('./src/tools/fortune-wheel/fortune-wheel.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']
|
||||
HashText: typeof import('./src/tools/hash-text/hash-text.vue')['default']
|
||||
@@ -125,7 +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']
|
||||
MarkdownTocGenerator: typeof import('./src/tools/markdown-toc-generator/markdown-toc-generator.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']
|
||||
@@ -133,26 +129,31 @@ declare module '@vue/runtime-core' {
|
||||
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||
NA: typeof import('naive-ui')['NA']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NColorPicker: typeof import('naive-ui')['NColorPicker']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NForm: typeof import('naive-ui')['NForm']
|
||||
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']
|
||||
NImage: typeof import('naive-ui')['NImage']
|
||||
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']
|
||||
NP: typeof import('naive-ui')['NP']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
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']
|
||||
|
||||
+2
-3
@@ -37,7 +37,6 @@
|
||||
"release": "node ./scripts/release.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dice-roller/rpg-dice-roller": "^5.5.1",
|
||||
"@it-tools/bip39": "^0.0.4",
|
||||
"@it-tools/oggen": "^1.3.0",
|
||||
"@regexper/render": "^1.0.0",
|
||||
@@ -53,7 +52,6 @@
|
||||
"@vueuse/core": "^10.3.0",
|
||||
"@vueuse/head": "^1.0.0",
|
||||
"@vueuse/router": "^10.0.0",
|
||||
"@younestouati/playing-cards-standard-deck": "^6.0.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"change-case": "^4.1.2",
|
||||
"colord": "^2.9.3",
|
||||
@@ -90,6 +88,7 @@
|
||||
"pinia": "^2.0.34",
|
||||
"plausible-tracker": "^0.3.8",
|
||||
"qrcode": "^1.5.1",
|
||||
"sanitize-html": "^2.13.1",
|
||||
"randexp": "^0.5.3",
|
||||
"sql-formatter": "^13.0.0",
|
||||
"ua-parser-js": "^1.0.35",
|
||||
@@ -102,7 +101,6 @@
|
||||
"vue-router": "^4.1.6",
|
||||
"vue-shadow-dom": "^4.2.0",
|
||||
"vue-tsc": "^1.8.1",
|
||||
"vue3-fortune-wheel": "^2.0.5",
|
||||
"vuedraggable": "^4.1.0",
|
||||
"xml-formatter": "^3.3.2",
|
||||
"xml-js": "^1.6.11",
|
||||
@@ -125,6 +123,7 @@
|
||||
"@types/node": "^18.15.11",
|
||||
"@types/node-forge": "^1.3.2",
|
||||
"@types/qrcode": "^1.5.0",
|
||||
"@types/sanitize-html": "^2.13.0",
|
||||
"@types/ua-parser-js": "^0.7.36",
|
||||
"@types/uuid": "^9.0.0",
|
||||
"@unocss/eslint-config": "^0.57.0",
|
||||
|
||||
Generated
+2366
-2854
File diff suppressed because it is too large.
Load diff
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
@@ -128,7 +128,7 @@ function activateOption(option: PaletteOption) {
|
||||
<c-input-text ref="inputRef" v-model:value="searchPrompt" raw-text placeholder="Type to search a tool or a command..." autofocus clearable />
|
||||
|
||||
<div v-for="(options, category) in filteredSearchResult" :key="category">
|
||||
<div ml-3 mt-3 text-sm text-primary font-bold op-60>
|
||||
<div ml-3 mt-3 text-sm font-bold text-primary op-60>
|
||||
{{ category }}
|
||||
</div>
|
||||
<command-palette-option v-for="option in options" :key="option.name" :option="option" :selected="selectedOptionIndex === getOptionIndex(option)" @activated="activateOption" />
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import cards from '@younestouati/playing-cards-standard-deck';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { randIntFromInterval } from '@/utils/random';
|
||||
|
||||
const cardKeys = Object.keys(cards);
|
||||
type CardNames = keyof typeof cards;
|
||||
|
||||
const numberOfCards = useQueryParamOrStorage({ name: 'cards', storageName: 'card-picker:n', defaultValue: 5 });
|
||||
const [cardPicked, refreshCardPicked] = computedRefreshable(() =>
|
||||
Array.from({ length: numberOfCards.value },
|
||||
() => cardKeys[randIntFromInterval(0, 51)]));
|
||||
|
||||
const suitNames = {
|
||||
c: 'clubs (♣)',
|
||||
d: 'diamonds (♦)',
|
||||
h: 'hearts (♥)',
|
||||
s: 'spades (♠)',
|
||||
};
|
||||
const numberNames = {
|
||||
1: 'Ace',
|
||||
11: 'Jack',
|
||||
12: 'Queen',
|
||||
13: 'King',
|
||||
};
|
||||
function translateName(cardId: string) {
|
||||
const [, number, suit] = /(\d+)([cdhs])/.exec(cardId) || [];
|
||||
if (!number && !suit) {
|
||||
return cardId;
|
||||
}
|
||||
return `${numberNames[number as never] || number} of ${suitNames[suit as never] || suit}`;
|
||||
}
|
||||
|
||||
const cardPickedString = computed(() => cardPicked.value.map(translateName).join(', '));
|
||||
|
||||
const { copy } = useCopy({ source: cardPickedString, text: 'Cards Picked copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card>
|
||||
<div mb-2 flex justify-center>
|
||||
<img v-for="(card, index) in cardPicked" :key="index" style="width:90px" mr-1 :src="`data:image/svg+xml;base64,${cards[card as CardNames]}`">
|
||||
</div>
|
||||
<div mb-2>
|
||||
<textarea-copyable :value="cardPickedString" readonly mb-1 />
|
||||
</div>
|
||||
<div flex justify-center gap-3>
|
||||
<n-form-item label="Number of cards:" label-placement="left">
|
||||
<n-input-number v-model:value="numberOfCards" min="1" placeholder="Width of the text" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<div flex justify-center gap-3>
|
||||
<c-button @click="copy()">
|
||||
Copy deck
|
||||
</c-button>
|
||||
<c-button @click="refreshCardPicked">
|
||||
Refresh deck
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { PlayCard } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Card Picker',
|
||||
path: '/card-picker',
|
||||
description: 'Generate a deck of playing cards',
|
||||
keywords: ['card', 'deck', 'picker'],
|
||||
component: () => import('./card-picker.vue'),
|
||||
icon: PlayCard,
|
||||
createdAt: new Date('2025-02-09'),
|
||||
});
|
||||
@@ -1,46 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
import { randIntFromInterval } from '@/utils/random';
|
||||
|
||||
const [coinFlip, refreshCoinFlip] = computedRefreshable(() => ({
|
||||
coin: randIntFromInterval(0, 10) % 2 === 0 ? 'Heads' : 'Tails',
|
||||
dt: Date.now(),
|
||||
}));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<Transition name="bounce" mode="out-in">
|
||||
<div :key="coinFlip.dt" flex items-center justify-center>
|
||||
<div flex items-center justify-center rounded-full outline style="width: 5em; height: 5em">
|
||||
{{ coinFlip.coin }}
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
<div mt-4 flex justify-center>
|
||||
<c-button @click="refreshCoinFlip">
|
||||
Re flip
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.bounce-enter-active {
|
||||
animation: bounce-in 0.5s;
|
||||
}
|
||||
.bounce-leave-active {
|
||||
animation: bounce-in 0.5s reverse;
|
||||
}
|
||||
@keyframes bounce-in {
|
||||
0% {
|
||||
transform: scale(0);
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.25);
|
||||
}
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Coin } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Coin Flipper',
|
||||
path: '/coin-flipper',
|
||||
description: 'Flip a coin',
|
||||
keywords: ['coin', 'flipper'],
|
||||
component: () => import('./coin-flipper.vue'),
|
||||
icon: Coin,
|
||||
createdAt: new Date('2025-02-09'),
|
||||
});
|
||||
@@ -1,66 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { DiceRoll } from '@dice-roller/rpg-dice-roller';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
|
||||
const dicesNotations = useQueryParamOrStorage({ name: 'dices', storageName: 'dice-roll:dices', defaultValue: '3d6' });
|
||||
const [diceRollResult, refreshDiceRollResult] = computedRefreshable(() => {
|
||||
try {
|
||||
return {
|
||||
error: '',
|
||||
roll: new DiceRoll(dicesNotations.value),
|
||||
};
|
||||
}
|
||||
catch (e: any) {
|
||||
return {
|
||||
error: e.toString(),
|
||||
roll: null,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
const diceRollString = computed(() => diceRollResult.value.roll?.output || '');
|
||||
|
||||
const { copy } = useCopy({ source: diceRollString, text: 'Dice Roll copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card>
|
||||
<c-input-text
|
||||
v-model:value="dicesNotations"
|
||||
label="Dice Roll Notations:" label-position="left"
|
||||
placeholder="Dice configuration"
|
||||
mb-2
|
||||
/>
|
||||
<n-p mb-2>
|
||||
For more information about Dice Notation, see <n-a href="https://dice-roller.github.io/documentation/guide/notation/" target="_blank">
|
||||
here
|
||||
</n-a>
|
||||
</n-p>
|
||||
|
||||
<c-alert v-if="diceRollResult.error" mb-2>
|
||||
{{ diceRollResult.error }}
|
||||
</c-alert>
|
||||
|
||||
<c-card v-if="!diceRollResult.error" title="Roll Result" mb-2>
|
||||
<input-copyable :value="diceRollResult.roll?.output" readonly mb-1 />
|
||||
<input-copyable :value="diceRollResult.roll?.total" label="Total" readonly placeholder="Dice Roll total:" label-position="left" mb-1 />
|
||||
</c-card>
|
||||
|
||||
<div mb-2 flex justify-center gap-3>
|
||||
<c-button @click="copy()">
|
||||
Copy roll result
|
||||
</c-button>
|
||||
<c-button @click="refreshDiceRollResult">
|
||||
Refresh roll
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<c-card v-if="!diceRollResult.error" title="Dice Notation Stats" mb-2>
|
||||
<input-copyable :value="diceRollResult.roll?.minTotal" readonly label="Min Total:" label-position="left" mb-1 />
|
||||
<input-copyable :value="diceRollResult.roll?.maxTotal" readonly label="Max Total:" label-position="left" mb-1 />
|
||||
<input-copyable :value="diceRollResult.roll?.averageTotal" readonly label="Avg Total:" label-position="left" mb-1 />
|
||||
</c-card>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Dice } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Dice Roller',
|
||||
path: '/dice-roller',
|
||||
description: 'RPG Dice Roller using Dice Notation',
|
||||
keywords: ['dice', 'rng', 'rpg', 'roller'],
|
||||
component: () => import('./dice-roller.vue'),
|
||||
icon: Dice,
|
||||
createdAt: new Date('2025-02-09'),
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.describe('Tool - Fortune wheel', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/fortune-wheel');
|
||||
});
|
||||
|
||||
test('Has correct title', async ({ page }) => {
|
||||
await expect(page).toHaveTitle('Fortune wheel - IT Tools');
|
||||
});
|
||||
});
|
||||
@@ -1,85 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { FortuneWheel } from 'vue3-fortune-wheel';
|
||||
import type { Data, ImgParams } from 'vue3-fortune-wheel';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
|
||||
const base = import.meta.env.BASE_URL;
|
||||
|
||||
const choices = useQueryParamOrStorage({ name: 'choices', storageName: 'fortune-wheel:chs', defaultValue: '' });
|
||||
const spinDuration = useQueryParamOrStorage({ name: 'duration', storageName: 'fortune-wheel:dur', defaultValue: 5 });
|
||||
|
||||
const colors = [
|
||||
{ bgColor: '#FF5733', color: '#FFFFFF' },
|
||||
{ bgColor: '#2E86C1', color: '#FFFFFF' },
|
||||
{ bgColor: '#28B463', color: '#FFFFFF' },
|
||||
{ bgColor: '#F1C40F', color: '#000000' },
|
||||
{ bgColor: '#8E44AD', color: '#FFFFFF' },
|
||||
{ bgColor: '#E74C3C', color: '#FFFFFF' },
|
||||
{ bgColor: '#1ABC9C', color: '#000000' },
|
||||
{ bgColor: '#34495E', color: '#FFFFFF' },
|
||||
{ bgColor: '#D35400', color: '#FFFFFF' },
|
||||
{ bgColor: '#2C3E50', color: '#FFFFFF' },
|
||||
];
|
||||
|
||||
const wheel = ref<InstanceType<typeof FortuneWheel> | null>(null);
|
||||
const data = computed(() => {
|
||||
return (choices.value || '').split('\n')
|
||||
.filter(s => s && s !== '')
|
||||
.map((choice, index) => ({ id: index + 1, value: choice, ...colors[index % colors.length] }));
|
||||
});
|
||||
|
||||
const logo: ImgParams = {
|
||||
src: `${base}logo.png`,
|
||||
width: 100,
|
||||
height: 100,
|
||||
};
|
||||
|
||||
const [randomGift, refreshGift] = computedRefreshable(() => {
|
||||
return Math.floor(Math.random() * data.value.length) + 1;
|
||||
});
|
||||
|
||||
const result = ref<Data>();
|
||||
function done(wheelResult: Data) {
|
||||
result.value = wheelResult;
|
||||
}
|
||||
|
||||
function restart() {
|
||||
refreshGift();
|
||||
wheel.value?.spin();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-form-item label="Spin Duration (seconds):" label-placement="left">
|
||||
<n-input-number v-model:value="spinDuration" :min="1" />
|
||||
</n-form-item>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="choices"
|
||||
label="Wheel choices (one per line):"
|
||||
placeholder="Wheel choices (one per line)"
|
||||
multiline
|
||||
rows="5"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<FortuneWheel
|
||||
ref="wheel"
|
||||
v-model="randomGift"
|
||||
middle-circle
|
||||
:img-params="logo"
|
||||
:anim-duration="spinDuration * 1000"
|
||||
:data="data"
|
||||
@done="done"
|
||||
/>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="restart()">
|
||||
Restart
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { ArrowsShuffle } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Fortune wheel',
|
||||
path: '/fortune-wheel',
|
||||
description: '',
|
||||
keywords: ['fortune', 'wheel'],
|
||||
component: () => import('./fortune-wheel.vue'),
|
||||
icon: ArrowsShuffle,
|
||||
createdAt: new Date('2025-02-24'),
|
||||
});
|
||||
+3
-13
@@ -1,11 +1,8 @@
|
||||
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 markdownTocGenerator } from './markdown-toc-generator';
|
||||
import { tool as emailNormalizer } from './email-normalizer';
|
||||
import { tool as fortuneWheel } from './fortune-wheel';
|
||||
import { tool as cardPicker } from './card-picker';
|
||||
import { tool as coinFlipper } from './coin-flipper';
|
||||
import { tool as diceRoller } from './dice-roller';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -117,6 +114,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
listConverter,
|
||||
tomlToJson,
|
||||
tomlToYaml,
|
||||
markdownTocGenerator,
|
||||
xmlToJson,
|
||||
jsonToXml,
|
||||
markdownToHtml,
|
||||
@@ -172,15 +170,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Math',
|
||||
components: [
|
||||
mathEvaluator,
|
||||
etaCalculator,
|
||||
percentageCalculator,
|
||||
diceRoller,
|
||||
coinFlipper,
|
||||
cardPicker,
|
||||
fortuneWheel,
|
||||
],
|
||||
components: [mathEvaluator, etaCalculator, percentageCalculator],
|
||||
},
|
||||
{
|
||||
name: 'Measurement',
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Table } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Markdown toc generator',
|
||||
path: '/markdown-toc-generator',
|
||||
description: 'Generate a TOC from a markdown file/content',
|
||||
keywords: ['markdown', 'md', 'toc', 'generator'],
|
||||
component: () => import('./markdown-toc-generator.vue'),
|
||||
icon: Table,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
declare module 'markdown-contents'{
|
||||
declare class MarkdownContents {
|
||||
markdown(): string;
|
||||
}
|
||||
export default function Create(markdown: string):MarkdownContents;
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
getTocMarkdown,
|
||||
} from './markdown-toc-generator.service';
|
||||
|
||||
describe('markdown-toc-generator', () => {
|
||||
it('Generate TOC correctly', async () => {
|
||||
expect(getTocMarkdown({
|
||||
markdown: '',
|
||||
})).to.equal('');
|
||||
|
||||
const sourceMarkdown = `# Some main title
|
||||
|
||||
[TOC]
|
||||
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
## Last Title`;
|
||||
|
||||
expect(getTocMarkdown({
|
||||
markdown: sourceMarkdown,
|
||||
anchorPrefix: 'h-',
|
||||
})).to.equal(`# Some main title
|
||||
|
||||
<!-- TOC START -->
|
||||
- [First Title](#h-first-title)
|
||||
- [Second Spaced Title](#h-second-spaced-title)
|
||||
* [Title with Link TOC](#h-title-with-link-toc)
|
||||
* [Title with code \`var\`](#h-title-with-code-var)
|
||||
- [Last Title](#h-last-title)
|
||||
<!-- TOC END -->
|
||||
|
||||
<!-- TOC ANCHOR --><a name="first-title"></a>
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="second-spaced-title"></a>
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="title-with-link-toc"></a>
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
<!-- TOC ANCHOR --><a name="title-with-code-var"></a>
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="last-title"></a>
|
||||
## Last Title`);
|
||||
expect(getTocMarkdown({
|
||||
markdown: sourceMarkdown,
|
||||
maxLevel: 2,
|
||||
})).to.equal(`# Some main title
|
||||
|
||||
<!-- TOC START -->
|
||||
- [First Title](#first-title)
|
||||
- [Second Spaced Title](#second-spaced-title)
|
||||
- [Last Title](#last-title)
|
||||
<!-- TOC END -->
|
||||
|
||||
<!-- TOC ANCHOR --><a name="first-title"></a>
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="second-spaced-title"></a>
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="last-title"></a>
|
||||
## Last Title`);
|
||||
expect(getTocMarkdown({
|
||||
markdown: sourceMarkdown,
|
||||
commentStyle: 'liquid',
|
||||
})).to.equal(`# Some main title
|
||||
|
||||
{%- # TOC START -%}
|
||||
- [First Title](#first-title)
|
||||
- [Second Spaced Title](#second-spaced-title)
|
||||
* [Title with Link TOC](#title-with-link-toc)
|
||||
* [Title with code \`var\`](#title-with-code-var)
|
||||
- [Last Title](#last-title)
|
||||
{%- # TOC END -%}
|
||||
|
||||
{%- # TOC ANCHOR -%}<a name="first-title"></a>
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
{%- # TOC ANCHOR -%}<a name="second-spaced-title"></a>
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
{%- # TOC ANCHOR -%}<a name="title-with-link-toc"></a>
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
{%- # TOC ANCHOR -%}<a name="title-with-code-var"></a>
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
{%- # TOC ANCHOR -%}<a name="last-title"></a>
|
||||
## Last Title`);
|
||||
expect(getTocMarkdown({
|
||||
markdown: sourceMarkdown,
|
||||
generateAnchors: false,
|
||||
})).to.equal(`# Some main title
|
||||
|
||||
<!-- TOC START -->
|
||||
- [First Title](#first-title)
|
||||
- [Second Spaced Title](#second-spaced-title)
|
||||
* [Title with Link TOC](#title-with-link-toc)
|
||||
* [Title with code \`var\`](#title-with-code-var)
|
||||
- [Last Title](#last-title)
|
||||
<!-- TOC END -->
|
||||
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
## Last Title`);
|
||||
expect(getTocMarkdown({
|
||||
markdown: sourceMarkdown,
|
||||
indentSpaces: 4,
|
||||
indentChars: '-',
|
||||
concatSpaces: false,
|
||||
})).to.equal(`# Some main title
|
||||
|
||||
<!-- TOC START -->
|
||||
- [First Title](#first-title)
|
||||
- [Second Spaced Title](#second--spaced--title)
|
||||
- [Title with Link TOC](#title-with-link-toc)
|
||||
- [Title with code \`var\`](#title-with-code-var)
|
||||
- [Last Title](#last-title)
|
||||
<!-- TOC END -->
|
||||
|
||||
<!-- TOC ANCHOR --><a name="first-title"></a>
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="second--spaced--title"></a>
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="title-with-link-toc"></a>
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
<!-- TOC ANCHOR --><a name="title-with-code-var"></a>
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="last-title"></a>
|
||||
## Last Title`);
|
||||
});
|
||||
|
||||
it('Regenerate TOC correctly', async () => {
|
||||
expect(getTocMarkdown({
|
||||
markdown: `# Some main title
|
||||
|
||||
<!-- TOC START -->
|
||||
- [First Title](#first-title)
|
||||
- [Second Spaced Title](#second--spaced--title)
|
||||
- [Title with Link TOC](#title-with-link-toc)
|
||||
- [Title with code \`var\`](#title-with-code-var)
|
||||
- [Last Title](#last-title)
|
||||
<!-- TOC END -->
|
||||
|
||||
<!-- TOC ANCHOR --><a name="first-title"></a>
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="second--spaced--title"></a>
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="title-with-link-toc"></a>
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
<!-- TOC ANCHOR --><a name="title-with-code-var"></a>
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="last-title"></a>
|
||||
## Last Title`,
|
||||
anchorPrefix: 'h-',
|
||||
})).to.equal(`# Some main title
|
||||
|
||||
<!-- TOC START -->
|
||||
- [First Title](#h-first-title)
|
||||
- [Second Spaced Title](#h-second-spaced-title)
|
||||
* [Title with Link TOC](#h-title-with-link-toc)
|
||||
* [Title with code \`var\`](#h-title-with-code-var)
|
||||
- [Last Title](#h-last-title)
|
||||
<!-- TOC END -->
|
||||
|
||||
<!-- TOC ANCHOR --><a name="first-title"></a>
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="second-spaced-title"></a>
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="title-with-link-toc"></a>
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
<!-- TOC ANCHOR --><a name="title-with-code-var"></a>
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="last-title"></a>
|
||||
## Last Title`);
|
||||
});
|
||||
|
||||
it('Generate distinct TOC ids', async () => {
|
||||
expect(getTocMarkdown({
|
||||
markdown: `# Some main title
|
||||
|
||||
[TOC]
|
||||
|
||||
## Same Title 1
|
||||
|
||||
Some text
|
||||
|
||||
## Same Title 1
|
||||
|
||||
Some text
|
||||
|
||||
### Same title 1
|
||||
|
||||
Some text`,
|
||||
anchorPrefix: 'h-',
|
||||
})).to.equal(`# Some main title
|
||||
|
||||
<!-- TOC START -->
|
||||
- [Same Title 1](#h-same-title-1)
|
||||
- [Same Title 1](#h-same-title-1-1)
|
||||
* [Same title 1](#h-same-title-1-2)
|
||||
<!-- TOC END -->
|
||||
|
||||
<!-- TOC ANCHOR --><a name="same-title-1"></a>
|
||||
## Same Title 1
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="same-title-1-1"></a>
|
||||
## Same Title 1
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="same-title-1-2"></a>
|
||||
### Same title 1
|
||||
|
||||
Some text`);
|
||||
});
|
||||
|
||||
it('Generate ids for non latin', async () => {
|
||||
expect(getTocMarkdown({
|
||||
markdown: `# Some main title
|
||||
|
||||
[TOC]
|
||||
|
||||
## Привет non-latin 你好
|
||||
|
||||
Some text
|
||||
|
||||
## 😄 emoji
|
||||
|
||||
Some text
|
||||
|
||||
### Other title 1
|
||||
|
||||
Some text`,
|
||||
anchorPrefix: 'h-',
|
||||
})).to.equal(`# Some main title
|
||||
|
||||
<!-- TOC START -->
|
||||
- [Привет non-latin 你好](#h--non-latin-)
|
||||
- [😄 emoji](#h--emoji)
|
||||
* [Other title 1](#h-other-title-1)
|
||||
<!-- TOC END -->
|
||||
|
||||
<!-- TOC ANCHOR --><a name="-non-latin-"></a>
|
||||
## Привет non-latin 你好
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="-emoji"></a>
|
||||
## 😄 emoji
|
||||
|
||||
Some text
|
||||
|
||||
<!-- TOC ANCHOR --><a name="other-title-1"></a>
|
||||
### Other title 1
|
||||
|
||||
Some text`);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,183 @@
|
||||
import sanitizeHtml from 'sanitize-html';
|
||||
|
||||
function stripNonLatinCharacters(text: string) {
|
||||
return text.replace(/[^A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u02BB\u02EE\uA78C\d\s_-]/g, '');
|
||||
};
|
||||
|
||||
function transformInlineCode(text: string, transform: (s: string) => string) {
|
||||
return text.replace(/`(.*?)`/g, (_, p) => {
|
||||
return `\`${transform(p)}\``;
|
||||
});
|
||||
};
|
||||
|
||||
function spacesToDash(text: string) {
|
||||
return text.replace(/\s/g, '-');
|
||||
};
|
||||
|
||||
function stripHtmlTags(text: string) {
|
||||
return sanitizeHtml(text, {
|
||||
allowedTags: [],
|
||||
allowedAttributes: {},
|
||||
});
|
||||
}
|
||||
|
||||
function stripMarkdownLinks(text: string, replacement: string = '$1') {
|
||||
return text.replace(/\[([^\]]*)\]\([^\)]*\)/g, replacement); // NOSONAR
|
||||
};
|
||||
|
||||
function concatDashes(text: string) {
|
||||
return text.replace(/--+/g, '-');
|
||||
};
|
||||
|
||||
function removeUnderscoreBoldAndItalics(text: string) {
|
||||
const underscoreBoldAndItalicsRegexes = ['__', '_'].map((it) => {
|
||||
return new RegExp(`\\b${it}([^_\\s]|[^_\\s].*?[^_\\s])${it}\\b`, 'g');
|
||||
});
|
||||
|
||||
let result = text;
|
||||
|
||||
underscoreBoldAndItalicsRegexes.forEach((regex) => {
|
||||
result = result.replace(regex, '$1');
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
function genericAnchorGenerator(text: string, concatSpaces: boolean) {
|
||||
let result = text;
|
||||
result = result.toLowerCase();
|
||||
result = transformInlineCode(result, (s: string) => {
|
||||
return stripNonLatinCharacters(s);
|
||||
});
|
||||
result = removeUnderscoreBoldAndItalics(result);
|
||||
result = stripHtmlTags(result);
|
||||
result = stripMarkdownLinks(result);
|
||||
result = result.trim();
|
||||
result = stripNonLatinCharacters(result);
|
||||
result = spacesToDash(result);
|
||||
if (concatSpaces) {
|
||||
result = concatDashes(result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
function escapeRegExp(string: string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
||||
}
|
||||
|
||||
interface Title {
|
||||
level: number
|
||||
id: string
|
||||
name: string
|
||||
md: string
|
||||
}
|
||||
|
||||
function getTitles(markdown: string, idGenerator: (titleMarkdownContent: string) => string) {
|
||||
const titles: Title[] = [];
|
||||
|
||||
markdown = markdown.replace(/^```[\s\S]*?\n```/mg, () => {
|
||||
return '';
|
||||
});
|
||||
markdown = markdown.replace(/^~~~[\s\S]*?\n~~~/mg, () => {
|
||||
return '';
|
||||
});
|
||||
|
||||
[...markdown.matchAll(/^(#+)(.*$)/mg)].forEach( // NOSONAR
|
||||
([match, levelString, titleContent]) => {
|
||||
const level = levelString.length;
|
||||
|
||||
titles.push({
|
||||
md: match,
|
||||
level,
|
||||
id: idGenerator(titleContent),
|
||||
name: titleContent.trim(),
|
||||
});
|
||||
});
|
||||
|
||||
return titles;
|
||||
};
|
||||
|
||||
export function getTocMarkdown({
|
||||
markdown,
|
||||
generateAnchors = true,
|
||||
indentChars = '-*+',
|
||||
indentSpaces = 2,
|
||||
maxLevel = -1,
|
||||
anchorPrefix = '',
|
||||
concatSpaces = true,
|
||||
commentStyle = 'html',
|
||||
}: {
|
||||
markdown: string
|
||||
generateAnchors?: boolean
|
||||
indentChars?: string
|
||||
indentSpaces?: number
|
||||
maxLevel?: number
|
||||
anchorPrefix?: string
|
||||
concatSpaces?: boolean
|
||||
commentStyle?: 'html' | 'liquid'
|
||||
}) {
|
||||
const allIds: { [id: string]: number } = {};
|
||||
const getFinalId = (id: string) => {
|
||||
if (typeof allIds[id] === 'undefined') {
|
||||
allIds[id] = 0;
|
||||
return id;
|
||||
}
|
||||
else {
|
||||
allIds[id] += 1;
|
||||
return `${id}-${allIds[id]}`;
|
||||
}
|
||||
};
|
||||
const titles = getTitles(markdown, titleContent => getFinalId(genericAnchorGenerator(titleContent, concatSpaces)));
|
||||
|
||||
const createLink = (linkText: string, url: string) => {
|
||||
return `[${linkText.replace(/\[/g, '\\[').replace(/\]/g, '\\]')}](${url.replace(/\(/g, '%28').replace(/\(/g, '%29')})`;
|
||||
};
|
||||
|
||||
let markdownTOC = '';
|
||||
let resultMarkdown = markdown;
|
||||
const commentOpen = commentStyle === 'html' ? '<!--' : '{%- #';
|
||||
const commentClose = commentStyle === 'html' ? '-->' : '-%}';
|
||||
|
||||
resultMarkdown = resultMarkdown.replace(
|
||||
new RegExp(`\n${escapeRegExp(commentOpen)} TOC START.*?TOC END ${escapeRegExp(commentClose)}\n`, 'smg'),
|
||||
'\n[TOC]\n',
|
||||
);
|
||||
resultMarkdown = resultMarkdown.replace(
|
||||
new RegExp(`^${escapeRegExp(commentOpen)} TOC ANCHOR.*?\n`, 'mg'),
|
||||
'',
|
||||
);
|
||||
|
||||
titles.forEach((title) => {
|
||||
if (title.level === 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (maxLevel > 0 && title.level > maxLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
const level = title.level - 2;
|
||||
let offset = '';
|
||||
if (level) {
|
||||
offset = `${Array.from({ length: level * indentSpaces }).join(' ')} `;
|
||||
}
|
||||
const bulletChar = indentChars[level] ?? indentChars.slice(-1)[0];
|
||||
|
||||
const anchorName = `${anchorPrefix}${title.id}`;
|
||||
|
||||
markdownTOC += `${offset}${bulletChar} ${createLink(stripMarkdownLinks(title.name), `#${anchorName}`)}\n`;
|
||||
|
||||
if (generateAnchors) {
|
||||
resultMarkdown = resultMarkdown.replace(
|
||||
new RegExp(`(?<!^${commentOpen} TOC ANCHOR.*\n)^${escapeRegExp(title.md)}`, 'm'),
|
||||
`${commentOpen} TOC ANCHOR ${commentClose}<a name="${title.id}"></a>\n${title.md}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
resultMarkdown = resultMarkdown.replace(
|
||||
/^\[TOC\]\n/mg,
|
||||
`${commentOpen} TOC START ${commentClose}\n${markdownTOC}${commentOpen} TOC END ${commentClose}\n`,
|
||||
);
|
||||
|
||||
return resultMarkdown;
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<script setup lang="ts">
|
||||
import { withDefaultOnError } from '../../utils/defaults';
|
||||
import {
|
||||
getTocMarkdown,
|
||||
} from './markdown-toc-generator.service';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
|
||||
const markdown = ref(`# Some main title
|
||||
|
||||
[TOC]
|
||||
|
||||
## First Title
|
||||
|
||||
Some text
|
||||
|
||||
## Second Spaced Title
|
||||
|
||||
Some text
|
||||
|
||||
### Title with Link [TOC](http://it-tools.tech)
|
||||
|
||||
\`\`\`
|
||||
## some bash code
|
||||
echo 'test';
|
||||
\`\`\`
|
||||
|
||||
### Title with code \`var\`
|
||||
|
||||
Some text
|
||||
|
||||
## Last Title`);
|
||||
const generateAnchors = useQueryParamOrStorage({ name: 'anchors', storageName: 'md-toc-gen:anchors', defaultValue: true });
|
||||
const indentChars = useQueryParamOrStorage({ name: 'bullets', storageName: 'md-toc-gen:bullets', defaultValue: '-*+' });
|
||||
const indentSpaces = ref(3);
|
||||
const maxLevel = useQueryParamOrStorage({ name: 'max', storageName: 'md-toc-gen:max', defaultValue: -1 });
|
||||
const anchorPrefix = useQueryParamOrStorage({ name: 'prefix', storageName: 'md-toc-gen:prefix', defaultValue: '' });
|
||||
const concatSpaces = useQueryParamOrStorage({ name: 'concat', storageName: 'md-toc-gen:concat', defaultValue: false });
|
||||
const commentStyle = useQueryParamOrStorage({ name: 'comment', storageName: 'md-toc-gen:comment', defaultValue: 'html' });
|
||||
|
||||
const markdownWithTOC = computed(() => withDefaultOnError(() => {
|
||||
return getTocMarkdown({
|
||||
markdown: markdown.value,
|
||||
anchorPrefix: anchorPrefix.value,
|
||||
commentStyle: commentStyle.value as ('html' | 'liquid'),
|
||||
concatSpaces: concatSpaces.value,
|
||||
generateAnchors: generateAnchors.value,
|
||||
indentChars: indentChars.value,
|
||||
indentSpaces: indentSpaces.value,
|
||||
maxLevel: maxLevel.value,
|
||||
});
|
||||
}, ''));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="Options" mb-2>
|
||||
<n-space>
|
||||
<n-form-item label-placement="left">
|
||||
<n-checkbox v-model:checked="generateAnchors">
|
||||
Generate Anchors
|
||||
</n-checkbox>
|
||||
</n-form-item>
|
||||
<n-form-item label="Max Heading Level:" label-placement="left">
|
||||
<n-input-number
|
||||
v-model:value="maxLevel"
|
||||
placeholder="Max Heading Level..."
|
||||
:max="6" :min="-1"
|
||||
/>
|
||||
</n-form-item>
|
||||
</n-space>
|
||||
|
||||
<details>
|
||||
<summary>Advanced</summary>
|
||||
<n-space>
|
||||
<n-form-item label-placement="left">
|
||||
<n-checkbox v-model:checked="concatSpaces">
|
||||
Concat Spaces
|
||||
</n-checkbox>
|
||||
</n-form-item>
|
||||
<c-input-text
|
||||
v-model:value="indentChars"
|
||||
label="Bullet Chars"
|
||||
label-position="left"
|
||||
placeholder="Bullet Chars"
|
||||
/>
|
||||
<c-input-text
|
||||
v-model:value="anchorPrefix"
|
||||
label="Anchors Prefix"
|
||||
label-position="left"
|
||||
placeholder="Anchors Prefix"
|
||||
/>
|
||||
<n-form-item label="Indents: " label-placement="left">
|
||||
<n-input-number
|
||||
v-model:value="indentSpaces"
|
||||
placeholder="Indents..."
|
||||
:max="10" :min="1"
|
||||
/>
|
||||
</n-form-item>
|
||||
<c-select
|
||||
v-model:value="commentStyle"
|
||||
label="Comment Styles"
|
||||
label-position="left"
|
||||
:options="['html', 'liquid']"
|
||||
placeholder="Comment Styles"
|
||||
/>
|
||||
</n-space>
|
||||
</details>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Input markdown" mb-2>
|
||||
<n-p>You can paste a document with existing TOC (generated by this tool) or add a <code>[TOC]</code> marker in your document (on a single line)</n-p>
|
||||
<c-input-text
|
||||
v-model:value="markdown"
|
||||
placeholder="Put your markdown here..."
|
||||
multiline
|
||||
rows="8"
|
||||
/>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Output markdown with TOC" mb-2>
|
||||
<textarea-copyable
|
||||
language="markdown"
|
||||
:value="markdownWithTOC"
|
||||
/>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -151,7 +151,7 @@ function onSearchInput() {
|
||||
>
|
||||
<div flex-1 truncate>
|
||||
<slot name="displayed-value">
|
||||
<input v-if="searchable && isOpen" ref="searchInputRef" v-model="searchQuery" type="text" placeholder="Search..." class="search-input" w-full color-current lh-normal @input="onSearchInput">
|
||||
<input v-if="searchable && isOpen" ref="searchInputRef" v-model="searchQuery" type="text" placeholder="Search..." class="search-input" w-full lh-normal color-current @input="onSearchInput">
|
||||
<span v-else-if="selectedOption" lh-normal>
|
||||
{{ selectedOption.label }}
|
||||
</span>
|
||||
|
||||
@@ -39,7 +39,7 @@ const headers = computed(() => {
|
||||
<template>
|
||||
<div class="relative overflow-x-auto rounded">
|
||||
<table class="w-full border-collapse text-left text-sm text-gray-500 dark:text-gray-400" role="table" :aria-label="description">
|
||||
<thead v-if="!hideHeaders" class="bg-#ffffff text-gray-700 uppercase dark:bg-#333333 dark:text-gray-400" border-b="1px solid dark:transparent #efeff5">
|
||||
<thead v-if="!hideHeaders" class="bg-#ffffff uppercase text-gray-700 dark:bg-#333333 dark:text-gray-400" border-b="1px solid dark:transparent #efeff5">
|
||||
<tr>
|
||||
<th v-for="header in headers" :key="header.key" scope="col" class="px-6 py-3 text-xs">
|
||||
{{ header.label }}
|
||||
|
||||
Reference in new issue
Block a user