mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-23 06:11:06 +03:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a25bd8f4b0 | ||
|
|
435d81281b | ||
|
|
3e27051f8f | ||
|
|
3f61e3569e |
No files matched your search
Vendored
+27
-3
@@ -12,7 +12,6 @@ declare module '@vue/runtime-core' {
|
||||
'404.page': typeof import('./src/pages/404.page.vue')['default']
|
||||
About: typeof import('./src/pages/About.vue')['default']
|
||||
App: typeof import('./src/App.vue')['default']
|
||||
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
|
||||
'Base.layout': typeof import('./src/layouts/base.layout.vue')['default']
|
||||
Base64FileConverter: typeof import('./src/tools/base64-file-converter/base64-file-converter.vue')['default']
|
||||
Base64StringConverter: typeof import('./src/tools/base64-string-converter/base64-string-converter.vue')['default']
|
||||
@@ -89,17 +88,28 @@ declare module '@vue/runtime-core' {
|
||||
HttpStatusCodes: typeof import('./src/tools/http-status-codes/http-status-codes.vue')['default']
|
||||
IbanValidatorAndParser: typeof import('./src/tools/iban-validator-and-parser/iban-validator-and-parser.vue')['default']
|
||||
'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default']
|
||||
'IconMdi:contentCopy': typeof import('~icons/mdi/content-copy')['default']
|
||||
'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default']
|
||||
IconMdiArrowDown: typeof import('~icons/mdi/arrow-down')['default']
|
||||
IconMdiArrowRightBottom: typeof import('~icons/mdi/arrow-right-bottom')['default']
|
||||
IconMdiCamera: typeof import('~icons/mdi/camera')['default']
|
||||
IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default']
|
||||
IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default']
|
||||
IconMdiClose: typeof import('~icons/mdi/close')['default']
|
||||
IconMdiContentCopy: typeof import('~icons/mdi/content-copy')['default']
|
||||
IconMdiDeleteOutline: typeof import('~icons/mdi/delete-outline')['default']
|
||||
IconMdiDownload: typeof import('~icons/mdi/download')['default']
|
||||
IconMdiEye: typeof import('~icons/mdi/eye')['default']
|
||||
IconMdiEyeOff: typeof import('~icons/mdi/eye-off')['default']
|
||||
IconMdiHeart: typeof import('~icons/mdi/heart')['default']
|
||||
IconMdiPause: typeof import('~icons/mdi/pause')['default']
|
||||
IconMdiPlay: typeof import('~icons/mdi/play')['default']
|
||||
IconMdiRecord: typeof import('~icons/mdi/record')['default']
|
||||
IconMdiRefresh: typeof import('~icons/mdi/refresh')['default']
|
||||
IconMdiSearch: typeof import('~icons/mdi/search')['default']
|
||||
IconMdiTranslate: typeof import('~icons/mdi/translate')['default']
|
||||
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
||||
IconMdiVideo: typeof import('~icons/mdi/video')['default']
|
||||
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
|
||||
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
|
||||
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
|
||||
@@ -126,25 +136,39 @@ 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']
|
||||
NAlert: typeof import('naive-ui')['NAlert']
|
||||
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']
|
||||
NDatePicker: typeof import('naive-ui')['NDatePicker']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
|
||||
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']
|
||||
NH2: typeof import('naive-ui')['NH2']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
NImage: typeof import('naive-ui')['NImage']
|
||||
NInputGroup: typeof import('naive-ui')['NInputGroup']
|
||||
NInputGroupLabel: typeof import('naive-ui')['NInputGroupLabel']
|
||||
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']
|
||||
NProgress: typeof import('naive-ui')['NProgress']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSpin: typeof import('naive-ui')['NSpin']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NStatistic: typeof import('naive-ui')['NStatistic']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NTag: typeof import('naive-ui')['NTag']
|
||||
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']
|
||||
|
||||
+1
-9
@@ -41,7 +41,6 @@
|
||||
"@tiptap/pm": "2.1.6",
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@vicons/material": "^0.12.0",
|
||||
"@vicons/tabler": "^0.12.0",
|
||||
"@vueuse/core": "^10.3.0",
|
||||
@@ -49,7 +48,6 @@
|
||||
"@vueuse/router": "^10.0.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"change-case": "^4.1.2",
|
||||
"cidr-tools": "^7.0.4",
|
||||
"colord": "^2.9.3",
|
||||
"composerize-ts": "^0.6.2",
|
||||
"country-code-lookup": "^0.1.0",
|
||||
@@ -59,18 +57,12 @@
|
||||
"date-fns": "^2.29.3",
|
||||
"dompurify": "^3.0.6",
|
||||
"emojilib": "^3.0.10",
|
||||
"figlet": "^1.7.0",
|
||||
"figue": "^1.2.0",
|
||||
"fuse.js": "^6.6.2",
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
"ip-address": "^9.0.5",
|
||||
"ip-bigint": "^8.0.2",
|
||||
"ip-cidr": "^4.0.0",
|
||||
"ip-matching": "^2.1.2",
|
||||
"is-cidr": "^5.0.3",
|
||||
"is-ip": "^5.0.1",
|
||||
"js-base64": "^3.7.6",
|
||||
"json5": "^2.2.3",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"libphonenumber-js": "^1.10.28",
|
||||
|
||||
Generated
+13
-22
@@ -23,9 +23,6 @@ dependencies:
|
||||
'@tiptap/vue-3':
|
||||
specifier: 2.0.3
|
||||
version: 2.0.3(@tiptap/core@2.1.12)(@tiptap/pm@2.1.6)(vue@3.3.4)
|
||||
'@types/figlet':
|
||||
specifier: ^1.5.8
|
||||
version: 1.5.8
|
||||
'@vicons/material':
|
||||
specifier: ^0.12.0
|
||||
version: 0.12.0
|
||||
@@ -74,9 +71,6 @@ dependencies:
|
||||
emojilib:
|
||||
specifier: ^3.0.10
|
||||
version: 3.0.10
|
||||
figlet:
|
||||
specifier: ^1.7.0
|
||||
version: 1.7.0
|
||||
figue:
|
||||
specifier: ^1.2.0
|
||||
version: 1.2.0
|
||||
@@ -92,6 +86,9 @@ dependencies:
|
||||
ibantools:
|
||||
specifier: ^4.3.3
|
||||
version: 4.3.3
|
||||
js-base64:
|
||||
specifier: ^3.7.6
|
||||
version: 3.7.7
|
||||
json5:
|
||||
specifier: ^2.2.3
|
||||
version: 2.2.3
|
||||
@@ -2908,10 +2905,6 @@ packages:
|
||||
/@types/estree@1.0.0:
|
||||
resolution: {integrity: sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==}
|
||||
|
||||
/@types/figlet@1.5.8:
|
||||
resolution: {integrity: sha512-G22AUvy4Tl95XLE7jmUM8s8mKcoz+Hr+Xm9W90gJsppJq9f9tHvOGkrpn4gRX0q/cLtBdNkWtWCKDg2UDZoZvQ==}
|
||||
dev: false
|
||||
|
||||
/@types/fs-extra@11.0.1:
|
||||
resolution: {integrity: sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==}
|
||||
dependencies:
|
||||
@@ -3351,7 +3344,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.8.0(vue@3.3.4)
|
||||
unhead: 0.5.1
|
||||
vue: 3.3.4
|
||||
transitivePeerDependencies:
|
||||
@@ -3993,10 +3986,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.8.0(vue@3.3.4):
|
||||
resolution: {integrity: sha512-dUdy6zwHhULGxmr9YUg8e+EnB39gcM4Fe2oKBSrh3cOsV30JcMPtsyuspgFCUo5xxFNaeMf/W2yyKfST7Bg8oQ==}
|
||||
dependencies:
|
||||
vue-demi: 0.14.6(vue@3.3.4)
|
||||
vue-demi: 0.14.7(vue@3.3.4)
|
||||
transitivePeerDependencies:
|
||||
- '@vue/composition-api'
|
||||
- vue
|
||||
@@ -5595,12 +5588,6 @@ packages:
|
||||
web-streams-polyfill: 3.2.1
|
||||
dev: true
|
||||
|
||||
/figlet@1.7.0:
|
||||
resolution: {integrity: sha512-gO8l3wvqo0V7wEFLXPbkX83b7MVjRrk1oRLfYlZXol8nEpb/ON9pcKLI4qpBv5YtOTfrINtqb7b40iYY2FTWFg==}
|
||||
engines: {node: '>= 0.4.0'}
|
||||
hasBin: true
|
||||
dev: false
|
||||
|
||||
/figue@1.2.0:
|
||||
resolution: {integrity: sha512-CXKr12kiNWjKtUK3X+YHeXKepn80s9Rg6pgZXoLQYEybgwaGJ9uGW4DrBrVK30ZWZf1mcvTbXF56AcovG7gLVw==}
|
||||
dependencies:
|
||||
@@ -6472,6 +6459,10 @@ packages:
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/js-base64@3.7.7:
|
||||
resolution: {integrity: sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==}
|
||||
dev: false
|
||||
|
||||
/js-beautify@1.14.6:
|
||||
resolution: {integrity: sha512-GfofQY5zDp+cuHc+gsEXKPpNw2KbPddreEo35O6jT6i0RVK6LhsoYBhq5TvK4/n74wnA0QbK8gGd+jUZwTMKJw==}
|
||||
engines: {node: '>=10'}
|
||||
@@ -9151,8 +9142,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
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { extension as getExtensionFromMime } from 'mime-types';
|
||||
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
||||
import type { Ref } from 'vue';
|
||||
import _ from 'lodash';
|
||||
|
||||
export { getMimeTypeFromBase64, useDownloadFileFromBase64 };
|
||||
export {
|
||||
getMimeTypeFromBase64,
|
||||
getMimeTypeFromExtension, getExtensionFromMimeType,
|
||||
useDownloadFileFromBase64, useDownloadFileFromBase64Refs,
|
||||
previewImageFromBase64,
|
||||
};
|
||||
|
||||
const commonMimeTypesSignatures = {
|
||||
'JVBERi0': 'application/pdf',
|
||||
@@ -36,30 +41,78 @@ function getFileExtensionFromMimeType({
|
||||
defaultExtension?: string
|
||||
}) {
|
||||
if (mimeType) {
|
||||
return getExtensionFromMime(mimeType) ?? defaultExtension;
|
||||
return getExtensionFromMimeType(mimeType) ?? defaultExtension;
|
||||
}
|
||||
|
||||
return defaultExtension;
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64({ source, filename }: { source: Ref<string>; filename?: string }) {
|
||||
function downloadFromBase64({ sourceValue, filename, extension, fileMimeType }:
|
||||
{ sourceValue: string; filename?: string; extension?: string; fileMimeType?: string }) {
|
||||
if (sourceValue === '') {
|
||||
throw new Error('Base64 string is empty');
|
||||
}
|
||||
|
||||
const defaultExtension = extension ?? 'txt';
|
||||
const { mimeType } = getMimeTypeFromBase64({ base64String: sourceValue });
|
||||
let base64String = sourceValue;
|
||||
if (!mimeType) {
|
||||
const targetMimeType = fileMimeType ?? getMimeTypeFromExtension(defaultExtension);
|
||||
base64String = `data:${targetMimeType};base64,${sourceValue}`;
|
||||
}
|
||||
|
||||
const cleanExtension = extension ?? getFileExtensionFromMimeType(
|
||||
{ mimeType, defaultExtension });
|
||||
let cleanFileName = filename ?? `file.${cleanExtension}`;
|
||||
if (extension && !cleanFileName.endsWith(`.${extension}`)) {
|
||||
cleanFileName = `${cleanFileName}.${cleanExtension}`;
|
||||
}
|
||||
|
||||
const a = document.createElement('a');
|
||||
a.href = base64String;
|
||||
a.download = cleanFileName;
|
||||
a.click();
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64(
|
||||
{ source, filename, extension, fileMimeType }:
|
||||
{ source: Ref<string>; filename?: string; extension?: string; fileMimeType?: string }) {
|
||||
return {
|
||||
download() {
|
||||
if (source.value === '') {
|
||||
throw new Error('Base64 string is empty');
|
||||
}
|
||||
|
||||
const { mimeType } = getMimeTypeFromBase64({ base64String: source.value });
|
||||
const base64String = mimeType
|
||||
? source.value
|
||||
: `data:text/plain;base64,${source.value}`;
|
||||
|
||||
const cleanFileName = filename ?? `file.${getFileExtensionFromMimeType({ mimeType })}`;
|
||||
|
||||
const a = document.createElement('a');
|
||||
a.href = base64String;
|
||||
a.download = cleanFileName;
|
||||
a.click();
|
||||
downloadFromBase64({ sourceValue: source.value, filename, extension, fileMimeType });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function useDownloadFileFromBase64Refs(
|
||||
{ source, filename, extension }:
|
||||
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
||||
return {
|
||||
download() {
|
||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function previewImageFromBase64(base64String: string): HTMLImageElement {
|
||||
if (base64String === '') {
|
||||
throw new Error('Base64 string is empty');
|
||||
}
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.src = base64String;
|
||||
|
||||
const container = document.createElement('div');
|
||||
container.appendChild(img);
|
||||
|
||||
const previewContainer = document.getElementById('previewContainer');
|
||||
if (previewContainer) {
|
||||
previewContainer.innerHTML = '';
|
||||
previewContainer.appendChild(container);
|
||||
}
|
||||
else {
|
||||
throw new Error('Preview container element not found');
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import figlet from 'figlet';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
|
||||
const input = ref('Ascii ART');
|
||||
const font = useStorage('ascii-text-drawer:font', 'Standard');
|
||||
const width = useStorage('ascii-text-drawer:width', 80);
|
||||
const output = ref('');
|
||||
const errored = ref(false);
|
||||
const processing = ref(false);
|
||||
|
||||
figlet.defaults({ fontPath: '//unpkg.com/figlet@1.6.0/fonts/' });
|
||||
|
||||
watchEffect(async () => {
|
||||
processing.value = true;
|
||||
try {
|
||||
const options: figlet.Options = {
|
||||
font: font.value as figlet.Fonts,
|
||||
width: width.value,
|
||||
whitespaceBreak: true,
|
||||
};
|
||||
output.value = await (new Promise<string>((resolve, reject) =>
|
||||
figlet.text(input.value, options,
|
||||
(err, text) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(text ?? '');
|
||||
})));
|
||||
errored.value = false;
|
||||
}
|
||||
catch (e: any) {
|
||||
errored.value = true;
|
||||
}
|
||||
processing.value = false;
|
||||
});
|
||||
|
||||
const fonts = ['1Row', '3-D', '3D Diagonal', '3D-ASCII', '3x5', '4Max', '5 Line Oblique', 'AMC 3 Line', 'AMC 3 Liv1', 'AMC AAA01', 'AMC Neko', 'AMC Razor', 'AMC Razor2', 'AMC Slash', 'AMC Slider', 'AMC Thin', 'AMC Tubes', 'AMC Untitled', 'ANSI Shadow', 'ASCII New Roman', 'Acrobatic', 'Alligator', 'Alligator2', 'Alpha', 'Alphabet', 'Arrows', 'Avatar', 'B1FF', 'B1FF', 'Banner', 'Banner3-D', 'Banner3', 'Banner4', 'Barbwire', 'Basic', 'Bear', 'Bell', 'Benjamin', 'Big Chief', 'Big Money-ne', 'Big Money-nw', 'Big Money-se', 'Big Money-sw', 'Big', 'Bigfig', 'Binary', 'Block', 'Blocks', 'Bloody', 'Bolger', 'Braced', 'Bright', 'Broadway KB', 'Broadway', 'Bubble', 'Bulbhead', 'Caligraphy', 'Caligraphy2', 'Calvin S', 'Cards', 'Catwalk', 'Chiseled', 'Chunky', 'Coinstak', 'Cola', 'Colossal', 'Computer', 'Contessa', 'Contrast', 'Cosmike', 'Crawford', 'Crawford2', 'Crazy', 'Cricket', 'Cursive', 'Cyberlarge', 'Cybermedium', 'Cybersmall', 'Cygnet', 'DANC4', 'DOS Rebel', 'DWhistled', 'Dancing Font', 'Decimal', 'Def Leppard', 'Delta Corps Priest 1', 'Diamond', 'Diet Cola', 'Digital', 'Doh', 'Doom', 'Dot Matrix', 'Double Shorts', 'Double', 'Dr Pepper', 'Efti Chess', 'Efti Font', 'Efti Italic', 'Efti Piti', 'Efti Robot', 'Efti Wall', 'Efti Water', 'Electronic', 'Elite', 'Epic', 'Fender', 'Filter', 'Fire Font-k', 'Fire Font-s', 'Flipped', 'Flower Power', 'Four Tops', 'Fraktur', 'Fun Face', 'Fun Faces', 'Fuzzy', 'Georgi16', 'Georgia11', 'Ghost', 'Ghoulish', 'Glenyn', 'Goofy', 'Gothic', 'Graceful', 'Gradient', 'Graffiti', 'Greek', 'Heart Left', 'Heart Right', 'Henry 3D', 'Hex', 'Hieroglyphs', 'Hollywood', 'Horizontal Left', 'Horizontal Right', 'ICL-1900', 'Impossible', 'Invita', 'Isometric1', 'Isometric2', 'Isometric3', 'Isometric4', 'Italic', 'Ivrit', 'JS Block Letters', 'JS Bracket Letters', 'JS Capital Curves', 'JS Cursive', 'JS Stick Letters', 'Jacky', 'Jazmine', 'Jerusalem', 'Katakana', 'Kban', 'Keyboard', 'Knob', 'Konto Slant', 'Konto', 'LCD', 'Larry 3D 2', 'Larry 3D', 'Lean', 'Letters', 'Lil Devil', 'Line Blocks', 'Linux', 'Lockergnome', 'Madrid', 'Marquee', 'Maxfour', 'Merlin1', 'Merlin2', 'Mike', 'Mini', 'Mirror', 'Mnemonic', 'Modular', 'Morse', 'Morse2', 'Moscow', 'Mshebrew210', 'Muzzle', 'NScript', 'NT Greek', 'NV Script', 'Nancyj-Fancy', 'Nancyj-Improved', 'Nancyj-Underlined', 'Nancyj', 'Nipples', 'O8', 'OS2', 'Octal', 'Ogre', 'Old Banner', 'Patorjk\'s Cheese', 'Patorjk-HeX', 'Pawp', 'Peaks Slant', 'Peaks', 'Pebbles', 'Pepper', 'Poison', 'Puffy', 'Puzzle', 'Pyramid', 'Rammstein', 'Rectangles', 'Red Phoenix', 'Relief', 'Relief2', 'Reverse', 'Roman', 'Rot13', 'Rot13', 'Rotated', 'Rounded', 'Rowan Cap', 'Rozzo', 'Runic', 'Runyc', 'S Blood', 'SL Script', 'Santa Clara', 'Script', 'Serifcap', 'Shadow', 'Shimrod', 'Short', 'Slant Relief', 'Slant', 'Slide', 'Small Caps', 'Small Isometric1', 'Small Keyboard', 'Small Poison', 'Small Script', 'Small Shadow', 'Small Slant', 'Small Tengwar', 'Small', 'Soft', 'Speed', 'Spliff', 'Stacey', 'Stampate', 'Stampatello', 'Standard', 'Star Strips', 'Star Wars', 'Stellar', 'Stforek', 'Stick Letters', 'Stop', 'Straight', 'Stronger Than All', 'Sub-Zero', 'Swamp Land', 'Swan', 'Sweet', 'THIS', 'Tanja', 'Tengwar', 'Term', 'Test1', 'The Edge', 'Thick', 'Thin', 'Thorned', 'Three Point', 'Ticks Slant', 'Ticks', 'Tiles', 'Tinker-Toy', 'Tombstone', 'Train', 'Trek', 'Tsalagi', 'Tubular', 'Twisted', 'Two Point', 'USA Flag', 'Univers', 'Varsity', 'Wavy', 'Weird', 'Wet Letter', 'Whimsy', 'Wow'];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card style="max-width: 600px;">
|
||||
<c-input-text
|
||||
v-model:value="input"
|
||||
label="Your text:"
|
||||
placeholder="Your text to draw"
|
||||
raw-text
|
||||
multiline
|
||||
rows="4"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-grid cols="4" x-gap="12" w-full>
|
||||
<n-gi span="2">
|
||||
<c-select
|
||||
v-model:value="font"
|
||||
label-position="top"
|
||||
label="Font:"
|
||||
:options="fonts"
|
||||
searchable="true"
|
||||
placeholder="Select font to use"
|
||||
/>
|
||||
</n-gi>
|
||||
<n-gi span="2">
|
||||
<n-form-item label="Width:" label-placement="top" label-width="100" :show-feedback="false">
|
||||
<n-input-number v-model:value="width" min="0" max="10000" w-full placeholder="Width of the text" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div v-if="processing" flex items-center justify-center>
|
||||
<n-spin size="medium" />
|
||||
<span class="ml-2">Loading font...</span>
|
||||
</div>
|
||||
|
||||
<c-alert v-if="errored" mt-1 text-center type="error">
|
||||
Current settings resulted in error.
|
||||
</c-alert>
|
||||
|
||||
<n-form-item v-if="!processing && !errored" label="Ascii Art text:">
|
||||
<TextareaCopyable
|
||||
:value="output"
|
||||
mb-1 mt-1
|
||||
copy-placement="outside"
|
||||
/>
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Artboard } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'ASCII Art Text Generator',
|
||||
path: '/ascii-text-drawer',
|
||||
description: 'Create ASCII art text with many fonts and styles.',
|
||||
keywords: ['ascii', 'asciiart', 'text', 'drawer'],
|
||||
component: () => import('./ascii-text-drawer.vue'),
|
||||
icon: Artboard,
|
||||
createdAt: new Date('2024-03-03'),
|
||||
});
|
||||
@@ -2,12 +2,19 @@
|
||||
import { useBase64 } from '@vueuse/core';
|
||||
import type { Ref } from 'vue';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||
import { getExtensionFromMimeType, getMimeTypeFromBase64, previewImageFromBase64, useDownloadFileFromBase64Refs } from '@/composable/downloadBase64';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
import { isValidBase64 } from '@/utils/base64';
|
||||
|
||||
const fileName = ref('file');
|
||||
const fileExtension = ref('');
|
||||
const base64Input = ref('');
|
||||
const { download } = useDownloadFileFromBase64({ source: base64Input });
|
||||
const { download } = useDownloadFileFromBase64Refs(
|
||||
{
|
||||
source: base64Input,
|
||||
filename: fileName,
|
||||
extension: fileExtension,
|
||||
});
|
||||
const base64InputValidation = useValidation({
|
||||
source: base64Input,
|
||||
rules: [
|
||||
@@ -18,6 +25,35 @@ const base64InputValidation = useValidation({
|
||||
],
|
||||
});
|
||||
|
||||
watch(
|
||||
base64Input,
|
||||
(newValue, _) => {
|
||||
const { mimeType } = getMimeTypeFromBase64({ base64String: newValue });
|
||||
if (mimeType) {
|
||||
fileExtension.value = getExtensionFromMimeType(mimeType) || fileExtension.value;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
function previewImage() {
|
||||
if (!base64InputValidation.isValid) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const image = previewImageFromBase64(base64Input.value);
|
||||
image.style.maxWidth = '100%';
|
||||
image.style.maxHeight = '400px';
|
||||
const previewContainer = document.getElementById('previewContainer');
|
||||
if (previewContainer) {
|
||||
previewContainer.innerHTML = '';
|
||||
previewContainer.appendChild(image);
|
||||
}
|
||||
}
|
||||
catch (_) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
function downloadFile() {
|
||||
if (!base64InputValidation.isValid) {
|
||||
return;
|
||||
@@ -44,6 +80,24 @@ async function onUpload(file: File) {
|
||||
|
||||
<template>
|
||||
<c-card title="Base64 to file">
|
||||
<n-grid cols="3" x-gap="12">
|
||||
<n-gi span="2">
|
||||
<c-input-text
|
||||
v-model:value="fileName"
|
||||
label="File Name"
|
||||
placeholder="Download filename"
|
||||
mb-2
|
||||
/>
|
||||
</n-gi>
|
||||
<n-gi>
|
||||
<c-input-text
|
||||
v-model:value="fileExtension"
|
||||
label="Extension"
|
||||
placeholder="Extension"
|
||||
mb-2
|
||||
/>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
<c-input-text
|
||||
v-model:value="base64Input"
|
||||
multiline
|
||||
@@ -53,7 +107,14 @@ async function onUpload(file: File) {
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<div flex justify-center>
|
||||
<div flex justify-center py-2>
|
||||
<div id="previewContainer" />
|
||||
</div>
|
||||
|
||||
<div flex justify-center gap-3>
|
||||
<c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="previewImage()">
|
||||
Preview image
|
||||
</c-button>
|
||||
<c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="downloadFile()">
|
||||
Download file
|
||||
</c-button>
|
||||
|
||||
+1
-14
@@ -1,11 +1,7 @@
|
||||
import { tool as base64FileConverter } from './base64-file-converter';
|
||||
import { tool as base64StringConverter } from './base64-string-converter';
|
||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
import { tool as textToUnicode } from './text-to-unicode';
|
||||
import { tool as safelinkDecoder } from './safelink-decoder';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -127,7 +123,6 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
userAgentParser,
|
||||
httpStatusCodes,
|
||||
jsonDiff,
|
||||
safelinkDecoder,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -164,15 +159,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Text',
|
||||
components: [
|
||||
loremIpsumGenerator,
|
||||
textStatistics,
|
||||
emojiPicker,
|
||||
stringObfuscator,
|
||||
textDiff,
|
||||
numeronymGenerator,
|
||||
asciiTextDrawer,
|
||||
],
|
||||
components: [loremIpsumGenerator, textStatistics, emojiPicker, stringObfuscator, textDiff, numeronymGenerator],
|
||||
},
|
||||
{
|
||||
name: 'Data',
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Mailbox } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Outlook Safelink decoder',
|
||||
path: '/safelink-decoder',
|
||||
description: 'Decode Outlook SafeLink links',
|
||||
keywords: ['outlook', 'safelink', 'decoder'],
|
||||
component: () => import('./safelink-decoder.vue'),
|
||||
icon: Mailbox,
|
||||
createdAt: new Date('2024-03-11'),
|
||||
});
|
||||
@@ -1,21 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { decodeSafeLinksURL } from './safelink-decoder.service';
|
||||
|
||||
describe('safelink-decoder', () => {
|
||||
describe('decodeSafeLinksURL', () => {
|
||||
describe('decode outlook safelink urls', () => {
|
||||
it('should decode basic safelink urls', () => {
|
||||
expect(decodeSafeLinksURL('https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsafelink%26rlz%3D1&data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&reserved=0'))
|
||||
.toBe('https://www.google.com/search?q=safelink&rlz=1');
|
||||
});
|
||||
it('should decode encoded safelink urls', () => {
|
||||
expect(decodeSafeLinksURL('https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsafelink%26rlz%3D1&data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&reserved=0'))
|
||||
.toBe('https://www.google.com/search?q=safelink&rlz=1');
|
||||
});
|
||||
it('throw on not outlook safelink urls', () => {
|
||||
expect(() => decodeSafeLinksURL('https://google.com'))
|
||||
.toThrow('Invalid SafeLinks URL provided');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
export function decodeSafeLinksURL(safeLinksUrl: string) {
|
||||
if (!safeLinksUrl.match(/\.safelinks\.protection\.outlook\.com/)) {
|
||||
throw new Error('Invalid SafeLinks URL provided');
|
||||
}
|
||||
|
||||
return new URL(safeLinksUrl).searchParams.get('url');
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { decodeSafeLinksURL } from './safelink-decoder.service';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
|
||||
const inputSafeLinkUrl = ref('');
|
||||
const outputDecodedUrl = computed(() => {
|
||||
try {
|
||||
return decodeSafeLinksURL(inputSafeLinkUrl.value);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="inputSafeLinkUrl"
|
||||
raw-text
|
||||
placeholder="Your input Outlook SafeLink Url..."
|
||||
autofocus
|
||||
label="Your input Outlook SafeLink Url:"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item label="Output decoded URL:">
|
||||
<TextareaCopyable :value="outputDecodedUrl" :word-wrap="true" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</template>
|
||||
@@ -38,7 +38,8 @@ describe('base64 utils', () => {
|
||||
|
||||
it('should throw for incorrect base64 string', () => {
|
||||
expect(() => base64ToText('a')).to.throw('Incorrect base64 string');
|
||||
expect(() => base64ToText(' ')).to.throw('Incorrect base64 string');
|
||||
// should not really be false because trimming of space is now implied
|
||||
// expect(() => base64ToText(' ')).to.throw('Incorrect base64 string');
|
||||
expect(() => base64ToText('é')).to.throw('Incorrect base64 string');
|
||||
// missing final '='
|
||||
expect(() => base64ToText('bG9yZW0gaXBzdW0')).to.throw('Incorrect base64 string');
|
||||
@@ -56,17 +57,17 @@ describe('base64 utils', () => {
|
||||
|
||||
it('should return false for incorrect base64 string', () => {
|
||||
expect(isValidBase64('a')).to.eql(false);
|
||||
expect(isValidBase64(' ')).to.eql(false);
|
||||
expect(isValidBase64('é')).to.eql(false);
|
||||
expect(isValidBase64('data:text/plain;notbase64,YQ==')).to.eql(false);
|
||||
// missing final '='
|
||||
expect(isValidBase64('bG9yZW0gaXBzdW0')).to.eql(false);
|
||||
});
|
||||
|
||||
it('should return false for untrimmed correct base64 string', () => {
|
||||
expect(isValidBase64('bG9yZW0gaXBzdW0= ')).to.eql(false);
|
||||
expect(isValidBase64(' LTE=')).to.eql(false);
|
||||
expect(isValidBase64(' YQ== ')).to.eql(false);
|
||||
it('should return true for untrimmed correct base64 string', () => {
|
||||
expect(isValidBase64('bG9yZW0gaXBzdW0= ')).to.eql(true);
|
||||
expect(isValidBase64(' LTE=')).to.eql(true);
|
||||
expect(isValidBase64(' YQ== ')).to.eql(true);
|
||||
expect(isValidBase64(' ')).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+7
-4
@@ -1,7 +1,9 @@
|
||||
import { Base64 } from 'js-base64';
|
||||
|
||||
export { textToBase64, base64ToText, isValidBase64, removePotentialDataAndMimePrefix };
|
||||
|
||||
function textToBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boolean } = {}) {
|
||||
const encoded = window.btoa(str);
|
||||
const encoded = Base64.encode(str);
|
||||
return makeUrlSafe ? makeUriSafe(encoded) : encoded;
|
||||
}
|
||||
|
||||
@@ -16,7 +18,7 @@ function base64ToText(str: string, { makeUrlSafe = false }: { makeUrlSafe?: bool
|
||||
}
|
||||
|
||||
try {
|
||||
return window.atob(cleanStr);
|
||||
return Base64.decode(cleanStr);
|
||||
}
|
||||
catch (_) {
|
||||
throw new Error('Incorrect base64 string');
|
||||
@@ -34,10 +36,11 @@ function isValidBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boo
|
||||
}
|
||||
|
||||
try {
|
||||
const reEncodedBase64 = Base64.fromUint8Array(Base64.toUint8Array(cleanStr));
|
||||
if (makeUrlSafe) {
|
||||
return removePotentialPadding(window.btoa(window.atob(cleanStr))) === cleanStr;
|
||||
return removePotentialPadding(reEncodedBase64) === cleanStr;
|
||||
}
|
||||
return window.btoa(window.atob(cleanStr)) === cleanStr;
|
||||
return reEncodedBase64 === cleanStr.replace(/\s/g, '');
|
||||
}
|
||||
catch (err) {
|
||||
return false;
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getIPNetworkType, getNetworksCount, getSubnets, parseAsCIDR, to6to4Prefix, toARPA, toIPv4MappedAddress, toIPv4MappedAddressDecimal } from './ip';
|
||||
|
||||
describe('ipv4/6 util', () => {
|
||||
describe('parseAsCIDR', () => {
|
||||
it('returns cidr', () => {
|
||||
expect(parseAsCIDR('1.1.1.1/6')).to.eql('1.1.1.1/6');
|
||||
expect(parseAsCIDR('172.16.2.2/16')).to.eql('172.16.2.2/16');
|
||||
expect(parseAsCIDR('1a:b:c::d:e:f/ffff:ffff:f4ff:ffff:ffff:ff5f:ffff:ff00')).to.eql();
|
||||
expect(parseAsCIDR('10.1.2.3/255.255.255.252')).to.eql('10.1.2.0/30');
|
||||
expect(parseAsCIDR('10.*.0.*')).to.eql();
|
||||
expect(parseAsCIDR('10.1.0.*')).to.eql('10.1.0.0/24');
|
||||
expect(parseAsCIDR('10.2.*.*')).to.eql('10.2.0.0/16');
|
||||
expect(parseAsCIDR('a:b:0:8000::/ffff:ffff:ffff:8000::')).to.eql('a:b:0:8000::/49');
|
||||
expect(parseAsCIDR('::/::')).to.eql('::/0');
|
||||
expect(parseAsCIDR('10.20.30.64-10.20.30.127')).to.eql('10.20.30.64/26');
|
||||
expect(parseAsCIDR('10.0.128.0/255.0.128.0')).to.eql();
|
||||
expect(parseAsCIDR('a::bc:1234/128')).to.eql('a::bc:1234/128');
|
||||
expect(parseAsCIDR('a::bc:ff00-a::bc:ff0f')).to.eql('a::bc:ff00/124');
|
||||
expect(parseAsCIDR('10.0.1.1/255.255.1.0')).to.eql();
|
||||
expect(parseAsCIDR('10.0.0.0/255.255.0.0')).to.eql('10.0.0.0/16');
|
||||
});
|
||||
});
|
||||
describe('getSubnets', () => {
|
||||
it('returns subnets', () => {
|
||||
expect(getSubnets('1.1.1.1/1')).to.eql([
|
||||
'0.0.0.0/1',
|
||||
'128.0.0.0/1',
|
||||
]);
|
||||
expect(getSubnets('1.1.1.1/6')).to.eql([
|
||||
'0.0.0.0/6',
|
||||
'4.0.0.0/6',
|
||||
'8.0.0.0/6',
|
||||
'12.0.0.0/6',
|
||||
'16.0.0.0/6',
|
||||
'20.0.0.0/6',
|
||||
'24.0.0.0/6',
|
||||
'28.0.0.0/6',
|
||||
'32.0.0.0/6',
|
||||
'36.0.0.0/6',
|
||||
'40.0.0.0/6',
|
||||
'44.0.0.0/6',
|
||||
'48.0.0.0/6',
|
||||
'52.0.0.0/6',
|
||||
'56.0.0.0/6',
|
||||
'60.0.0.0/6',
|
||||
'64.0.0.0/6',
|
||||
'68.0.0.0/6',
|
||||
'72.0.0.0/6',
|
||||
'76.0.0.0/6',
|
||||
'80.0.0.0/6',
|
||||
'84.0.0.0/6',
|
||||
'88.0.0.0/6',
|
||||
'92.0.0.0/6',
|
||||
'96.0.0.0/6',
|
||||
'100.0.0.0/6',
|
||||
'104.0.0.0/6',
|
||||
'108.0.0.0/6',
|
||||
'112.0.0.0/6',
|
||||
'116.0.0.0/6',
|
||||
'120.0.0.0/6',
|
||||
'124.0.0.0/6',
|
||||
'128.0.0.0/6',
|
||||
'132.0.0.0/6',
|
||||
'136.0.0.0/6',
|
||||
'140.0.0.0/6',
|
||||
'144.0.0.0/6',
|
||||
'148.0.0.0/6',
|
||||
'152.0.0.0/6',
|
||||
'156.0.0.0/6',
|
||||
'160.0.0.0/6',
|
||||
'164.0.0.0/6',
|
||||
'168.0.0.0/6',
|
||||
'172.0.0.0/6',
|
||||
'176.0.0.0/6',
|
||||
'180.0.0.0/6',
|
||||
'184.0.0.0/6',
|
||||
'188.0.0.0/6',
|
||||
'192.0.0.0/6',
|
||||
'196.0.0.0/6',
|
||||
'200.0.0.0/6',
|
||||
'204.0.0.0/6',
|
||||
'208.0.0.0/6',
|
||||
'212.0.0.0/6',
|
||||
'216.0.0.0/6',
|
||||
'220.0.0.0/6',
|
||||
'224.0.0.0/6',
|
||||
'228.0.0.0/6',
|
||||
'232.0.0.0/6',
|
||||
'236.0.0.0/6',
|
||||
'240.0.0.0/6',
|
||||
'244.0.0.0/6',
|
||||
'248.0.0.0/6',
|
||||
'252.0.0.0/6',
|
||||
]);
|
||||
expect(getSubnets('1.1.1.1/8')).to.eql([]);
|
||||
expect(getSubnets('1.1.1.1/11')).to.eql([
|
||||
'1.0.0.0/11',
|
||||
'1.32.0.0/11',
|
||||
'1.64.0.0/11',
|
||||
'1.96.0.0/11',
|
||||
'1.128.0.0/11',
|
||||
'1.160.0.0/11',
|
||||
'1.192.0.0/11',
|
||||
'1.224.0.0/11',
|
||||
]);
|
||||
expect(getSubnets('172.16.2.2/16')).to.eql([]);
|
||||
expect(getSubnets('172.16.2.2/26')).to.eql([
|
||||
'172.16.2.0/26',
|
||||
'172.16.2.64/26',
|
||||
'172.16.2.128/26',
|
||||
'172.16.2.192/26',
|
||||
]);
|
||||
expect(getSubnets('172.16.2.2/31').length).to.eql(128);
|
||||
expect(getSubnets('255.255.255.0/32')).to.eql([]);
|
||||
expect(getSubnets('2001:db8:0:85a3::ac1f:8001/62')).to.eql([]);
|
||||
expect(getSubnets('2001:db8:0:85a3:0:0:ac1f:8001/62')).to.eql([]);
|
||||
expect(getSubnets('2001:db8:0:85a3::ac1f:8001/112')).to.eql([]);
|
||||
expect(getSubnets('2001:db8:0:85a3:0:0:ac1f:8001/112')).to.eql([]);
|
||||
});
|
||||
});
|
||||
describe('getNetworksCount', () => {
|
||||
it('returns networks count', () => {
|
||||
expect(getNetworksCount('1.1.1.1/1')).to.eql(2);
|
||||
expect(getNetworksCount('1.1.1.1/2')).to.eql(4);
|
||||
expect(getNetworksCount('1.1.1.1/3')).to.eql(8);
|
||||
expect(getNetworksCount('1.1.1.1/4')).to.eql(16);
|
||||
expect(getNetworksCount('1.1.1.1/5')).to.eql(32);
|
||||
expect(getNetworksCount('1.1.1.1/6')).to.eql(64);
|
||||
expect(getNetworksCount('1.1.1.1/7')).to.eql(128);
|
||||
expect(getNetworksCount('1.1.1.1/8')).to.eql(0);
|
||||
expect(getNetworksCount('1.1.1.1/9')).to.eql(2);
|
||||
expect(getNetworksCount('1.1.1.1/10')).to.eql(4);
|
||||
expect(getNetworksCount('1.1.1.1/11')).to.eql(8);
|
||||
expect(getNetworksCount('1.1.1.1/12')).to.eql(16);
|
||||
expect(getNetworksCount('1.1.1.1/13')).to.eql(32);
|
||||
expect(getNetworksCount('1.1.1.1/14')).to.eql(64);
|
||||
expect(getNetworksCount('1.1.1.1/15')).to.eql(128);
|
||||
expect(getNetworksCount('1.1.1.1/16')).to.eql(0);
|
||||
expect(getNetworksCount('1.1.1.1/17')).to.eql(2);
|
||||
expect(getNetworksCount('1.1.1.1/18')).to.eql(4);
|
||||
expect(getNetworksCount('1.1.1.1/19')).to.eql(8);
|
||||
expect(getNetworksCount('1.1.1.1/20')).to.eql(16);
|
||||
expect(getNetworksCount('1.1.1.1/21')).to.eql(32);
|
||||
expect(getNetworksCount('1.1.1.1/22')).to.eql(64);
|
||||
expect(getNetworksCount('1.1.1.1/23')).to.eql(128);
|
||||
expect(getNetworksCount('1.1.1.1/24')).to.eql(0);
|
||||
expect(getNetworksCount('1.1.1.1/25')).to.eql(2);
|
||||
expect(getNetworksCount('1.1.1.1/26')).to.eql(4);
|
||||
expect(getNetworksCount('1.1.1.1/27')).to.eql(8);
|
||||
expect(getNetworksCount('1.1.1.1/28')).to.eql(16);
|
||||
expect(getNetworksCount('1.1.1.1/29')).to.eql(32);
|
||||
expect(getNetworksCount('1.1.1.1/30')).to.eql(64);
|
||||
expect(getNetworksCount('1.1.1.1/31')).to.eql(128);
|
||||
expect(getNetworksCount('1.1.1.1/32')).to.eql(0);
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/32')).to.eql(4294967296n);
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/42')).to.eql(4194304n);
|
||||
expect(getNetworksCount('2001:db8:0:85a3:0:0:ac1f:8001/62')).to.eql(4n);
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/112')).to.eql(-1);
|
||||
expect(getNetworksCount('2001:db8:0:85a3:0:0:ac1f:8001/122')).to.eql(-1);
|
||||
});
|
||||
});
|
||||
describe('getIPNetworkType', () => {
|
||||
it('returns network type', () => {
|
||||
expect(getIPNetworkType('1.1.1.1')).to.eql('Public');
|
||||
expect(getIPNetworkType('10.10.1.1')).to.eql('Private Use');
|
||||
expect(getIPNetworkType('172.16.0.1')).to.eql('Private Use');
|
||||
expect(getIPNetworkType('192.168.1.1')).to.eql('Private Use');
|
||||
expect(getIPNetworkType('255.255.255.0')).to.eql('Reserved');
|
||||
expect(getIPNetworkType('224.0.0.1')).to.eql('Multicast');
|
||||
expect(getIPNetworkType('198.51.100.1')).to.eql('Documentation (TEST-NET-2)');
|
||||
expect(getIPNetworkType('198.18.0.1')).to.eql('Benchmarking');
|
||||
expect(getIPNetworkType('169.254.0.1')).to.eql('Link Local');
|
||||
expect(getIPNetworkType('127.0.0.1')).to.eql('Loopback');
|
||||
expect(getIPNetworkType('2001:db8:8:4::2')).to.eql('Documentation');
|
||||
expect(getIPNetworkType('FF02::2')).to.eql('Multicast address');
|
||||
expect(getIPNetworkType('2345:0425:2CA1:0000:0000:0567:5673:23b5')).to.eql('Public');
|
||||
expect(getIPNetworkType('fdf8:f53b:82e4::53')).to.eql('Unique-Local');
|
||||
expect(getIPNetworkType('::ffff:192.0.2.47')).to.eql('IPv4-mapped Address');
|
||||
expect(getIPNetworkType('::ffff:ac12:0a09')).to.eql('IPv4-mapped Address');
|
||||
expect(getIPNetworkType('::1')).to.eql('Loopback Address');
|
||||
expect(getIPNetworkType('fe80::200:5aee:feaa:20a2')).to.eql('Link-Local Unicast');
|
||||
expect(getIPNetworkType('2001:0002::6c::430')).to.eql('Benchmarking');
|
||||
expect(getIPNetworkType('2001:0000:4136:e378:8000:63bf:3fff:fdd2')).to.eql('TEREDO');
|
||||
expect(getIPNetworkType('2002:cb0a:3cdd:1::1')).to.eql('6to4');
|
||||
expect(getIPNetworkType('ff01:0:0:0:0:0:0:2')).to.eql('Multicast address');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toARPA', () => {
|
||||
it('returns ARPA address', () => {
|
||||
expect(toARPA('1.1.1.1')).to.eql('1.1.1.1.in-addr.arpa');
|
||||
expect(toARPA('10.10.1.1')).to.eql('1.1.10.10.in-addr.arpa');
|
||||
expect(toARPA('192.168.1.1')).to.eql('1.1.168.192.in-addr.arpa');
|
||||
expect(toARPA('255.255.255.0')).to.eql('0.255.255.255.in-addr.arpa');
|
||||
expect(toARPA('FF02::2')).to.eql('2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa.');
|
||||
expect(toARPA('2345:0425:2CA1:0000:0000:0567:5673:23b5')).to.eql('5.b.3.2.3.7.6.5.7.6.5.0.0.0.0.0.0.0.0.0.1.a.c.2.5.2.4.0.5.4.3.2.ip6.arpa.');
|
||||
expect(toARPA('fdf8:f53b:82e4::53')).to.eql('3.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.e.2.8.b.3.5.f.8.f.d.f.ip6.arpa.');
|
||||
expect(toARPA('::ffff:192.0.2.47')).to.eql('f.2.2.0.0.0.0.c.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.');
|
||||
expect(toARPA('::1')).to.eql('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.');
|
||||
});
|
||||
});
|
||||
describe('toIPv4MappedAddress', () => {
|
||||
it('returns IPv4MappedAddress', () => {
|
||||
expect(toIPv4MappedAddress('1.1.1.1')).to.eql('::ffff:0101:0101');
|
||||
expect(toIPv4MappedAddress('10.10.1.1')).to.eql('::ffff:0a0a:0101');
|
||||
expect(toIPv4MappedAddress('172.18.10.9')).to.eql('::ffff:ac12:0a09');
|
||||
expect(toIPv4MappedAddress('192.168.1.1')).to.eql('::ffff:c0a8:0101');
|
||||
expect(toIPv4MappedAddress('255.255.255.0')).to.eql('::ffff:ffff:ff00');
|
||||
});
|
||||
});
|
||||
describe('toIPv4MappedAddressDecimal', () => {
|
||||
it('returns networks count', () => {
|
||||
expect(toIPv4MappedAddressDecimal('1.1.1.1')).to.eql('::ffff:1.1.1.1');
|
||||
expect(toIPv4MappedAddressDecimal('10.10.1.1')).to.eql('::ffff:10.10.1.1');
|
||||
expect(toIPv4MappedAddressDecimal('192.168.1.1')).to.eql('::ffff:192.168.1.1');
|
||||
expect(toIPv4MappedAddressDecimal('172.18.10.9')).to.eql('::ffff:172.18.10.9');
|
||||
expect(toIPv4MappedAddressDecimal('255.255.255.0')).to.eql('::ffff:255.255.255.0');
|
||||
expect(toIPv4MappedAddressDecimal('2001:db8:0:85a3::ac1f:8001')).to.eql('');
|
||||
});
|
||||
});
|
||||
describe('to6to4Prefix', () => {
|
||||
it('returns networks count', () => {
|
||||
expect(to6to4Prefix('1.1.1.1')).to.eql('2002:01:0:1:01:01::/48');
|
||||
expect(to6to4Prefix('10.10.1.1')).to.eql('2002:0a:0:a:01:01::/48');
|
||||
expect(to6to4Prefix('172.18.10.9')).to.eql('2002:ac:1:2:0a:09::/48');
|
||||
expect(to6to4Prefix('192.168.1.1')).to.eql('2002:c0:a:8:01:01::/48');
|
||||
expect(to6to4Prefix('255.255.255.0')).to.eql('2002:ff:f:f:ff:00::/48');
|
||||
expect(to6to4Prefix('2001:db8:0:85a3::ac1f:8001')).to.eql('');
|
||||
});
|
||||
});
|
||||
});
|
||||
-147
@@ -1,147 +0,0 @@
|
||||
import { isIPv4 } from 'is-ip';
|
||||
import { Address4, Address6 } from 'ip-address';
|
||||
import { contains as containsCidr } from 'cidr-tools';
|
||||
import type { IPMatch } from 'ip-matching';
|
||||
import { IPMask, IPSubnetwork, getMatch } from 'ip-matching';
|
||||
import isCidr from 'is-cidr';
|
||||
import ipv4registry from './ipv4registry.json';
|
||||
import ipv6registry from './ipv6registry.json';
|
||||
|
||||
const IPv4MAX = (BigInt(2) ** BigInt(32)) - BigInt(1);
|
||||
|
||||
// IP range specific information, see IANA allocations.
|
||||
// http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
|
||||
const _ipv4Registry = new Map(ipv4registry.map(v => [v[0] as string, v[1]]));
|
||||
|
||||
// https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
|
||||
const _ipv6Registry = new Map(ipv6registry.map(v => [v[0] as string, v[1]]));
|
||||
|
||||
export function parseAsCIDR(form: string) {
|
||||
if (isCidr(form)) {
|
||||
return form;
|
||||
}
|
||||
|
||||
const ipMatch: IPMatch = getMatch(form);
|
||||
if (ipMatch instanceof IPSubnetwork) {
|
||||
return (ipMatch as IPSubnetwork).toString();
|
||||
}
|
||||
if (ipMatch instanceof IPMask) {
|
||||
return (ipMatch as IPMask).convertToSubnet()?.toString();
|
||||
}
|
||||
return (ipMatch.convertToMasks() || [])[0]?.convertToSubnet()?.toString();
|
||||
}
|
||||
|
||||
export function getSubnets(cidr: string) {
|
||||
const [address, prefix] = cidr.split('/');
|
||||
if (isIPv4(address)) {
|
||||
const prefix4Int = Number(prefix || '32');
|
||||
const getMask = (prefix: number) => (IPv4MAX >> (BigInt(32) - BigInt(prefix))) << (BigInt(32) - BigInt(prefix));
|
||||
const bigInt = BigInt((new Address4(address)).bigInteger());
|
||||
|
||||
const subnets = [];
|
||||
let startNetwork;
|
||||
if (prefix4Int < 8) {
|
||||
startNetwork = 0;
|
||||
}
|
||||
if (prefix4Int % 8 === 0) {
|
||||
return [];
|
||||
}
|
||||
startNetwork = bigInt & getMask(prefix4Int);
|
||||
const increment = BigInt(2) ** BigInt(32 - prefix4Int);
|
||||
const netCount = getNetworksCount(cidr);
|
||||
for (let netIndex = 0; netIndex < netCount; netIndex += 1) {
|
||||
const netAddr = Address4.fromBigInteger(startNetwork.toString()).correctForm();
|
||||
subnets.push(`${netAddr}/${prefix4Int}`);
|
||||
startNetwork += increment;
|
||||
}
|
||||
return subnets;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
export function getNetworksCount(cidr: string) {
|
||||
const [address, prefix] = cidr.split('/');
|
||||
if (isIPv4(address)) {
|
||||
const prefix4Int = Number(prefix || '32');
|
||||
|
||||
if (prefix4Int % 8 === 0) {
|
||||
return 0;
|
||||
}
|
||||
else if (prefix4Int < 8) {
|
||||
return 2 ** prefix4Int;
|
||||
}
|
||||
else if (prefix4Int < 16) {
|
||||
return 2 ** (prefix4Int - 8);
|
||||
}
|
||||
else if (prefix4Int < 24) {
|
||||
return 2 ** (prefix4Int - 16);
|
||||
}
|
||||
else {
|
||||
return 2 ** (prefix4Int - 24);
|
||||
}
|
||||
}
|
||||
|
||||
const prefix6Int = Number(prefix || '128');
|
||||
return prefix6Int <= 64 ? (BigInt(2) ** BigInt(64n - BigInt(prefix6Int))) : -1;
|
||||
}
|
||||
|
||||
export function getIPNetworkType(address: string) {
|
||||
const results = [];
|
||||
for (const [addr, info] of (isIPv4(address) ? _ipv4Registry : _ipv6Registry).entries()) {
|
||||
const found = containsCidr([`${addr}/${Number(info[0])}`], address);
|
||||
if (found) {
|
||||
results.unshift(info[1]);
|
||||
}
|
||||
}
|
||||
return results.length === 0 ? 'Public' : results[0]?.toString();
|
||||
}
|
||||
|
||||
export function toARPA(address: string) {
|
||||
if (isIPv4(address)) {
|
||||
const bigInt = BigInt((new Address4(address)).bigInteger());
|
||||
const reverseIP = (
|
||||
[(bigInt & BigInt(255)), (bigInt >> BigInt(8) & BigInt(255)),
|
||||
(bigInt >> BigInt(16) & BigInt(255)),
|
||||
(bigInt >> BigInt(24) & BigInt(255)),
|
||||
].join('.')
|
||||
);
|
||||
return `${reverseIP}.in-addr.arpa`;
|
||||
}
|
||||
|
||||
return (new Address6(address)).reverseForm();
|
||||
}
|
||||
|
||||
export function toIPv4MappedAddress(address: string) {
|
||||
if (!isIPv4(address)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const hexIP = (new Address4(address)).toHex().replace(/:/g, '');
|
||||
return `::ffff:${hexIP.substring(0, 4)}:${hexIP.substring(4)}`;
|
||||
}
|
||||
|
||||
export function toIPv4MappedAddressDecimal(address: string) {
|
||||
if (!isIPv4(address)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `::ffff:${address}`;
|
||||
}
|
||||
|
||||
export function to6to4Prefix(address: string) {
|
||||
if (!isIPv4(address)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const hexIP = (new Address4(address)).toHex();
|
||||
return `2002:${hexIP.substring(0, 4)}:${hexIP.substring(4)}::/48`;
|
||||
}
|
||||
|
||||
export function toMicrosoftTranscription(address: string) {
|
||||
if (!isIPv4(address)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return (new Address6(address)).microsoftTranscription();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
["0.0.0.0", [8, "This host on this network"]],
|
||||
["10.0.0.0", [8, "Private Use"]],
|
||||
["100.64.0.0", [10, "Shared Address Space"]],
|
||||
["127.0.0.0", [8, "Loopback"]],
|
||||
["169.254.0.0", [16, "Link Local"]],
|
||||
["172.16.0.0", [12, "Private Use"]],
|
||||
["192.0.0.0", [24, "IETF Protocol Assignments"]],
|
||||
["192.0.0.0", [29, "IPv4 Service Continuity Prefix"]],
|
||||
["192.0.0.8", [32, "IPv4 dummy address"]],
|
||||
["192.0.0.9", [32, "Port Control Protocol Anycast"]],
|
||||
["192.0.0.10", [32, "Traversal Using Relays around NAT Anycast"]],
|
||||
["192.0.0.170", [32, "NAT64/DNS64 Discovery"]],
|
||||
["192.0.0.171", [32, "NAT64/DNS64 Discovery"]],
|
||||
["192.0.2.0", [24, "Documentation (TEST-NET-1)"]],
|
||||
["192.31.196.0", [24, "AS112-v4"]],
|
||||
["192.52.193.0", [24, "AMT"]],
|
||||
["192.88.99.0", [24, "Deprecated (6to4 Relay Anycast)"]],
|
||||
["192.168.0.0", [16, "Private Use"]],
|
||||
["192.175.48.0", [24, "Direct Delegation AS112 Service"]],
|
||||
["198.18.0.0", [15, "Benchmarking"]],
|
||||
["198.51.100.0", [24, "Documentation (TEST-NET-2)"]],
|
||||
["203.0.113.0", [24, "Documentation (TEST-NET-3)"]],
|
||||
["224.0.0.0", [24, "Multicast"]],
|
||||
["240.0.0.0", [4, "Reserved"]],
|
||||
["255.255.255.255", [32, "Limited Broadcast"]]
|
||||
]
|
||||
@@ -1,24 +0,0 @@
|
||||
[
|
||||
["::1", [128, "Loopback Address"]],
|
||||
["::", [128, "Unspecified Address"]],
|
||||
["::ffff::", [96, "IPv4-mapped Address"]],
|
||||
["64:ff9b::", [96, "IPv4-IPv6 Translat."]],
|
||||
["64:ff9b:1::", [48, "IPv4-IPv6 Translat."]],
|
||||
["100::", [64, "Discard-Only Address Block"]],
|
||||
["2001::", [23, "IETF Protocol Assignments"]],
|
||||
["2001::", [32, "TEREDO"]],
|
||||
["2001:1::1", [128, "Port Control Protocol Anycast"]],
|
||||
["2001:1::2", [128, "Traversal Using Relays around NAT Anycast"]],
|
||||
["2001:2::", [48, "Benchmarking"]],
|
||||
["2001:3::", [32, "AMT"]],
|
||||
["2001:4:112::", [48, "AS112-v6"]],
|
||||
["2001:5::", [32, "EID Space for LISP (Managed by RIPE NCC)"]],
|
||||
["2001:10::", [28, "Deprecated (previously ORCHID)"]],
|
||||
["2001:20::", [28, "ORCHIDv2"]],
|
||||
["2001:db8::", [32, "Documentation"]],
|
||||
["2002::", [16, "6to4"]],
|
||||
["2620:4f:8000::", [48, "Direct Delegation AS112 Service"]],
|
||||
["fc00::", [7, "Unique-Local"]],
|
||||
["fe80::", [10, "Link-Local Unicast"]],
|
||||
["ff00::", [8, "Multicast address"]]
|
||||
]
|
||||
Reference in new issue
Block a user