MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / splitProp

Method splitProp

tools/nodered2mcu.js:1775–1815  ·  view source on GitHub ↗
(prop)

Source from the content-addressed store, hash-verified

1773 return this.resolveValue(type, value);
1774 }
1775 splitProp(prop) {
1776 let parts = [], start = 0, depth = 0;
1777 for (let position = 0; position < prop.length; position++) {
1778 const c = prop[position];
1779 if (position === (prop.length - 1)) {
1780 parts.push(prop.slice(start));
1781 break;
1782 }
1783
1784 if ((0 === depth) && ("." === c)) {
1785 if (start !== position)
1786 parts.push(prop.slice(start, position));
1787 start = position + 1;
1788 }
1789 else
1790 if ("[" === c) {
1791 if (0 === depth) {
1792 parts.push(prop.slice(start, position));
1793 start = position;
1794 }
1795 depth += 1;
1796 }
1797 else
1798 if ("]" === c) {
1799 depth -= 1;
1800 if (0 === depth) {
1801 parts.push(prop.slice(start, position + 1));
1802 start = position + 1;
1803 }
1804 }
1805 }
1806
1807 return parts.map(part => {
1808 if (part.startsWith("["))
1809 return part;
1810 const identifier = regexIdentifierNameES6.test(part);
1811 if (identifier)
1812 return "." + part;
1813 return `["${part}"]`;
1814 });
1815 }
1816 prepareProp(prop) {
1817 return this.splitProp(prop).join("");
1818 }

Callers 2

preparePropMethod · 0.80
createPropPathMethod · 0.80

Calls 4

mapMethod · 0.80
testMethod · 0.80
sliceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected