Skip to content

Commit 060c9b2

Browse files
committed
Merge branch 'feat/json-php-array' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts # vite.config.ts
2 parents 488cee0 + ebfae5e commit 060c9b2

File tree

8 files changed

+139
-0
lines changed

8 files changed

+139
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"json-editor-vue": "^0.16.0",
133133
"json5": "^2.2.3",
134134
"jsonpath": "^1.1.1",
135+
"jsonar-mod": "^1.9.0",
135136
"jwt-decode": "^3.1.2",
136137
"libphonenumber-js": "^1.10.28",
137138
"lodash": "^4.17.21",
@@ -176,6 +177,7 @@
176177
"vite-plugin-node-polyfills": "^0.22.0",
177178
"vite-plugin-node-polyfills": "^0.21.0",
178179
"vanilla-jsoneditor": "^0.23.8",
180+
"vite-plugin-node-polyfills": "^0.21.0",
179181
"vue": "^3.3.4",
180182
"vue-color-wheel": "^0.1.1",
181183
"vue-i18n": "^9.9.1",

pnpm-lock.yaml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { tool as jqTester } from './jq-tester';
2020
import { tool as jsonpathMemo } from './jsonpath-memo';
2121
import { tool as jqMemo } from './jq-memo';
2222
import { tool as jsUnobfuscator } from './js-unobfuscator';
23+
import { tool as jsonToPhpArray } from './json-to-php-array';
24+
import { tool as phpArrayToJson } from './php-array-to-json';
2325

2426
import { tool as cssXpathConverter } from './css-xpath-converter';
2527
import { tool as cssSelectorsMemo } from './css-selectors-memo';
@@ -205,6 +207,8 @@ export const toolsByCategory: ToolCategory[] = [
205207
folderStructureDiagram,
206208
imageToCss,
207209
jsUnobfuscator,
210+
jsonToPhpArray,
211+
phpArrayToJson,
208212
],
209213
},
210214
{

src/tools/json-to-php-array/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { BrandPhp } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Json to PHP-Array',
6+
path: '/json-to-php-array',
7+
description: 'Convert JSON to PHP Array',
8+
keywords: ['json', 'php', 'array'],
9+
component: () => import('./json-to-php-array.vue'),
10+
icon: BrandPhp,
11+
createdAt: new Date('2024-05-11'),
12+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<script setup lang="ts">
2+
import jsonar from 'jsonar-mod';
3+
import JSON5 from 'json5';
4+
import type { UseValidationRule } from '@/composable/validation';
5+
import { withDefaultOnError } from '@/utils/defaults';
6+
7+
const defaultValue = `{
8+
a:"b",
9+
arr: [1, "2"],
10+
nested: {
11+
c:12,
12+
d: "az"
13+
}
14+
}`;
15+
function transformer(value: string) {
16+
return withDefaultOnError(() => jsonar.arrify(JSON5.parse(value), { prettify: true }), '');
17+
}
18+
19+
const rules: UseValidationRule<string>[] = [
20+
{
21+
validator: (v: string) => JSON5.parse(v),
22+
message: 'Provided JSON is not valid.',
23+
},
24+
];
25+
</script>
26+
27+
<template>
28+
<format-transformer
29+
input-label="Your JSON"
30+
:input-default="defaultValue"
31+
input-placeholder="Paste your JSON here..."
32+
output-label="PHP Array version"
33+
:input-validation-rules="rules"
34+
:transformer="transformer"
35+
/>
36+
</template>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module 'jsonar-mod' {
2+
export function arrify(json: any, options?: { prettify?: boolean}): string
3+
export function parse(php: string): object
4+
}

src/tools/php-array-to-json/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { BrandPhp } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'PHP-Array to JSON',
6+
path: '/php-array-to-json',
7+
description: 'Convert PHP Array to JSON',
8+
keywords: ['php', 'array', 'json'],
9+
component: () => import('./php-array-to-json.vue'),
10+
icon: BrandPhp,
11+
createdAt: new Date('2024-05-11'),
12+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script setup lang="ts">
2+
import jsonar from 'jsonar-mod';
3+
import type { UseValidationRule } from '@/composable/validation';
4+
import { withDefaultOnError } from '@/utils/defaults';
5+
6+
const defaultValue = `array(
7+
"a" => "b",
8+
"arr" => array(
9+
1,
10+
"2"
11+
),
12+
"nested" => array(
13+
"c" => 12,
14+
"d" => "az"
15+
)
16+
);`;
17+
function transformer(value: string) {
18+
return withDefaultOnError(() => JSON.stringify(jsonar.parse(value), null, 2), '');
19+
}
20+
21+
const rules: UseValidationRule<string>[] = [
22+
{
23+
validator: (v: string) => v === '' || jsonar.parse(v),
24+
message: 'Provided PHP Array is not valid.',
25+
},
26+
];
27+
</script>
28+
29+
<template>
30+
<format-transformer
31+
input-label="Your PHP Array"
32+
:input-default="defaultValue"
33+
input-placeholder="Paste your PHP Array here..."
34+
output-label="JSON version"
35+
output-language="json"
36+
:input-validation-rules="rules"
37+
:transformer="transformer"
38+
/>
39+
</template>

0 commit comments

Comments
 (0)