1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-19 22:18:03 +00:00

Loose JSON parsing. Many UI improvements.

This commit is contained in:
2023-02-19 17:26:32 +01:00
parent 7ac1587c95
commit 78540622ee
25 changed files with 211 additions and 130 deletions

View File

@ -1,5 +1,6 @@
import { isInt } from '$lib/math';
import { canBeObjectId, int32, int64, uint64 } from '$lib/mongo';
import { jsonLooseParse } from '$lib/strings';
export default function input(node, { autofocus, type, onValid, onInvalid, mandatory } = {
autofocus: false,
@ -26,7 +27,7 @@ export default function input(node, { autofocus, type, onValid, onInvalid, manda
switch (type) {
case 'json':
try {
JSON.parse(node.value);
jsonLooseParse(node.value);
return false;
}
catch {

View File

@ -0,0 +1,29 @@
{
"Fields": {
"$currentDate": "Current Date",
"$inc": "Increment",
"$min": "Min",
"$max": "Max",
"$mul": "Multiply",
"$rename": "Rename",
"$set": "Set",
"$setOnInsert": "Set on Insert",
"$unset": "Unset"
},
"Array": {
"$addToSet": "Add to Set",
"$pop": "Pop",
"$pull": "Pull",
"$push": "Push",
"$pullAll": "Push All"
},
"Modifiers": {
"$each": "Each",
"$position": "Position",
"$slice": "Slice",
"$sort": "Sort"
},
"Bitwise": {
"$bit": "Bit"
}
}

View File

@ -1,8 +1,9 @@
import { ObjectId } from 'bson';
import aggregationStages from './aggregation-stages.json';
import atomicUpdateOperators from './atomic-update-operators.json';
import locales from './locales.json';
export { aggregationStages, locales };
export { aggregationStages, atomicUpdateOperators, locales };
// Calculate the min and max values of (un)signed integers with n bits
export const intMin = bits => Math.pow(2, bits - 1) * -1;

View File

@ -56,3 +56,8 @@ export function setValue(object, path, value) {
return object;
}
export function deepClone(obj) {
// Room for improvement below
return JSON.parse(JSON.stringify(obj));
}

View File

@ -2,3 +2,23 @@ export function capitalise(string = '') {
const capitalised = string.charAt(0).toUpperCase() + string.slice(1);
return capitalised;
}
export function jsonLooseParse(json) {
const obj = new Function(`return (${json})`)();
return obj;
}
export function convertLooseJson(json) {
const j = JSON.stringify(jsonLooseParse(json));
return j;
}
export function looseJsonIsValid(json) {
try {
jsonLooseParse(json);
return true;
}
catch {
return false;
}
}