mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 06:40:20 +03:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2664b78bbb | ||
|
|
6fadc83c4b | ||
|
|
0e73e5885c |
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
+5
-8
@@ -64,8 +64,6 @@ declare module '@vue/runtime-core' {
|
||||
'CTextCopyable.demo': typeof import('./src/ui/c-text-copyable/c-text-copyable.demo.vue')['default']
|
||||
CTooltip: typeof import('./src/ui/c-tooltip/c-tooltip.vue')['default']
|
||||
'CTooltip.demo': typeof import('./src/ui/c-tooltip/c-tooltip.demo.vue')['default']
|
||||
DataStorageUnitConverter: typeof import('./src/tools/data-storage-unit-converter/data-storage-unit-converter.vue')['default']
|
||||
DataTransferRateConverter: typeof import('./src/tools/data-transfer-rate-converter/data-transfer-rate-converter.vue')['default']
|
||||
DateTimeConverter: typeof import('./src/tools/date-time-converter/date-time-converter.vue')['default']
|
||||
'DemoHome.page': typeof import('./src/ui/demo/demo-home.page.vue')['default']
|
||||
DemoWrapper: typeof import('./src/ui/demo/demo-wrapper.vue')['default']
|
||||
@@ -132,9 +130,7 @@ declare module '@vue/runtime-core' {
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NButton: typeof import('naive-ui')['NButton']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
@@ -142,13 +138,14 @@ declare module '@vue/runtime-core' {
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
NInput: typeof import('naive-ui')['NInput']
|
||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NStatistic: typeof import('naive-ui')['NStatistic']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
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']
|
||||
@@ -166,7 +163,7 @@ declare module '@vue/runtime-core' {
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
|
||||
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
|
||||
SlaCalculator: typeof import('./src/tools/sla-calculator/sla-calculator.vue')['default']
|
||||
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
|
||||
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
|
||||
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
"@tiptap/pm": "2.1.6",
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@types/big.js": "^6.2.2",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@vicons/material": "^0.12.0",
|
||||
@@ -50,6 +51,7 @@
|
||||
"@vueuse/head": "^1.0.0",
|
||||
"@vueuse/router": "^10.0.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"big.js": "^6.2.2",
|
||||
"change-case": "^4.1.2",
|
||||
"colord": "^2.9.3",
|
||||
"composerize-ts": "^0.6.2",
|
||||
@@ -81,9 +83,11 @@
|
||||
"netmask": "^2.0.2",
|
||||
"node-forge": "^1.3.1",
|
||||
"oui-data": "^1.0.10",
|
||||
"parse-duration": "^1.1.0",
|
||||
"pdf-signature-reader": "^1.4.2",
|
||||
"pinia": "^2.0.34",
|
||||
"plausible-tracker": "^0.3.8",
|
||||
"pretty-ms": "^9.1.0",
|
||||
"qrcode": "^1.5.1",
|
||||
"randexp": "^0.5.3",
|
||||
"sql-formatter": "^13.0.0",
|
||||
|
||||
Generated
+39
-3
@@ -26,6 +26,9 @@ 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/big.js':
|
||||
specifier: ^6.2.2
|
||||
version: 6.2.2
|
||||
'@types/figlet':
|
||||
specifier: ^1.5.8
|
||||
version: 1.5.8
|
||||
@@ -50,6 +53,9 @@ dependencies:
|
||||
bcryptjs:
|
||||
specifier: ^2.4.3
|
||||
version: 2.4.3
|
||||
big.js:
|
||||
specifier: ^6.2.2
|
||||
version: 6.2.2
|
||||
change-case:
|
||||
specifier: ^4.1.2
|
||||
version: 4.1.2
|
||||
@@ -143,6 +149,9 @@ dependencies:
|
||||
oui-data:
|
||||
specifier: ^1.0.10
|
||||
version: 1.0.10
|
||||
parse-duration:
|
||||
specifier: ^1.1.0
|
||||
version: 1.1.0
|
||||
pdf-signature-reader:
|
||||
specifier: ^1.4.2
|
||||
version: 1.4.2
|
||||
@@ -152,6 +161,9 @@ dependencies:
|
||||
plausible-tracker:
|
||||
specifier: ^0.3.8
|
||||
version: 0.3.8
|
||||
pretty-ms:
|
||||
specifier: ^9.1.0
|
||||
version: 9.1.0
|
||||
qrcode:
|
||||
specifier: ^1.5.1
|
||||
version: 1.5.1
|
||||
@@ -2920,6 +2932,10 @@ packages:
|
||||
resolution: {integrity: sha512-LiMQ6EOPob/4yUL66SZzu6Yh77cbzJFYll+ZfaPiPPFswtIlA/Fs1MzdKYA7JApHU49zQTbJGX3PDmCpIdDBRQ==}
|
||||
dev: true
|
||||
|
||||
/@types/big.js@6.2.2:
|
||||
resolution: {integrity: sha512-e2cOW9YlVzFY2iScnGBBkplKsrn2CsObHQ2Hiw4V1sSyiGbgWL8IyqE3zFi1Pt5o1pdAtYkDAIsF3KKUPjdzaA==}
|
||||
dev: false
|
||||
|
||||
/@types/chai-subset@1.3.3:
|
||||
resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==}
|
||||
dependencies:
|
||||
@@ -3395,7 +3411,7 @@ packages:
|
||||
dependencies:
|
||||
'@unhead/dom': 0.5.1
|
||||
'@unhead/schema': 0.5.1
|
||||
'@vueuse/shared': 11.0.3(vue@3.3.4)
|
||||
'@vueuse/shared': 11.1.0(vue@3.3.4)
|
||||
unhead: 0.5.1
|
||||
vue: 3.3.4
|
||||
transitivePeerDependencies:
|
||||
@@ -4037,8 +4053,8 @@ packages:
|
||||
- vue
|
||||
dev: false
|
||||
|
||||
/@vueuse/shared@11.0.3(vue@3.3.4):
|
||||
resolution: {integrity: sha512-0rY2m6HS5t27n/Vp5cTDsKTlNnimCqsbh/fmT2LgE+aaU42EMfXo8+bNX91W9I7DDmxfuACXMmrd7d79JxkqWA==}
|
||||
/@vueuse/shared@11.1.0(vue@3.3.4):
|
||||
resolution: {integrity: sha512-YUtIpY122q7osj+zsNMFAfMTubGz0sn5QzE5gPzAIiCmtt2ha3uQUY1+JPyL4gRCTsLPX82Y9brNbo/aqlA91w==}
|
||||
dependencies:
|
||||
vue-demi: 0.14.10(vue@3.3.4)
|
||||
transitivePeerDependencies:
|
||||
@@ -4261,6 +4277,10 @@ packages:
|
||||
resolution: {integrity: sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ==}
|
||||
dev: false
|
||||
|
||||
/big.js@6.2.2:
|
||||
resolution: {integrity: sha512-y/ie+Faknx7sZA5MfGA2xKlu0GDv8RWrXGsmlteyJQ2lvoKv9GBK/fpRMc2qlSoBAgNxrixICFCBefIq8WCQpQ==}
|
||||
dev: false
|
||||
|
||||
/binary-extensions@2.2.0:
|
||||
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -7344,6 +7364,10 @@ packages:
|
||||
callsites: 3.1.0
|
||||
dev: true
|
||||
|
||||
/parse-duration@1.1.0:
|
||||
resolution: {integrity: sha512-z6t9dvSJYaPoQq7quMzdEagSFtpGu+utzHqqxmpVWNNZRIXnvqyCvn9XsTdh7c/w0Bqmdz3RB3YnRaKtpRtEXQ==}
|
||||
dev: false
|
||||
|
||||
/parse-entities@2.0.0:
|
||||
resolution: {integrity: sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==}
|
||||
dependencies:
|
||||
@@ -7365,6 +7389,11 @@ packages:
|
||||
lines-and-columns: 1.2.4
|
||||
dev: true
|
||||
|
||||
/parse-ms@4.0.0:
|
||||
resolution: {integrity: sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==}
|
||||
engines: {node: '>=18'}
|
||||
dev: false
|
||||
|
||||
/parse-node-version@1.0.1:
|
||||
resolution: {integrity: sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==}
|
||||
engines: {node: '>= 0.10'}
|
||||
@@ -7572,6 +7601,13 @@ packages:
|
||||
react-is: 18.2.0
|
||||
dev: true
|
||||
|
||||
/pretty-ms@9.1.0:
|
||||
resolution: {integrity: sha512-o1piW0n3tgKIKCwk2vpM/vOV13zjJzvP37Ioze54YlTHE06m4tjEbzg9WsKkvTuyYln2DHjo5pY4qrZGI0otpw==}
|
||||
engines: {node: '>=18'}
|
||||
dependencies:
|
||||
parse-ms: 4.0.0
|
||||
dev: false
|
||||
|
||||
/prosemirror-changeset@2.2.1:
|
||||
resolution: {integrity: sha512-J7msc6wbxB4ekDFj+n9gTW/jav/p53kdlivvuppHsrZXCaQdVgRghoZbSS3kwrRyAstRVQ4/+u5k7YfLgkkQvQ==}
|
||||
dependencies:
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { convertStorageAndRateUnitsDisplay, displayStorageAndRateUnits } from './data-storage-unit-converter.service';
|
||||
|
||||
describe('data-storage-unit-converter', () => {
|
||||
describe('convertStorageAndRateUnitsDisplay', () => {
|
||||
it('convert from same base units', () => {
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1024 * 1024, fromUnit: 'B', toUnit: 'MiB' })).toBe('1');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1024, fromUnit: 'KiB', toUnit: 'MiB' })).toBe('1');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1, fromUnit: 'MiB', toUnit: 'KiB' })).toBe('1024');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1000, fromUnit: 'MB', toUnit: 'GB' })).toBe('1');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1024, fromUnit: 'MB', toUnit: 'MB' })).toBe('1024');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1, fromUnit: 'MB', toUnit: 'KB' })).toBe('1000');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1024, fromUnit: 'MiB', toUnit: 'GiB' })).toBe('1');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1000, fromUnit: 'MB', toUnit: 'GB' })).toBe('1');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1000, fromUnit: 'Mb', toUnit: 'Gb' })).toBe('1');
|
||||
});
|
||||
|
||||
it('convert between base units', () => {
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1, fromUnit: 'MB', toUnit: 'MiB' })).toBe('0.954');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1, fromUnit: 'MiB', toUnit: 'MB' })).toBe('1.049');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1000 * 1000, fromUnit: 'B', toUnit: 'MiB' })).toBe('0.954');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1024, fromUnit: 'KB', toUnit: 'MiB' })).toBe('0.977');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1000, fromUnit: 'MiB', toUnit: 'MB' })).toBe('1048.576');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1, fromUnit: 'MB', toUnit: 'Mb' })).toBe('8');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1000, fromUnit: 'KB', toUnit: 'Kb' })).toBe('8000');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1000, fromUnit: 'KiB', toUnit: 'Kb' })).toBe('8192');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 8, fromUnit: 'Mb', toUnit: 'MB' })).toBe('1');
|
||||
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1, fromUnit: 'Mb', toUnit: 'KB' })).toBe('125');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 125, fromUnit: 'KB', toUnit: 'Mb' })).toBe('1');
|
||||
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1, fromUnit: 'MiB', toUnit: 'Kb' })).toBe('8388.608');
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 8388.608, fromUnit: 'Kb', toUnit: 'MiB' })).toBe('1');
|
||||
});
|
||||
it('convert with unit display', () => {
|
||||
expect(convertStorageAndRateUnitsDisplay({ value: 1024 * 1024, fromUnit: 'B', toUnit: 'MiB', appendUnit: true })).toBe('1MiB');
|
||||
});
|
||||
|
||||
//
|
||||
});
|
||||
describe('displayStorageAndRateUnits', () => {
|
||||
it('convert to correct display value', () => {
|
||||
expect(displayStorageAndRateUnits({
|
||||
value: 1.234567, unit: 'MB', appendUnit: false,
|
||||
})).toBe('1.235');
|
||||
expect(displayStorageAndRateUnits({
|
||||
value: 1.234567, unit: 'MB', appendUnit: true,
|
||||
})).toBe('1.235MB');
|
||||
expect(displayStorageAndRateUnits({
|
||||
value: 1.234567, unit: 'MB', appendUnit: true, precision: 5,
|
||||
})).toBe('1.23457MB');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,45 +0,0 @@
|
||||
export type BibytesUnits = 'iB' | 'KiB' | 'MiB' | 'GiB' | 'TiB' | 'PiB' | 'EiB' | 'ZiB' | 'YiB';
|
||||
export type BytesUnits = 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'PB' | 'EB' | 'ZB' | 'YB';
|
||||
export type BitsUnits = 'b' | 'Kb' | 'Mb' | 'Gb' | 'Tb' | 'Pb' | 'Eb' | 'Zb' | 'Yb';
|
||||
export type AllSupportedUnits = BibytesUnits | BytesUnits | BitsUnits;
|
||||
|
||||
export function displayStorageAndRateUnits(
|
||||
{ value, unit, precision = 3, appendUnit = false }:
|
||||
{ value: number; unit: AllSupportedUnits; precision?: number ; appendUnit?: boolean }): string {
|
||||
return value.toFixed(precision).replace(/0+$/, '').replace(/\.$/, '') + (appendUnit ? unit : ''); // NOSONAR
|
||||
}
|
||||
|
||||
export function convertStorageAndRateUnitsDisplay(
|
||||
{ value, fromUnit, toUnit, precision = 3, appendUnit = false }:
|
||||
{ value: number; fromUnit: AllSupportedUnits; toUnit: AllSupportedUnits; precision?: number; appendUnit?: boolean }): string {
|
||||
return displayStorageAndRateUnits({
|
||||
precision,
|
||||
unit: toUnit,
|
||||
appendUnit,
|
||||
value: convertStorageAndRateUnits({
|
||||
value, fromUnit, toUnit,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function convertStorageAndRateUnits(
|
||||
{ value, fromUnit, toUnit }:
|
||||
{ value: number; fromUnit: AllSupportedUnits; toUnit: AllSupportedUnits }): number {
|
||||
const units = [
|
||||
'iB', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB',
|
||||
'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB',
|
||||
'b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb',
|
||||
];
|
||||
|
||||
const fromIndex = units.indexOf(fromUnit);
|
||||
const fromFactor = fromIndex / 9 > 1 ? 1000 : 1024;
|
||||
const fromDivisor = fromIndex / 9 > 2 ? 8 : 1;
|
||||
const toIndex = units.indexOf(toUnit);
|
||||
const toFactor = toIndex / 9 > 1 ? 1000 : 1024;
|
||||
const toDivisor = toIndex / 9 > 2 ? 8 : 1;
|
||||
|
||||
const fromBase = (fromFactor ** (fromIndex % 9)) / fromDivisor;
|
||||
const toBase = (toFactor ** (toIndex % 9)) / toDivisor;
|
||||
|
||||
return value * fromBase / toBase;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import InputCopyable from '../../components/InputCopyable.vue';
|
||||
import { type AllSupportedUnits, convertStorageAndRateUnitsDisplay } from './data-storage-unit-converter.service';
|
||||
|
||||
const input = ref<{ size: string; unit: string }>({ size: '0', unit: 'KB' });
|
||||
const output = ref<{ unit: string; precision: number; appendUnit: boolean }>({ unit: 'MB', precision: 3, appendUnit: false });
|
||||
|
||||
const allUnits = [
|
||||
{ value: 'B', label: 'Bytes (B)' },
|
||||
{ value: 'b', label: 'Bits (bit)' },
|
||||
{ value: 'iB', label: 'Bibytes (iB)' },
|
||||
{ value: 'KB', label: 'Kilobytes (KB)' },
|
||||
{ value: 'Kb', label: 'Kilobits (Kbit)' },
|
||||
{ value: 'KiB', label: 'Kibibytes (KiB)' },
|
||||
{ value: 'MB', label: 'Megabytes (MB)' },
|
||||
{ value: 'Mb', label: 'Megabits (Mbit)' },
|
||||
{ value: 'MiB', label: 'Mebibytes (MiB)' },
|
||||
{ value: 'GB', label: 'Gigabytes (GB)' },
|
||||
{ value: 'Gb', label: 'Gigabits (Gbit)' },
|
||||
{ value: 'GiB', label: 'Gibibytes (GiB)' },
|
||||
{ value: 'TB', label: 'Terabytes (TB)' },
|
||||
{ value: 'Tb', label: 'Terabits (Tbit)' },
|
||||
{ value: 'TiB', label: 'Tebibytes (TiB)' },
|
||||
{ value: 'PB', label: 'Petabytes (PB)' },
|
||||
{ value: 'Pb', label: 'Petabits (Pbit)' },
|
||||
{ value: 'PiB', label: 'Pebibytes (PiB)' },
|
||||
{ value: 'EB', label: 'Exabytes (EB)' },
|
||||
{ value: 'Eb', label: 'Exabits (Ebit)' },
|
||||
{ value: 'EiB', label: 'Exbibytes (EiB)' },
|
||||
{ value: 'ZB', label: 'Zettabytes (ZB)' },
|
||||
{ value: 'Zb', label: 'Zettabits (Zbit)' },
|
||||
{ value: 'ZiB', label: 'Zebibytes (ZiB)' },
|
||||
{ value: 'YB', label: 'Yottabytes (YB)' },
|
||||
{ value: 'Yb', label: 'Yottabits (Ybit)' },
|
||||
{ value: 'YiB', label: 'Yobibytes (YiB)' },
|
||||
];
|
||||
|
||||
const convertedValue = computed(() => {
|
||||
try {
|
||||
return convertStorageAndRateUnitsDisplay({
|
||||
value: Number(input.value.size),
|
||||
fromUnit: input.value.unit as AllSupportedUnits,
|
||||
toUnit: output.value.unit as AllSupportedUnits,
|
||||
precision: output.value.precision,
|
||||
appendUnit: output.value.appendUnit,
|
||||
});
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card>
|
||||
<n-form-item label="Input Size:" label-placement="left" mb-1>
|
||||
<c-input-text
|
||||
v-model:value="input.size"
|
||||
placeholder="Put your number here (ex: 1024)"
|
||||
mr-2
|
||||
/>
|
||||
<c-select
|
||||
v-model:value="input.unit"
|
||||
:options="allUnits"
|
||||
placeholder="Select input unit"
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<div flex items-baseline gap-2>
|
||||
<c-select
|
||||
v-model:value="output.unit"
|
||||
label="Output:" label-position="left"
|
||||
:options="allUnits"
|
||||
placeholder="Select output unit"
|
||||
/>
|
||||
|
||||
<n-form-item label="Precision:" label-placement="left">
|
||||
<n-input-number v-model:value="output.precision" style="width:100px" placeholder="Precision..." :max="10" :min="0" />
|
||||
</n-form-item>
|
||||
|
||||
<n-checkbox v-model:checked="output.appendUnit">
|
||||
Show unit?
|
||||
</n-checkbox>
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<InputCopyable
|
||||
label="Output value"
|
||||
:value="convertedValue"
|
||||
placeholder="Output value will be here..."
|
||||
/>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,16 +0,0 @@
|
||||
import { ArrowsLeftRight } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Data Storage Unit converter',
|
||||
path: '/data-storage-unit-converter',
|
||||
description: 'Convert data storage or transfer units (bytes, bibytes, bits, kilobytes...)',
|
||||
keywords: ['data', 'storage', 'unit', 'conversion',
|
||||
'bits', 'bytes', 'bibytes', 'binary',
|
||||
'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB',
|
||||
'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB',
|
||||
'b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'],
|
||||
component: () => import('./data-storage-unit-converter.vue'),
|
||||
icon: ArrowsLeftRight,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { amountTransferable, transferSpeedRate, transferTimeSeconds } from './data-transfer-rate-converter.service';
|
||||
|
||||
describe('data-transfer-converter', () => {
|
||||
describe('transferTimeSeconds', () => {
|
||||
it('compute transfer time in seconds', () => {
|
||||
expect(transferTimeSeconds({
|
||||
dataSize: 100,
|
||||
dataSizeUnit: 'MB',
|
||||
bitRate: 10,
|
||||
bitRateUnit: 'Mb',
|
||||
})).toBe(80);
|
||||
});
|
||||
});
|
||||
describe('transferSpeedRate', () => {
|
||||
it('compute transferSpeedRate', () => {
|
||||
expect(transferSpeedRate({
|
||||
dataSize: 100,
|
||||
dataSizeUnit: 'MB',
|
||||
hours: 0,
|
||||
minutes: 1,
|
||||
seconds: 20,
|
||||
bitRateUnit: 'Mb',
|
||||
})).toBe(10);
|
||||
expect(transferSpeedRate({
|
||||
dataSize: 100,
|
||||
dataSizeUnit: 'MB',
|
||||
hours: 0,
|
||||
minutes: 1,
|
||||
seconds: 20,
|
||||
bitRateUnit: 'MB',
|
||||
})).toBe(1.25);
|
||||
});
|
||||
});
|
||||
describe('amountTransferable', () => {
|
||||
it('compute amount transfered', () => {
|
||||
expect(amountTransferable({
|
||||
bitRate: 10,
|
||||
bitRateUnit: 'Mb',
|
||||
hours: 1,
|
||||
minutes: 0,
|
||||
seconds: 0,
|
||||
dataSizeUnit: 'MB',
|
||||
})).toBe(4500);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,57 +0,0 @@
|
||||
import { type AllSupportedUnits, convertStorageAndRateUnits } from '../data-storage-unit-converter/data-storage-unit-converter.service';
|
||||
|
||||
export function transferTimeSeconds({
|
||||
dataSize,
|
||||
dataSizeUnit,
|
||||
bitRate,
|
||||
bitRateUnit,
|
||||
}: {
|
||||
dataSize: number
|
||||
dataSizeUnit: AllSupportedUnits
|
||||
bitRate: number
|
||||
bitRateUnit: AllSupportedUnits
|
||||
}): number {
|
||||
const dataSizeInBytes = convertStorageAndRateUnits({ value: dataSize, fromUnit: dataSizeUnit, toUnit: 'B' });
|
||||
const bitRateInBytes = convertStorageAndRateUnits({ value: bitRate, fromUnit: bitRateUnit, toUnit: 'B' });
|
||||
return bitRateInBytes > 0 ? dataSizeInBytes / bitRateInBytes : 0;
|
||||
}
|
||||
|
||||
export function transferSpeedRate({
|
||||
dataSize,
|
||||
dataSizeUnit,
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
bitRateUnit,
|
||||
}: {
|
||||
dataSize: number
|
||||
dataSizeUnit: AllSupportedUnits
|
||||
hours: number
|
||||
minutes: number
|
||||
seconds: number
|
||||
bitRateUnit: AllSupportedUnits
|
||||
}): number {
|
||||
const dataSizeInBits = convertStorageAndRateUnits({ value: dataSize, fromUnit: dataSizeUnit, toUnit: 'b' });
|
||||
const timeInSeconds = hours * 3600 + minutes * 60 + seconds;
|
||||
return convertStorageAndRateUnits({ value: timeInSeconds > 0 ? dataSizeInBits / timeInSeconds : 0, fromUnit: 'b', toUnit: bitRateUnit });
|
||||
}
|
||||
|
||||
export function amountTransferable({
|
||||
bitRate,
|
||||
bitRateUnit,
|
||||
hours,
|
||||
minutes,
|
||||
seconds,
|
||||
dataSizeUnit,
|
||||
}: {
|
||||
bitRate: number
|
||||
bitRateUnit: AllSupportedUnits
|
||||
hours: number
|
||||
minutes: number
|
||||
seconds: number
|
||||
dataSizeUnit: AllSupportedUnits
|
||||
}): number {
|
||||
const bitRateInBytes = convertStorageAndRateUnits({ value: bitRate, fromUnit: bitRateUnit, toUnit: 'B' });
|
||||
const timeInSeconds = hours * 3600 + minutes * 60 + seconds;
|
||||
return convertStorageAndRateUnits({ value: bitRateInBytes * timeInSeconds, fromUnit: 'B', toUnit: dataSizeUnit });
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { formatDuration, intervalToDuration } from 'date-fns';
|
||||
import { type AllSupportedUnits, displayStorageAndRateUnits } from '../data-storage-unit-converter/data-storage-unit-converter.service';
|
||||
import { amountTransferable, transferSpeedRate, transferTimeSeconds } from './data-transfer-rate-converter.service';
|
||||
|
||||
const allStorateUnits = [
|
||||
{ value: 'B', label: 'Bytes (B)' },
|
||||
{ value: 'iB', label: 'Bibytes (iB)' },
|
||||
{ value: 'KB', label: 'Kilobytes (KB)' },
|
||||
{ value: 'KiB', label: 'Kibibytes (KiB)' },
|
||||
{ value: 'MB', label: 'Megabytes (MB)' },
|
||||
{ value: 'MiB', label: 'Mebibytes (MiB)' },
|
||||
{ value: 'GB', label: 'Gigabytes (GB)' },
|
||||
{ value: 'GiB', label: 'Gibibytes (GiB)' },
|
||||
{ value: 'TB', label: 'Terabytes (TB)' },
|
||||
{ value: 'TiB', label: 'Tebibytes (TiB)' },
|
||||
{ value: 'PB', label: 'Petabytes (PB)' },
|
||||
{ value: 'PiB', label: 'Pebibytes (PiB)' },
|
||||
{ value: 'EB', label: 'Exabytes (EB)' },
|
||||
{ value: 'EiB', label: 'Exbibytes (EiB)' },
|
||||
{ value: 'ZB', label: 'Zettabytes (ZB)' },
|
||||
{ value: 'ZiB', label: 'Zebibytes (ZiB)' },
|
||||
{ value: 'YB', label: 'Yottabytes (YB)' },
|
||||
{ value: 'YiB', label: 'Yobibytes (YiB)' },
|
||||
];
|
||||
const allBitsUnits = [
|
||||
{ value: 'b', label: 'Bits (bit)' },
|
||||
{ value: 'Kb', label: 'Kilobits (Kbit)' },
|
||||
{ value: 'Mb', label: 'Megabits (Mbit)' },
|
||||
{ value: 'Gb', label: 'Gigabits (Gbit)' },
|
||||
{ value: 'Tb', label: 'Terabits (Tbit)' },
|
||||
{ value: 'Pb', label: 'Petabits (Pbit)' },
|
||||
{ value: 'Eb', label: 'Exabits (Ebit)' },
|
||||
{ value: 'Zb', label: 'Zettabits (Zbit)' },
|
||||
{ value: 'Yb', label: 'Yottabits (Ybit)' },
|
||||
];
|
||||
|
||||
const allRateUnits = [...allBitsUnits, ...allStorateUnits];
|
||||
|
||||
function convertToTimeDisplay(seconds: number) {
|
||||
if (seconds === 0) {
|
||||
return '0';
|
||||
}
|
||||
return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 }));
|
||||
}
|
||||
|
||||
const transferTimeInput = ref<{
|
||||
dataSize: string
|
||||
dataSizeUnit: string
|
||||
bitRate: string
|
||||
bitRateUnit: string
|
||||
}>({
|
||||
dataSize: '0',
|
||||
dataSizeUnit: 'MB',
|
||||
bitRate: '1',
|
||||
bitRateUnit: 'Mb',
|
||||
});
|
||||
const transferTimeOutput = computed(() => {
|
||||
try {
|
||||
return convertToTimeDisplay(transferTimeSeconds({
|
||||
dataSize: Number(transferTimeInput.value.dataSize),
|
||||
dataSizeUnit: transferTimeInput.value.dataSizeUnit as AllSupportedUnits,
|
||||
bitRate: Number(transferTimeInput.value.bitRate),
|
||||
bitRateUnit: transferTimeInput.value.bitRateUnit as AllSupportedUnits,
|
||||
}));
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const transferSpeedRateInput = ref<{
|
||||
dataSize: string
|
||||
dataSizeUnit: string
|
||||
hours: number
|
||||
minutes: number
|
||||
seconds: number
|
||||
bitRateUnit: string
|
||||
}>({
|
||||
dataSize: '0',
|
||||
dataSizeUnit: 'GB',
|
||||
hours: 0,
|
||||
minutes: 0,
|
||||
seconds: 0,
|
||||
bitRateUnit: 'Mb',
|
||||
});
|
||||
const transferSpeedRateOutput = computed(() => {
|
||||
try {
|
||||
return displayStorageAndRateUnits({
|
||||
unit: transferSpeedRateInput.value.bitRateUnit as AllSupportedUnits,
|
||||
appendUnit: true,
|
||||
value: transferSpeedRate({
|
||||
dataSize: Number(transferSpeedRateInput.value.dataSize),
|
||||
dataSizeUnit: transferSpeedRateInput.value.dataSizeUnit as AllSupportedUnits,
|
||||
hours: transferSpeedRateInput.value.hours,
|
||||
minutes: transferSpeedRateInput.value.minutes,
|
||||
seconds: transferSpeedRateInput.value.seconds,
|
||||
bitRateUnit: transferSpeedRateInput.value.bitRateUnit as AllSupportedUnits,
|
||||
}),
|
||||
});
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const amountTransferableInput = ref<{
|
||||
bitRate: string
|
||||
bitRateUnit: string
|
||||
hours: number
|
||||
minutes: number
|
||||
seconds: number
|
||||
dataSizeUnit: string
|
||||
}>({
|
||||
bitRate: '0',
|
||||
bitRateUnit: 'Mb',
|
||||
hours: 0,
|
||||
minutes: 0,
|
||||
seconds: 0,
|
||||
dataSizeUnit: 'MB',
|
||||
});
|
||||
const amountTransferableOutput = computed(() => {
|
||||
try {
|
||||
return displayStorageAndRateUnits({
|
||||
unit: amountTransferableInput.value.dataSizeUnit as AllSupportedUnits,
|
||||
appendUnit: true,
|
||||
value: amountTransferable({
|
||||
bitRate: Number(amountTransferableInput.value.bitRate),
|
||||
bitRateUnit: amountTransferableInput.value.bitRateUnit as AllSupportedUnits,
|
||||
hours: amountTransferableInput.value.hours,
|
||||
minutes: amountTransferableInput.value.minutes,
|
||||
seconds: amountTransferableInput.value.seconds,
|
||||
dataSizeUnit: amountTransferableInput.value.dataSizeUnit as AllSupportedUnits,
|
||||
}),
|
||||
});
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="Transfer Time" mb-2>
|
||||
<n-form-item label="Data Size:" label-placement="left">
|
||||
<n-input v-model:value="transferTimeInput.dataSize" placeholder="Data Size..." :min="0" w-full />
|
||||
<c-select
|
||||
v-model:value="transferTimeInput.dataSizeUnit"
|
||||
searchable
|
||||
:options="allStorateUnits"
|
||||
placeholder="Select a storage unit"
|
||||
ml-1
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="Bit Rate:" label-placement="left">
|
||||
<n-input v-model:value="transferTimeInput.bitRate" placeholder="Bit Rate..." :min="0" w-full />
|
||||
<c-select
|
||||
v-model:value="transferTimeInput.bitRateUnit"
|
||||
searchable
|
||||
:options="allRateUnits"
|
||||
placeholder="Select a bit rate unit"
|
||||
ml-1
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<InputCopyable
|
||||
label="Transfer time"
|
||||
:value="transferTimeOutput"
|
||||
placeholder="Transfer time will be here..."
|
||||
/>
|
||||
</c-card>
|
||||
<c-card title="Transfer Bit Rate/Speed" mb-2>
|
||||
<n-form-item label="Data Size:" label-placement="left">
|
||||
<n-input v-model:value="transferSpeedRateInput.dataSize" placeholder="Data Size..." :min="0" w-full />
|
||||
<c-select
|
||||
v-model:value="transferSpeedRateInput.dataSizeUnit"
|
||||
:options="allStorateUnits"
|
||||
placeholder="Select a storage unit"
|
||||
ml-1
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="Duration (h/m/s):" label-placement="left">
|
||||
<n-input-number v-model:value="transferSpeedRateInput.hours" mr-1 placeholder="Hours" :min="0" w-full />
|
||||
<n-input-number v-model:value="transferSpeedRateInput.minutes" mr-1 placeholder="Minutes" :min="0" w-full />
|
||||
<n-input-number v-model:value="transferSpeedRateInput.seconds" mr-1 placeholder="Seconds" :min="0" w-full />
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div flex items-baseline gap-2>
|
||||
<InputCopyable
|
||||
label="Transfer Bit Rate/Speed:"
|
||||
label-position="left"
|
||||
:value="transferSpeedRateOutput"
|
||||
placeholder="Bit Rate will be here..."
|
||||
/>
|
||||
<c-select
|
||||
v-model:value="transferSpeedRateInput.bitRateUnit"
|
||||
:options="allRateUnits"
|
||||
placeholder="Select a bit rate unit"
|
||||
ml-1
|
||||
/>
|
||||
</div>
|
||||
</c-card>
|
||||
<c-card title="Amount Transferable" mb-2>
|
||||
<n-form-item label="Bit Rate:" label-placement="left">
|
||||
<n-input v-model:value="amountTransferableInput.bitRate" placeholder="Bit Rate..." :min="0" w-full />
|
||||
<c-select
|
||||
v-model:value="amountTransferableInput.bitRateUnit"
|
||||
:options="allRateUnits"
|
||||
placeholder="Select a bit rate unit"
|
||||
ml-1
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="Duration (h/m/s):" label-placement="left">
|
||||
<n-input-number v-model:value="amountTransferableInput.hours" mr-1 placeholder="Hours" :min="0" w-full />
|
||||
<n-input-number v-model:value="amountTransferableInput.minutes" mr-1 placeholder="Minutes" :min="0" w-full />
|
||||
<n-input-number v-model:value="amountTransferableInput.seconds" mr-1 placeholder="Seconds" :min="0" w-full />
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div flex items-baseline gap-2>
|
||||
<InputCopyable
|
||||
label="Amount transferable:"
|
||||
label-position="left"
|
||||
:value="amountTransferableOutput"
|
||||
placeholder="Amount transferable will be here..."
|
||||
/>
|
||||
<c-select
|
||||
v-model:value="amountTransferableInput.dataSizeUnit"
|
||||
searchable
|
||||
:options="allStorateUnits"
|
||||
placeholder="Select a storage unit"
|
||||
ml-1
|
||||
/>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { TransferIn } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Data Transfer Rate Calculator',
|
||||
path: '/data-transfer-rate-converter',
|
||||
description: 'Compute Data Transfer times, rates and amount of data',
|
||||
keywords: ['data', 'transfer', 'rate', 'convert', 'time'],
|
||||
component: () => import('./data-transfer-rate-converter.vue'),
|
||||
icon: TransferIn,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
+8
-10
@@ -1,9 +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 slaCalculator } from './sla-calculator';
|
||||
import { tool as emailNormalizer } from './email-normalizer';
|
||||
import { tool as dataTransferRateConverter } from './data-transfer-rate-converter';
|
||||
import { tool as dataStorageUnitConverter } from './data-storage-unit-converter';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -170,17 +169,16 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Math',
|
||||
components: [
|
||||
mathEvaluator,
|
||||
etaCalculator,
|
||||
percentageCalculator,
|
||||
dataTransferRateConverter,
|
||||
dataStorageUnitConverter,
|
||||
],
|
||||
components: [mathEvaluator, etaCalculator, percentageCalculator],
|
||||
},
|
||||
{
|
||||
name: 'Measurement',
|
||||
components: [chronometer, temperatureConverter, benchmarkBuilder],
|
||||
components: [
|
||||
chronometer,
|
||||
temperatureConverter,
|
||||
benchmarkBuilder,
|
||||
slaCalculator,
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Text',
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Clock } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'SLA calculator',
|
||||
path: '/sla-calculator',
|
||||
description: 'Service Level Agreement Calcultator',
|
||||
keywords: ['sla', 'service', 'level', 'agreement', 'calculator'],
|
||||
component: () => import('./sla-calculator.vue'),
|
||||
icon: Clock,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { downTimeToSLA, slaToDowntimes } from './sla-calculator.service';
|
||||
|
||||
describe('sla-calculator', () => {
|
||||
describe('downTimeToSLA', () => {
|
||||
it('compute correct values', () => {
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 100,
|
||||
mondayHours: 16,
|
||||
tuesdayHours: 6,
|
||||
wednesdayHours: 4,
|
||||
thursdayHours: 24,
|
||||
fridayHours: 21,
|
||||
saturdayHours: 16,
|
||||
sundayHours: 13,
|
||||
})).to.deep.eq({
|
||||
slaForDay: null,
|
||||
slaForMonth: 99.99361155031703,
|
||||
slaForQuarter: 99.99787051677234,
|
||||
slaForWeek: 99.97222222222223,
|
||||
slaForYear: 99.99946762919309,
|
||||
});
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 86400 / 10000,
|
||||
})).to.deep.eq({
|
||||
slaForDay: 99.99,
|
||||
slaForMonth: 99.99967145115916,
|
||||
slaForQuarter: 99.99989048371972,
|
||||
slaForWeek: 99.99857142857142,
|
||||
slaForYear: 99.99997262092992,
|
||||
});
|
||||
expect(downTimeToSLA({
|
||||
downTimeSeconds: 86400 / 2,
|
||||
})).to.deep.eq({
|
||||
slaForDay: 50,
|
||||
slaForMonth: 98.35725579580689,
|
||||
slaForQuarter: 99.45241859860229,
|
||||
slaForWeek: 92.85714285714286,
|
||||
slaForYear: 99.86310464965058,
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('slaToDowntimes', () => {
|
||||
it('compute correct values', () => {
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99,
|
||||
mondayHours: 9,
|
||||
tuesdayHours: 24,
|
||||
wednesdayHours: 10,
|
||||
thursdayHours: 8,
|
||||
fridayHours: 3,
|
||||
saturdayHours: 24,
|
||||
sundayHours: 4,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: null,
|
||||
secondsPerMonth: 12835.665,
|
||||
secondsPerQuarter: 38506.995,
|
||||
secondsPerWeek: 2952,
|
||||
secondsPerYear: 154027.98,
|
||||
});
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99.99,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: 8.64,
|
||||
secondsPerMonth: 262.9746,
|
||||
secondsPerQuarter: 788.9238,
|
||||
secondsPerWeek: 60.48,
|
||||
secondsPerYear: 3155.6952,
|
||||
});
|
||||
expect(slaToDowntimes({
|
||||
targetSLA: 99,
|
||||
})).to.deep.eq({
|
||||
secondsPerDay: 864,
|
||||
secondsPerMonth: 26297.46,
|
||||
secondsPerQuarter: 78892.38,
|
||||
secondsPerWeek: 6048,
|
||||
secondsPerYear: 315569.52,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
import Big from 'big.js';
|
||||
|
||||
const hoursDay = Big('24');
|
||||
const daysWeek = Big('7');
|
||||
const monthsYear = Big('12');
|
||||
const daysYear = Big('365.2425');
|
||||
const weeksYear = daysYear.div(daysWeek);
|
||||
const daysMonth = daysYear.div(monthsYear);
|
||||
const weeksMonth = daysMonth.div(daysWeek);
|
||||
|
||||
interface DaysHours {
|
||||
mondayHours?: number
|
||||
tuesdayHours?: number
|
||||
wednesdayHours?: number
|
||||
thursdayHours?: number
|
||||
fridayHours?: number
|
||||
saturdayHours?: number
|
||||
sundayHours?: number
|
||||
}
|
||||
|
||||
function prepareDurations({
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: DaysHours) {
|
||||
const durHoursWeek = Big(mondayHours).plus(tuesdayHours).plus(wednesdayHours).plus(thursdayHours).plus(fridayHours).plus(saturdayHours).plus(sundayHours);
|
||||
const durSecondsWeek = durHoursWeek.mul('3600');
|
||||
const durSecondsDay = durSecondsWeek.div(daysWeek);
|
||||
const durSecondsMonth = durSecondsWeek.mul(weeksMonth);
|
||||
const durSecondsQuarter = durSecondsMonth.mul('3');
|
||||
const durSecondsYear = durSecondsWeek.mul(weeksYear);
|
||||
const fullWeekHours = daysWeek.mul(hoursDay);
|
||||
|
||||
return {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
};
|
||||
}
|
||||
|
||||
export function downTimeToSLA({
|
||||
downTimeSeconds,
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: {
|
||||
downTimeSeconds: number
|
||||
} & DaysHours) {
|
||||
const {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
} = prepareDurations({
|
||||
mondayHours, tuesdayHours, wednesdayHours, thursdayHours, fridayHours, saturdayHours, sundayHours,
|
||||
});
|
||||
|
||||
const one = Big('1');
|
||||
const hundred = Big('100');
|
||||
const downTimeSecondsBig = Big(downTimeSeconds);
|
||||
|
||||
return {
|
||||
slaForDay: fullWeekHours.eq(durHoursWeek) ? one.minus(downTimeSecondsBig.div(durSecondsDay)).mul(hundred).toNumber() : null,
|
||||
slaForWeek: one.minus(downTimeSecondsBig.div(durSecondsWeek)).mul(hundred).toNumber(),
|
||||
slaForMonth: one.minus(downTimeSecondsBig.div(durSecondsMonth)).mul(hundred).toNumber(),
|
||||
slaForQuarter: one.minus(downTimeSecondsBig.div(durSecondsQuarter)).mul(hundred).toNumber(),
|
||||
slaForYear: one.minus(downTimeSecondsBig.div(durSecondsYear)).mul(hundred).toNumber(),
|
||||
};
|
||||
}
|
||||
|
||||
export function slaToDowntimes({
|
||||
targetSLA,
|
||||
mondayHours = 24,
|
||||
tuesdayHours = 24,
|
||||
wednesdayHours = 24,
|
||||
thursdayHours = 24,
|
||||
fridayHours = 24,
|
||||
saturdayHours = 24,
|
||||
sundayHours = 24,
|
||||
}: {
|
||||
targetSLA: number
|
||||
mondayHours?: number
|
||||
tuesdayHours?: number
|
||||
wednesdayHours?: number
|
||||
thursdayHours?: number
|
||||
fridayHours?: number
|
||||
saturdayHours?: number
|
||||
sundayHours?: number
|
||||
}) {
|
||||
const {
|
||||
durHoursWeek,
|
||||
durSecondsWeek,
|
||||
durSecondsDay,
|
||||
durSecondsMonth,
|
||||
durSecondsQuarter,
|
||||
durSecondsYear,
|
||||
fullWeekHours,
|
||||
} = prepareDurations({
|
||||
mondayHours, tuesdayHours, wednesdayHours, thursdayHours, fridayHours, saturdayHours, sundayHours,
|
||||
});
|
||||
|
||||
const allowedDowntime = Big('1').minus(Big(targetSLA).div('100'));
|
||||
|
||||
return {
|
||||
secondsPerDay: fullWeekHours.eq(durHoursWeek) ? allowedDowntime.mul(durSecondsDay).toNumber() : null,
|
||||
secondsPerWeek: allowedDowntime.mul(durSecondsWeek).toNumber(),
|
||||
secondsPerMonth: allowedDowntime.mul(durSecondsMonth).toNumber(),
|
||||
secondsPerQuarter: allowedDowntime.mul(durSecondsQuarter).toNumber(),
|
||||
secondsPerYear: allowedDowntime.mul(durSecondsYear).toNumber(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<script setup lang="ts">
|
||||
import prettyMilliseconds from 'pretty-ms';
|
||||
import parse from 'parse-duration';
|
||||
import { downTimeToSLA, slaToDowntimes } from './sla-calculator.service';
|
||||
import { useQueryParam, useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
function prettySeconds(seconds: number | null) {
|
||||
if (!seconds) {
|
||||
return '';
|
||||
}
|
||||
return prettyMilliseconds(seconds * 1000);
|
||||
}
|
||||
|
||||
const daysHours = useQueryParamOrStorage<{
|
||||
mon?: number
|
||||
tue?: number
|
||||
wed?: number
|
||||
thu?: number
|
||||
fri?: number
|
||||
sat?: number
|
||||
sun?: number
|
||||
}>({
|
||||
name: 'days',
|
||||
storageName: 'sla:days',
|
||||
defaultValue: {
|
||||
mon: 24,
|
||||
tue: 24,
|
||||
wed: 24,
|
||||
thu: 24,
|
||||
fri: 24,
|
||||
sat: 24,
|
||||
sun: 24,
|
||||
},
|
||||
});
|
||||
const inputSLA = useQueryParam({ name: 'sla', defaultValue: 99.99 });
|
||||
const outputDownTimes = computed(() => {
|
||||
const weekdaysHours = daysHours.value;
|
||||
const downtimesSeconds = slaToDowntimes({
|
||||
targetSLA: inputSLA.value,
|
||||
mondayHours: weekdaysHours.mon,
|
||||
tuesdayHours: weekdaysHours.tue,
|
||||
wednesdayHours: weekdaysHours.wed,
|
||||
thursdayHours: weekdaysHours.thu,
|
||||
fridayHours: weekdaysHours.fri,
|
||||
saturdayHours: weekdaysHours.sat,
|
||||
sundayHours: weekdaysHours.sun,
|
||||
});
|
||||
return {
|
||||
durationPerDay: prettySeconds(downtimesSeconds.secondsPerDay),
|
||||
durationPerMonth: prettySeconds(downtimesSeconds.secondsPerMonth),
|
||||
durationPerQuarter: prettySeconds(downtimesSeconds.secondsPerQuarter),
|
||||
durationPerWeek: prettySeconds(downtimesSeconds.secondsPerWeek),
|
||||
durationPerYear: prettySeconds(downtimesSeconds.secondsPerYear),
|
||||
};
|
||||
});
|
||||
|
||||
const inputDuration = useQueryParam({ name: 'dur', defaultValue: '1s' });
|
||||
const inputDurationValidation = useValidation({
|
||||
source: inputDuration,
|
||||
rules: [
|
||||
{
|
||||
message: 'Invalid duration',
|
||||
validator: value => parse(value),
|
||||
},
|
||||
],
|
||||
});
|
||||
const inputDurationSeconds = computed(() => {
|
||||
if (!inputDurationValidation.isValid) {
|
||||
return 0;
|
||||
}
|
||||
return parse(inputDuration.value, 's') || 0;
|
||||
});
|
||||
const outputSLAs = computed(() => {
|
||||
const weekdaysHours = daysHours.value;
|
||||
const slas = downTimeToSLA({
|
||||
downTimeSeconds: inputDurationSeconds.value,
|
||||
mondayHours: weekdaysHours.mon,
|
||||
tuesdayHours: weekdaysHours.tue,
|
||||
wednesdayHours: weekdaysHours.wed,
|
||||
thursdayHours: weekdaysHours.thu,
|
||||
fridayHours: weekdaysHours.fri,
|
||||
saturdayHours: weekdaysHours.sat,
|
||||
sundayHours: weekdaysHours.sun,
|
||||
});
|
||||
return {
|
||||
slaForDay: slas.slaForDay?.toPrecision(6),
|
||||
slaForWeek: slas.slaForWeek.toPrecision(6),
|
||||
slaForMonth: slas.slaForMonth.toPrecision(6),
|
||||
slaForQuarter: slas.slaForQuarter.toPrecision(6),
|
||||
slaForYear: slas.slaForYear.toPrecision(6),
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="SLA to downtimes" mb-2>
|
||||
<n-form-item label="Agreed SLA" label-placement="left">
|
||||
<n-input-number v-model:value="inputSLA" :min="0" :max="100" />
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item v-if="outputDownTimes.durationPerDay" label="Daily downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerDay" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Weekly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerWeek" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Monthly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerMonth" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Quarterly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerQuarter" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Yearly downtime" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputDownTimes.durationPerYear" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Downtime to SLA" mb-2>
|
||||
<c-input-text
|
||||
v-model:value="inputDuration"
|
||||
label="Downtime duration"
|
||||
label-position="left"
|
||||
placeholder="Put downtime duration here..."
|
||||
:validation="inputDurationValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item v-if="outputSLAs.slaForDay" label="Daily SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForDay" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Weekly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForWeek" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Monthly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForMonth" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Quarterly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForQuarter" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Yearly SLA" label-placement="left" label-width="100">
|
||||
<input-copyable :value="outputSLAs.slaForYear" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Weekdays hours">
|
||||
<div flex flex-wrap gap-1>
|
||||
<n-form-item label="Monday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.mon" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Tuesday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.tue" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Wednesday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.wed" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Thursday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.thu" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Friday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.fri" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<div flex flex-wrap gap-1>
|
||||
<n-form-item label="Saturday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.sat" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Sunday" flex-1>
|
||||
<n-input-number v-model:value="daysHours.sun" :min="0" :max="24" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user