|
Last change
on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const isPlainObject = require('./isPlainObject.js');
|
|---|
| 6 |
|
|---|
| 7 | function isJSONValue(value) {
|
|---|
| 8 | switch (typeof value) {
|
|---|
| 9 | case 'object': {
|
|---|
| 10 | return value === null || isJSONArray(value) || isJSONObject(value);
|
|---|
| 11 | }
|
|---|
| 12 | case 'string':
|
|---|
| 13 | case 'number':
|
|---|
| 14 | case 'boolean': {
|
|---|
| 15 | return true;
|
|---|
| 16 | }
|
|---|
| 17 | default: {
|
|---|
| 18 | return false;
|
|---|
| 19 | }
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | function isJSONArray(value) {
|
|---|
| 23 | if (!Array.isArray(value)) {
|
|---|
| 24 | return false;
|
|---|
| 25 | }
|
|---|
| 26 | return value.every(item => isJSONValue(item));
|
|---|
| 27 | }
|
|---|
| 28 | function isJSONObject(obj) {
|
|---|
| 29 | if (!isPlainObject.isPlainObject(obj)) {
|
|---|
| 30 | return false;
|
|---|
| 31 | }
|
|---|
| 32 | const keys = Reflect.ownKeys(obj);
|
|---|
| 33 | for (let i = 0; i < keys.length; i++) {
|
|---|
| 34 | const key = keys[i];
|
|---|
| 35 | const value = obj[key];
|
|---|
| 36 | if (typeof key !== 'string') {
|
|---|
| 37 | return false;
|
|---|
| 38 | }
|
|---|
| 39 | if (!isJSONValue(value)) {
|
|---|
| 40 | return false;
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 | return true;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | exports.isJSONArray = isJSONArray;
|
|---|
| 47 | exports.isJSONObject = isJSONObject;
|
|---|
| 48 | exports.isJSONValue = isJSONValue;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.