MCPcopy
hub / github.com/adobe/react-spectrum / pick

Function pick

packages/dev/parcel-packager-docs/DocsPackager.js:555–588  ·  view source on GitHub ↗
(obj, toPick, nodes)

Source from the content-addressed store, hash-verified

553
554// Exactly the same as `omit()` above except for `keys.has(key)` instead of `!keys.has(key)`.
555function pick(obj, toPick, nodes) {
556 obj = resolveValue(obj, nodes);
557
558 if (obj.type === 'interface' || obj.type === 'object') {
559 let keys = new Set();
560 if (toPick.type === 'string' && toPick.value) {
561 keys.add(toPick.value);
562 } else if (toPick.type === 'union') {
563 for (let e of toPick.elements) {
564 if (e.type === 'string' && e.value) {
565 keys.add(e.value);
566 }
567 }
568 }
569
570 if (keys.size === 0) {
571 return obj;
572 }
573
574 let properties = {};
575 for (let key in obj.properties) {
576 if (keys.has(key)) {
577 properties[key] = obj.properties[key];
578 }
579 }
580
581 return {
582 ...obj,
583 properties
584 };
585 }
586
587 return obj;
588}
589
590function resolveValue(obj, nodes) {
591 if (obj.type === 'link') {

Callers 1

fnFunction · 0.85

Calls 3

resolveValueFunction · 0.70
addMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected