UNPKG

951 BJavaScriptView Raw
1import React from 'react';
2import JSONNestedNode from './JSONNestedNode.js';
3// Returns the "n Items" string for this node,
4// generating and caching it if it hasn't been created yet.
5function createItemString(data, limit) {
6 let count = 0;
7 let hasMore = false;
8 if (Number.isSafeInteger(data.size)) {
9 count = data.size;
10 }
11 else {
12 // eslint-disable-next-line no-unused-vars
13 for (const entry of data) {
14 if (limit && count + 1 > limit) {
15 hasMore = true;
16 break;
17 }
18 count += 1;
19 }
20 }
21 return `${hasMore ? '>' : ''}${count} ${count !== 1 ? 'entries' : 'entry'}`;
22}
23// Configures <JSONNestedNode> to render an iterable
24export default function JSONIterableNode(props) {
25 return (React.createElement(JSONNestedNode, { ...props, nodeType: "Iterable", nodeTypeIndicator: "()", createItemString: createItemString, expandable: true }));
26}