Compare commits

..
Author SHA1 Message Date
ShareVB bf9e07a0a8 chore(github workflows): ci and e2e tests: try updating to node 20 2024-04-06 12:21:48 +02:00
sharevb 9c5b297b30 feat(new tool): JSON Escape/Unescape
JSON String Escaper/Unescaper
Fix #659
2024-04-04 00:03:40 +02:00
13 changed files with 113 additions and 178 deletions

No files matched your search

+1
View File
@@ -80,6 +80,7 @@
"pinia": "^2.0.34",
"plausible-tracker": "^0.3.8",
"qrcode": "^1.5.1",
"slashes": "^3.0.12",
"sql-formatter": "^13.0.0",
"ua-parser-js": "^1.0.35",
"ulid": "^2.3.0",
+13 -6
View File
@@ -140,6 +140,9 @@ dependencies:
qrcode:
specifier: ^1.5.1
version: 1.5.1
slashes:
specifier: ^3.0.12
version: 3.0.12
sql-formatter:
specifier: ^13.0.0
version: 13.0.0
@@ -3351,7 +3354,7 @@ packages:
dependencies:
'@unhead/dom': 0.5.1
'@unhead/schema': 0.5.1
'@vueuse/shared': 10.7.2(vue@3.3.4)
'@vueuse/shared': 10.9.0(vue@3.3.4)
unhead: 0.5.1
vue: 3.3.4
transitivePeerDependencies:
@@ -3993,10 +3996,10 @@ packages:
- vue
dev: false
/@vueuse/shared@10.7.2(vue@3.3.4):
resolution: {integrity: sha512-qFbXoxS44pi2FkgFjPvF4h7c9oMDutpyBdcJdMYIMg9XyXli2meFMuaKn+UMgsClo//Th6+beeCgqweT/79BVA==}
/@vueuse/shared@10.9.0(vue@3.3.4):
resolution: {integrity: sha512-Uud2IWncmAfJvRaFYzv5OHDli+FbOzxiVEQdLCKQKLyhz94PIyFC3CHcH7EDMwIn8NPtD06+PNbC/PiO0LGLtw==}
dependencies:
vue-demi: 0.14.6(vue@3.3.4)
vue-demi: 0.14.7(vue@3.3.4)
transitivePeerDependencies:
- '@vue/composition-api'
- vue
@@ -8108,6 +8111,10 @@ packages:
engines: {node: '>=12'}
dev: true
/slashes@3.0.12:
resolution: {integrity: sha512-Q9VME8WyGkc7pJf6QEkj3wE+2CnvZMI+XJhwdTPR8Z/kWQRXi7boAWLDibRPyHRTUTPx5FaU7MsyrjI3yLB4HA==}
dev: false
/snake-case@2.1.0:
resolution: {integrity: sha512-FMR5YoPFwOLuh4rRz92dywJjyKYZNLpMn1R5ujVpIYkbA9p01fq8RMg0FkO4M+Yobt4MjHeLTJVm5xFFBHSV2Q==}
dependencies:
@@ -9151,8 +9158,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 -1
View File
@@ -28,7 +28,7 @@ const compareMatch = computed(() => compareSync(compareString.value, compareHash
mb-2
/>
<n-form-item label="Salt count: " label-placement="left" label-width="120">
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="100" :min="0" w-full />
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="10" :min="0" w-full />
</n-form-item>
<c-input-text :value="hashed" readonly text-center />
+2 -2
View File
@@ -6,7 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as rmbNumbers } from './rmb-numbers';
import { tool as jsonEscaper } from './json-escaper';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -108,7 +108,6 @@ export const toolsByCategory: ToolCategory[] = [
listConverter,
tomlToJson,
tomlToYaml,
rmbNumbers,
],
},
{
@@ -130,6 +129,7 @@ export const toolsByCategory: ToolCategory[] = [
httpStatusCodes,
jsonDiff,
safelinkDecoder,
jsonEscaper,
],
},
{
@@ -11,9 +11,6 @@ describe('integer-base-converter', () => {
expect(convertBase({ value: '10100101', fromBase: 2, toBase: 16 })).toEqual('a5');
expect(convertBase({ value: '192654', fromBase: 10, toBase: 8 })).toEqual('570216');
expect(convertBase({ value: 'zz', fromBase: 64, toBase: 10 })).toEqual('2275');
expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 16 })).toEqual('20010db8000085a300000000ac1f8908');
expect(convertBase({ value: '20010db8000085a300000000ac1f8908', fromBase: 16, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
});
});
});
@@ -5,16 +5,16 @@ export function convertBase({ value, fromBase, toBase }: { value: string; fromBa
let decValue = value
.split('')
.reverse()
.reduce((carry: bigint, digit: string, index: number) => {
.reduce((carry: number, digit: string, index: number) => {
if (!fromRange.includes(digit)) {
throw new Error(`Invalid digit "${digit}" for base ${fromBase}.`);
}
return (carry += BigInt(fromRange.indexOf(digit)) * BigInt(fromBase) ** BigInt(index));
}, 0n);
return (carry += fromRange.indexOf(digit) * fromBase ** index);
}, 0);
let newValue = '';
while (decValue > 0) {
newValue = toRange[Number(decValue % BigInt(toBase))] + newValue;
decValue = (decValue - (decValue % BigInt(toBase))) / BigInt(toBase);
newValue = toRange[decValue % toBase] + newValue;
decValue = (decValue - (decValue % toBase)) / toBase;
}
return newValue || '0';
}
+12
View File
@@ -0,0 +1,12 @@
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Json Escaper/Unescaper',
path: '/json-escaper',
description: 'Escape and unescape JSON string',
keywords: ['json', 'string', 'escape', 'unescape'],
component: () => import('./json-escaper.vue'),
icon: Braces,
createdAt: new Date('2024-03-09'),
});
+78
View File
@@ -0,0 +1,78 @@
<script setup lang="ts">
import { addSlashes, removeSlashes } from 'slashes';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const unescapedInput = ref('');
const escapedOutput = computed(
() => {
try {
return addSlashes(unescapedInput.value);
}
catch (e: any) {
return e.toString();
}
},
);
const escapedInput = ref('');
const unescapedOutput = computed(
() => {
try {
return removeSlashes(escapedInput.value);
}
catch (e: any) {
return e.toString();
}
},
);
</script>
<template>
<div max-w-600>
<c-card title="Escape JSON string">
<c-input-text
v-model:value="unescapedInput"
placeholder="Put your string to escape..."
label="String to escape"
raw-text
multiline
rows="5"
mb-5
/>
<n-divider />
<TextareaCopyable
label="Escaped string"
:value="escapedOutput"
multiline
readonly
rows="5"
mb-5
/>
</c-card>
<c-card title="Unescape JSON string" mt-5>
<c-input-text
v-model:value="escapedInput"
placeholder="Put your string to unescape..."
label="String to unescape"
raw-text
multiline
rows="5"
mb-5
/>
<n-divider />
<TextareaCopyable
label="Unescaped string"
:value="unescapedOutput"
multiline
readonly
rows="5"
mb-5
/>
</c-card>
</div>
</template>
-12
View File
@@ -1,12 +0,0 @@
import { CurrencyYen } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'RMB Uppercase Converter',
path: '/rmb-numbers',
description: 'RMB/Renminbi Capitalization Conversion Tool',
keywords: ['rmb', 'renminbi', 'cny', 'number', 'uppercase', '人民币', '大写', '转换'],
component: () => import('./rmb-numbers.vue'),
icon: CurrencyYen,
createdAt: new Date('2024-04-29'),
});
@@ -1,37 +0,0 @@
import { describe, expect, it } from 'vitest';
import { rmb } from './rmb-numbers.service';
describe('rmb-case-converter', () => {
it('rmb to convert rmb numbers to uppercase', async () => {
expect(rmb(123)).to.deep.equal([
{
type: 'number',
value: '壹',
},
{
type: 'unit',
value: '佰',
},
{
type: 'number',
value: '贰',
},
{
type: 'unit',
value: '拾',
},
{
type: 'number',
value: '叁',
},
{
type: 'unit',
value: '元',
},
{
type: 'cut',
value: '整',
},
]);
});
});
@@ -1,67 +0,0 @@
export { rmb };
const numbers = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
const leftUnits = ['元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟', '万', '拾', '佰', '仟', '万'];
const rightUnits = ['角', '分'];
function rmb(value: number) {
if (Object.prototype.toString.call(value) === '[object Number]' && value >= 0.01) {
const fragment: any = [];
const [leftValues, rightValues] = String(value).split('.').map(part => part.split('').map(i => Number(i)));
const leftValueLength = leftValues.length; // 整数部分位数
const unit1 = leftValueLength - 1; // 元位
const unit5 = leftValueLength - 5; // 万位
const unit9 = leftValueLength - 9; // 亿位
const unit13 = leftValueLength - 13; // 万亿位
const unit17 = leftValueLength - 17; // 万万亿位
const hasLeftValue = leftValueLength > 1 || leftValues[0] > 0; // 整数部分不为0
const hasRightValue = rightValues && (rightValues[0] > 0 || rightValues[1] > 0); // 小数部分不为0
const has678Value = leftValues[unit5 - 1] > 0 || leftValues[unit5 - 2] > 0 || leftValues[unit5 - 3] > 0; // 拾万、佰万或仟万位不为0
const overflowIndex = leftValueLength - leftUnits.length; // 溢出位索引
let leftUnitIndex = 0;
for (let i = leftValueLength - 1; i >= 0; i--) {
if (leftValues[i] === 0 && (i === unit5 || i === unit9 || i === unit13 || i === unit17) && leftValues[i + 1] > 0) {
// 当前位为0,且当前位为万、亿、万亿、万万亿,且低一位不为0
fragment.unshift({ type: 'number', value: numbers[leftValues[i]] });
}
if ((leftValues[i] > 0) || (i === unit1 && hasLeftValue) || (i === unit5 && has678Value) || i === unit9 || i === unit13 || i === unit17) {
// 元、万、亿、万亿、万万亿或当前位不为0
fragment.unshift({ type: 'unit', value: leftUnits[leftUnitIndex] });
}
if (leftValues[i] > 0 || (leftValues[i + 1] > 0 && i !== unit5 && i !== unit9 && i !== unit13 && i !== unit17) || i <= overflowIndex) {
// 当前位不为0,或低一位不为0且当前位非万、亿、万亿、万万亿,或当前为溢出位
fragment.unshift({ type: 'number', value: numbers[leftValues[i]] });
}
leftUnitIndex++;
}
if (hasRightValue) {
// 角
if (rightValues[0] > 0 || hasLeftValue) { // 角位不为0,或整数位不为0
fragment.push({ type: 'number', value: numbers[rightValues[0]] });
}
if (rightValues[0] > 0) { // 角位不为0
fragment.push({ type: 'unit', value: rightUnits[0] });
}
// 分
if (rightValues[1] > 0) {
fragment.push({ type: 'number', value: numbers[rightValues[1]] });
fragment.push({ type: 'unit', value: rightUnits[1] });
}
}
else { // 没有小数位
fragment.push({ type: 'cut', value: '整' });
}
return fragment;
}
return [
{ type: 'number', value: '零' },
{ type: 'unit', value: '元' },
{ type: 'cut', value: '整' },
];
};
-44
View File
@@ -1,44 +0,0 @@
<script setup lang="ts">
import { useThemeVars } from 'naive-ui';
import { rmb } from './rmb-numbers.service';
const themeVars = useThemeVars();
const inputRmb = ref(23);
const outputRmb = computed(() => rmb(inputRmb.value)); ;
</script>
<template>
<div flex flex-col gap-2>
<c-card title="Lower Case Amount">
<n-input-number v-model:value="inputRmb" max="100000000000" min="0" placeholder="Enter the amount in lowercase (example: 1314.52)" :show-button="false" w-full />
</c-card>
<div my-16px divider />
<c-card title="Amount in Capital Letters" flex flex-col>
<div m-0 m-x-auto>
<span
v-for="(item, index) in outputRmb"
:key="index"
:class="item.type"
>
{{ item.value }}
</span>
</div>
</c-card>
</div>
</template>
<style lang="less" scoped>
.unit {
font-size: 1.4em;
color: v-bind('themeVars.successColor');
}
.number {
font-size: 2.4em;
}
.cut {
font-size: 1.4em;
color: v-bind('themeVars.errorColor');
}
</style>
+1 -1
View File
@@ -23,7 +23,7 @@ const decodeInput = ref('Hello%20world%20%3A)');
const decodeOutput = computed(() => withDefaultOnError(() => decodeURIComponent(decodeInput.value), ''));
const decodeValidation = useValidation({
source: decodeInput,
source: encodeInput,
rules: [
{
validator: value => isNotThrowing(() => decodeURIComponent(value)),