funda-ui 4.7.585 → 4.7.601
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Chatbox/index.js +1564 -506
- package/EventCalendar/index.js +2 -1
- package/EventCalendarTimeline/index.js +2 -1
- package/LiveSearch/index.js +341 -21
- package/MultipleCheckboxes/index.js +341 -21
- package/MultipleSelect/index.js +341 -21
- package/NativeSelect/index.js +341 -21
- package/Radio/index.js +341 -21
- package/Select/index.js +341 -21
- package/Utils/anim.js +338 -22
- package/Utils/initDefaultOptions.js +338 -22
- package/Utils/validate.d.ts +16 -6
- package/Utils/validate.js +338 -21
- package/lib/cjs/Chatbox/index.js +1564 -506
- package/lib/cjs/EventCalendar/index.js +2 -1
- package/lib/cjs/EventCalendarTimeline/index.js +2 -1
- package/lib/cjs/LiveSearch/index.js +341 -21
- package/lib/cjs/MultipleCheckboxes/index.js +341 -21
- package/lib/cjs/MultipleSelect/index.js +341 -21
- package/lib/cjs/NativeSelect/index.js +341 -21
- package/lib/cjs/Radio/index.js +341 -21
- package/lib/cjs/Select/index.js +341 -21
- package/lib/cjs/Utils/anim.js +338 -22
- package/lib/cjs/Utils/initDefaultOptions.js +338 -22
- package/lib/cjs/Utils/validate.d.ts +16 -6
- package/lib/cjs/Utils/validate.js +338 -21
- package/lib/esm/Chatbox/index.tsx +15 -11
- package/lib/esm/Chatbox/utils/func.ts +10 -10
- package/lib/esm/EventCalendar/index.tsx +2 -1
- package/lib/esm/EventCalendarTimeline/index.tsx +2 -1
- package/lib/esm/Utils/libs/validate.ts +367 -26
- package/package.json +1 -1
- package/lib/esm/Chatbox/useStreamController.tsx +0 -277
package/lib/cjs/Radio/index.js
CHANGED
|
@@ -638,6 +638,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
638
638
|
__nested_webpack_require_993__.r(__webpack_exports__);
|
|
639
639
|
/* harmony export */
|
|
640
640
|
__nested_webpack_require_993__.d(__webpack_exports__, {
|
|
641
|
+
/* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
|
|
642
|
+
return (/* binding */_fixAndParseJSON
|
|
643
|
+
);
|
|
644
|
+
},
|
|
641
645
|
/* harmony export */"isEmail": function isEmail() {
|
|
642
646
|
return (/* binding */_isEmail
|
|
643
647
|
);
|
|
@@ -682,37 +686,353 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
682
686
|
}, _typeof(obj);
|
|
683
687
|
}
|
|
684
688
|
/**
|
|
685
|
-
*
|
|
686
|
-
* @
|
|
687
|
-
* @returns boolean indicating if the string is a valid number
|
|
689
|
+
* Fix And Parse JSON (Support for handling complex escape JSON strings)
|
|
690
|
+
* @private
|
|
688
691
|
*/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
692
|
+
/*
|
|
693
|
+
- Always try JSON.parse first;
|
|
694
|
+
- If parsing fails, unescape \" → ";
|
|
695
|
+
- Then process the outermost object or array key-by-key, value-by-value;
|
|
696
|
+
- If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
|
|
697
|
+
recursively treat that value as a new root to repair;
|
|
698
|
+
- For values wrapped in quotes ('...' or "..."), extract the inner text and
|
|
699
|
+
re-encode it using JSON.stringify (ensures internal single/double quotes
|
|
700
|
+
are not corrupted);
|
|
701
|
+
- Set MAX_DEPTH to prevent infinite recursion.
|
|
702
|
+
*/
|
|
703
|
+
// fixAndParseJSON - recursively repairs top-level key/value
|
|
704
|
+
// (when encountering outermost values that are objects/arrays, it recurses)
|
|
705
|
+
|
|
706
|
+
/*
|
|
707
|
+
DEMO:
|
|
708
|
+
|
|
709
|
+
// ✅ Valid JSON (contains svg and single-quote content)
|
|
710
|
+
const okJson = `{
|
|
711
|
+
"label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
|
|
712
|
+
"value":"new",
|
|
713
|
+
"onClick":"method.setVal(''); method.clearData();"
|
|
714
|
+
}`;
|
|
715
|
+
|
|
716
|
+
// ❌ Single-quote JSON
|
|
717
|
+
const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
|
|
718
|
+
|
|
719
|
+
// ❌ Escaped JSON
|
|
720
|
+
const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
|
|
721
|
+
|
|
722
|
+
const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
|
|
723
|
+
|
|
724
|
+
const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> Deep Thought","value":"brief","onClick":"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}"},{"label":"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> Concise Answer","value":"brief","onClick":"if(isActive){method.setContextData({systemPrompt:'Please answer concisely, around 150 words, keep reasoning brief',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}"},{"label":"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> Metrics Analysis","value":"lab","onClick":"return method.executeCustomMethod('getLibList')","isSelect":true,"dynamicOptions":true}]";
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
|
|
728
|
+
console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
|
|
729
|
+
console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
|
|
730
|
+
console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
|
|
731
|
+
console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
|
|
732
|
+
*/
|
|
733
|
+
function _fixAndParseJSON(input) {
|
|
734
|
+
var MAX_DEPTH = 6;
|
|
735
|
+
|
|
736
|
+
// 1. Fast attempt
|
|
737
|
+
try {
|
|
738
|
+
return {
|
|
739
|
+
success: true,
|
|
740
|
+
data: JSON.parse(input)
|
|
741
|
+
};
|
|
742
|
+
} catch (e) {
|
|
743
|
+
// continue to repair
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// 2. Simple unescape of \" (common when copied from JS literals)
|
|
747
|
+
var s = input;
|
|
748
|
+
if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
|
|
749
|
+
s = s.trim();
|
|
750
|
+
try {
|
|
751
|
+
if (s.startsWith('{')) {
|
|
752
|
+
s = processTopObject(s, 0, MAX_DEPTH);
|
|
753
|
+
} else if (s.startsWith('[')) {
|
|
754
|
+
s = processTopArray(s, 0, MAX_DEPTH);
|
|
755
|
+
} else {
|
|
756
|
+
throw new Error('Input is not an object or array');
|
|
757
|
+
}
|
|
758
|
+
return {
|
|
759
|
+
success: true,
|
|
760
|
+
data: JSON.parse(s)
|
|
761
|
+
};
|
|
762
|
+
} catch (err) {
|
|
763
|
+
return {
|
|
764
|
+
success: false,
|
|
765
|
+
error: 'Invalid JSON format',
|
|
766
|
+
details: err instanceof Error ? err.message : String(err)
|
|
767
|
+
};
|
|
696
768
|
}
|
|
697
|
-
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/* ---------- Helper (recursive) functions ---------- */
|
|
772
|
+
|
|
773
|
+
function processTopObject(str, depth, MAX_DEPTH) {
|
|
774
|
+
if (depth > MAX_DEPTH) return str;
|
|
775
|
+
str = str.trim();
|
|
776
|
+
// Ensure it is wrapped in { ... }
|
|
777
|
+
if (!(str.startsWith('{') && str.endsWith('}'))) {
|
|
778
|
+
var f = str.indexOf('{');
|
|
779
|
+
var l = str.lastIndexOf('}');
|
|
780
|
+
if (f === -1 || l === -1 || l <= f) return str;
|
|
781
|
+
str = str.slice(f, l + 1);
|
|
782
|
+
}
|
|
783
|
+
var inner = str.slice(1, -1);
|
|
784
|
+
var pairs = splitTopLevel(inner);
|
|
785
|
+
var repairedPairs = pairs.map(function (pair) {
|
|
786
|
+
if (!pair || pair.trim() === '') return '';
|
|
787
|
+
var idx = findTopLevelColon(pair);
|
|
788
|
+
if (idx === -1) {
|
|
789
|
+
return pair; // Non key:value fragment, keep as is (rare case)
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
var rawKey = pair.slice(0, idx).trim();
|
|
793
|
+
var rawVal = pair.slice(idx + 1);
|
|
794
|
+
var keyContent = extractKeyContent(rawKey);
|
|
795
|
+
var keyJson = JSON.stringify(keyContent);
|
|
796
|
+
var repairedValue = repairPossiblyQuotedValue(rawVal, depth + 1, MAX_DEPTH);
|
|
797
|
+
return keyJson + ':' + repairedValue;
|
|
798
|
+
});
|
|
799
|
+
return '{' + repairedPairs.join(',') + '}';
|
|
800
|
+
}
|
|
801
|
+
function processTopArray(str, depth, MAX_DEPTH) {
|
|
802
|
+
if (depth > MAX_DEPTH) return str;
|
|
803
|
+
str = str.trim();
|
|
804
|
+
if (!(str.startsWith('[') && str.endsWith(']'))) {
|
|
805
|
+
var f = str.indexOf('[');
|
|
806
|
+
var l = str.lastIndexOf(']');
|
|
807
|
+
if (f === -1 || l === -1 || l <= f) return str;
|
|
808
|
+
str = str.slice(f, l + 1);
|
|
809
|
+
}
|
|
810
|
+
var inner = str.slice(1, -1);
|
|
811
|
+
var elements = splitTopLevel(inner);
|
|
812
|
+
var processed = elements.map(function (el) {
|
|
813
|
+
var t = el.trim();
|
|
814
|
+
if (t === '') return '';
|
|
815
|
+
if (t.startsWith('{')) return processTopObject(t, depth + 1, MAX_DEPTH);
|
|
816
|
+
if (t.startsWith('[')) return processTopArray(t, depth + 1, MAX_DEPTH);
|
|
817
|
+
return repairPossiblyQuotedValue(t, depth + 1, MAX_DEPTH);
|
|
818
|
+
});
|
|
819
|
+
return '[' + processed.join(',') + ']';
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// If value is quoted, extract inside and JSON.stringify again (safe escaping)
|
|
823
|
+
// If value is unquoted object/array literal, recurse treating it as new root
|
|
824
|
+
// Otherwise return as is (numbers, booleans, null, or raw expressions)
|
|
825
|
+
function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
|
|
826
|
+
var v = rawVal.trim();
|
|
827
|
+
if (v === '') return v;
|
|
828
|
+
if (v[0] === '"' || v[0] === "'") {
|
|
829
|
+
var quote = v[0];
|
|
830
|
+
// Find the last unescaped matching quote
|
|
831
|
+
var lastPos = -1;
|
|
832
|
+
for (var i = v.length - 1; i >= 0; i--) {
|
|
833
|
+
if (v[i] === quote) {
|
|
834
|
+
// check if escaped
|
|
835
|
+
var bs = 0;
|
|
836
|
+
var k = i - 1;
|
|
837
|
+
while (k >= 0 && v[k] === '\\') {
|
|
838
|
+
bs++;
|
|
839
|
+
k--;
|
|
840
|
+
}
|
|
841
|
+
if (bs % 2 === 0) {
|
|
842
|
+
lastPos = i;
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
|
|
848
|
+
return JSON.stringify(inner); // Generate valid JSON string (auto escape)
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// If unquoted object/array literal -> recurse
|
|
852
|
+
if (v.startsWith('{')) {
|
|
853
|
+
return processTopObject(v, depth, MAX_DEPTH);
|
|
854
|
+
}
|
|
855
|
+
if (v.startsWith('[')) {
|
|
856
|
+
return processTopArray(v, depth, MAX_DEPTH);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// Other (number, boolean, null, raw expression): return as is
|
|
860
|
+
return v;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/* --------- Utils: split by top-level commas, find colon, extract key --------- */
|
|
864
|
+
|
|
865
|
+
// Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
|
|
866
|
+
function splitTopLevel(str) {
|
|
867
|
+
var parts = [];
|
|
868
|
+
var buf = '';
|
|
869
|
+
var depthCurly = 0;
|
|
870
|
+
var depthSquare = 0;
|
|
871
|
+
var depthParen = 0;
|
|
872
|
+
var inSingle = false;
|
|
873
|
+
var inDouble = false;
|
|
874
|
+
var esc = false;
|
|
875
|
+
for (var i = 0; i < str.length; i++) {
|
|
876
|
+
var ch = str[i];
|
|
877
|
+
if (esc) {
|
|
878
|
+
buf += ch;
|
|
879
|
+
esc = false;
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
if (ch === '\\') {
|
|
883
|
+
buf += ch;
|
|
884
|
+
esc = true;
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
if (ch === "'" && !inDouble) {
|
|
888
|
+
inSingle = !inSingle;
|
|
889
|
+
buf += ch;
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
if (ch === '"' && !inSingle) {
|
|
893
|
+
inDouble = !inDouble;
|
|
894
|
+
buf += ch;
|
|
895
|
+
continue;
|
|
896
|
+
}
|
|
897
|
+
if (!inSingle && !inDouble) {
|
|
898
|
+
if (ch === '{') {
|
|
899
|
+
depthCurly++;
|
|
900
|
+
buf += ch;
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
903
|
+
if (ch === '}') {
|
|
904
|
+
depthCurly--;
|
|
905
|
+
buf += ch;
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
if (ch === '[') {
|
|
909
|
+
depthSquare++;
|
|
910
|
+
buf += ch;
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
if (ch === ']') {
|
|
914
|
+
depthSquare--;
|
|
915
|
+
buf += ch;
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
if (ch === '(') {
|
|
919
|
+
depthParen++;
|
|
920
|
+
buf += ch;
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
if (ch === ')') {
|
|
924
|
+
depthParen--;
|
|
925
|
+
buf += ch;
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
if (ch === ',' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
|
|
929
|
+
parts.push(buf);
|
|
930
|
+
buf = '';
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
buf += ch;
|
|
935
|
+
}
|
|
936
|
+
if (buf.trim() !== '') parts.push(buf);
|
|
937
|
+
return parts;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// Find the first top-level colon (ignores strings and nested structures)
|
|
941
|
+
function findTopLevelColon(str) {
|
|
942
|
+
var inSingle = false;
|
|
943
|
+
var inDouble = false;
|
|
944
|
+
var esc = false;
|
|
945
|
+
var depthCurly = 0;
|
|
946
|
+
var depthSquare = 0;
|
|
947
|
+
var depthParen = 0;
|
|
948
|
+
for (var i = 0; i < str.length; i++) {
|
|
949
|
+
var ch = str[i];
|
|
950
|
+
if (esc) {
|
|
951
|
+
esc = false;
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
if (ch === '\\') {
|
|
955
|
+
esc = true;
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
if (ch === "'" && !inDouble) {
|
|
959
|
+
inSingle = !inSingle;
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
if (ch === '"' && !inSingle) {
|
|
963
|
+
inDouble = !inDouble;
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
if (!inSingle && !inDouble) {
|
|
967
|
+
if (ch === '{') {
|
|
968
|
+
depthCurly++;
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
if (ch === '}') {
|
|
972
|
+
depthCurly--;
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
if (ch === '[') {
|
|
976
|
+
depthSquare++;
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
979
|
+
if (ch === ']') {
|
|
980
|
+
depthSquare--;
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
if (ch === '(') {
|
|
984
|
+
depthParen++;
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
if (ch === ')') {
|
|
988
|
+
depthParen--;
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
if (ch === ':' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
|
|
992
|
+
return i;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return -1;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// Extract key content (supports "key", 'key', key) → returns pure string key
|
|
1000
|
+
function extractKeyContent(rawKey) {
|
|
1001
|
+
var r = rawKey.trim();
|
|
1002
|
+
if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
|
|
1003
|
+
var inner = r.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
1004
|
+
return inner;
|
|
1005
|
+
}
|
|
1006
|
+
return r;
|
|
698
1007
|
}
|
|
699
1008
|
|
|
700
1009
|
/**
|
|
701
1010
|
* Determine whether it is in JSON format
|
|
702
|
-
* @
|
|
703
|
-
* @returns boolean indicating if the value is valid JSON
|
|
1011
|
+
* @private
|
|
704
1012
|
*/
|
|
705
|
-
function _isJSON(
|
|
706
|
-
if (typeof
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
if (/^[\],:{}\s]*$/.test(str.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
|
1013
|
+
function _isJSON(input) {
|
|
1014
|
+
if (typeof input === 'string' && input.length > 0) {
|
|
1015
|
+
return _fixAndParseJSON(input).success;
|
|
1016
|
+
} else {
|
|
1017
|
+
if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
|
|
711
1018
|
return true;
|
|
1019
|
+
} else {
|
|
1020
|
+
return false;
|
|
712
1021
|
}
|
|
713
|
-
return false;
|
|
714
1022
|
}
|
|
715
|
-
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Check if a string is a valid number
|
|
1027
|
+
* @param str - The string to check
|
|
1028
|
+
* @returns boolean indicating if the string is a valid number
|
|
1029
|
+
*/
|
|
1030
|
+
function _isValidNumeric(str) {
|
|
1031
|
+
if (typeof str !== "string") return false; // we only process strings!
|
|
1032
|
+
if (!isNaN(Number(str)) &&
|
|
1033
|
+
// use type coercion to parse the _entirety_ of the string
|
|
1034
|
+
!isNaN(parseFloat(str)) // ensure strings of whitespace fail
|
|
1035
|
+
) {
|
|
716
1036
|
return true;
|
|
717
1037
|
}
|
|
718
1038
|
return false;
|