@danielsimonjr/mathts-expression 0.6.7 → 0.7.1

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +204 -0
  2. package/dist/index.js +752 -244
  3. package/package.json +59 -59
package/dist/index.js CHANGED
@@ -5,11 +5,7 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __commonJS = (cb, mod) => function __require() {
8
- try {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- } catch (e) {
11
- throw mod = 0, e;
12
- }
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
9
  };
14
10
  var __copyProps = (to, from, except, desc) => {
15
11
  if (from && typeof from === "object" || typeof from === "function") {
@@ -164,6 +160,11 @@ function isRange(x) {
164
160
  const obj = x;
165
161
  return obj.constructor?.prototype?.isRange === true;
166
162
  }
163
+ function isIndex(x) {
164
+ if (!x || typeof x !== "object") return false;
165
+ const obj = x;
166
+ return obj.constructor?.prototype?.isIndex === true;
167
+ }
167
168
  function isHelp(x) {
168
169
  if (!x || typeof x !== "object") return false;
169
170
  const obj = x;
@@ -650,6 +651,75 @@ import {
650
651
  toPrecision
651
652
  } from "@danielsimonjr/mathts-core/internal";
652
653
 
654
+ // src/utils/customs.ts
655
+ function getSafeProperty(object, prop) {
656
+ if (isSafeProperty(object, prop)) {
657
+ return object[prop];
658
+ }
659
+ if (typeof object[prop] === "function" && isSafeMethod(object, prop)) {
660
+ throw new Error('Cannot access method "' + String(prop) + '" as a property');
661
+ }
662
+ throw new Error('No access to property "' + String(prop) + '"');
663
+ }
664
+ function setSafeProperty(object, prop, value) {
665
+ if (isSafeProperty(object, prop)) {
666
+ object[prop] = value;
667
+ return value;
668
+ }
669
+ throw new Error('No access to property "' + String(prop) + '"');
670
+ }
671
+ function isSafeProperty(object, prop) {
672
+ if (!isPlainObject(object) && !Array.isArray(object)) {
673
+ return false;
674
+ }
675
+ if (hasOwnProperty(safeNativeProperties, prop)) {
676
+ return true;
677
+ }
678
+ if (prop in Object.prototype) {
679
+ return false;
680
+ }
681
+ if (prop in Function.prototype) {
682
+ return false;
683
+ }
684
+ return true;
685
+ }
686
+ function getSafeMethod(object, method) {
687
+ if (!isSafeMethod(object, method)) {
688
+ throw new Error('No access to method "' + String(method) + '"');
689
+ }
690
+ return object[method];
691
+ }
692
+ function isSafeMethod(object, method) {
693
+ if (object === null || object === void 0 || typeof object[method] !== "function") {
694
+ return false;
695
+ }
696
+ if (hasOwnProperty(object, method) && Object.getPrototypeOf && method in Object.getPrototypeOf(object)) {
697
+ return false;
698
+ }
699
+ if (hasOwnProperty(safeNativeMethods, method)) {
700
+ return true;
701
+ }
702
+ if (method in Object.prototype) {
703
+ return false;
704
+ }
705
+ if (method in Function.prototype) {
706
+ return false;
707
+ }
708
+ return true;
709
+ }
710
+ function isPlainObject(object) {
711
+ return typeof object === "object" && !!object && object.constructor === Object;
712
+ }
713
+ var safeNativeProperties = {
714
+ length: true,
715
+ name: true
716
+ };
717
+ var safeNativeMethods = {
718
+ toString: true,
719
+ valueOf: true,
720
+ toLocaleString: true
721
+ };
722
+
653
723
  // src/parse.ts
654
724
  var name = "parse";
655
725
  var dependencies = [
@@ -756,7 +826,8 @@ var createParse = /* @__PURE__ */ factory(
756
826
  ">=": true,
757
827
  "<<": true,
758
828
  ">>": true,
759
- ">>>": true
829
+ ">>>": true,
830
+ ".": true
760
831
  };
761
832
  const NAMED_DELIMITERS = {
762
833
  mod: true,
@@ -851,25 +922,28 @@ var createParse = /* @__PURE__ */ factory(
851
922
  const c1 = currentCharacter(state);
852
923
  const c2 = currentString(state, 2);
853
924
  const c3 = currentString(state, 3);
925
+ let delim = "";
854
926
  if (c3.length === 3 && DELIMITERS[c3]) {
855
- state.tokenType = 1 /* DELIMITER */;
856
- state.token = c3;
857
- next(state);
858
- next(state);
859
- next(state);
860
- return;
861
- }
862
- if (c2.length === 2 && DELIMITERS[c2] && (c2 !== "?." || !parse.isDigit(state.expression.charAt(state.index + 2)))) {
863
- state.tokenType = 1 /* DELIMITER */;
864
- state.token = c2;
865
- next(state);
866
- next(state);
867
- return;
927
+ delim = c3;
928
+ } else if (c2.length === 2 && DELIMITERS[c2]) {
929
+ delim = c2;
930
+ } else if (DELIMITERS[c1]) {
931
+ delim = c1;
932
+ }
933
+ if (delim) {
934
+ if (delim.endsWith(".") && parse.isDigit(state.expression.charAt(state.index + delim.length))) {
935
+ delim = delim.slice(0, -1);
936
+ if (delim.length > 0 && !DELIMITERS[delim]) {
937
+ delim = "";
938
+ }
939
+ }
868
940
  }
869
- if (DELIMITERS[c1]) {
941
+ if (delim) {
870
942
  state.tokenType = 1 /* DELIMITER */;
871
- state.token = c1;
872
- next(state);
943
+ state.token = delim;
944
+ for (let i = 0; i < delim.length; i++) {
945
+ next(state);
946
+ }
873
947
  return;
874
948
  }
875
949
  if (parse.isDigitDot(c1)) {
@@ -904,10 +978,6 @@ var createParse = /* @__PURE__ */ factory(
904
978
  if (currentCharacter(state) === ".") {
905
979
  state.token += currentCharacter(state);
906
980
  next(state);
907
- if (!parse.isDigit(currentCharacter(state))) {
908
- state.tokenType = 1 /* DELIMITER */;
909
- return;
910
- }
911
981
  } else {
912
982
  while (parse.isDigit(currentCharacter(state))) {
913
983
  state.token += currentCharacter(state);
@@ -1023,26 +1093,29 @@ var createParse = /* @__PURE__ */ factory(
1023
1093
  function parseBlock(state) {
1024
1094
  let node;
1025
1095
  const blocks = [];
1026
- let visible;
1027
- if (state.token !== "" && state.token !== "\n" && state.token !== ";") {
1028
- node = parseAssignment(state);
1029
- if (state.comment) {
1030
- node.comment = state.comment;
1031
- }
1032
- }
1033
- while (state.token === "\n" || state.token === ";") {
1034
- if (blocks.length === 0 && node) {
1035
- visible = state.token !== ";";
1036
- blocks.push({ node, visible });
1037
- }
1038
- getToken(state);
1039
- if (state.token !== "\n" && state.token !== ";" && state.token !== "") {
1096
+ let hasSeparators = false;
1097
+ let nodePushed = true;
1098
+ while (state.token !== "") {
1099
+ if (state.token !== "\n" && state.token !== ";") {
1040
1100
  node = parseAssignment(state);
1101
+ nodePushed = false;
1041
1102
  if (state.comment) {
1042
1103
  node.comment = state.comment;
1043
1104
  }
1044
- visible = state.token !== ";";
1045
- blocks.push({ node, visible });
1105
+ }
1106
+ if (state.token === "\n" || state.token === ";") {
1107
+ hasSeparators = true;
1108
+ if (node && !nodePushed) {
1109
+ blocks.push({ node, visible: state.token !== ";" });
1110
+ nodePushed = true;
1111
+ }
1112
+ getToken(state);
1113
+ } else {
1114
+ if (node && hasSeparators && !nodePushed) {
1115
+ blocks.push({ node, visible: state.token !== ";" });
1116
+ nodePushed = true;
1117
+ }
1118
+ break;
1046
1119
  }
1047
1120
  }
1048
1121
  if (blocks.length > 0) {
@@ -1688,7 +1761,7 @@ var createParse = /* @__PURE__ */ factory(
1688
1761
  throw createSyntaxError(state, "Colon : expected after object key");
1689
1762
  }
1690
1763
  getToken(state);
1691
- properties2[key] = parseAssignment(state);
1764
+ setSafeProperty(properties2, key, parseAssignment(state));
1692
1765
  }
1693
1766
  } while (state.token === ",");
1694
1767
  if (state.token !== "}") {
@@ -1787,9 +1860,15 @@ var createParserClass = /* @__PURE__ */ factory(
1787
1860
  Parser.prototype.type = "Parser";
1788
1861
  Parser.prototype.isParser = true;
1789
1862
  Parser.prototype.evaluate = function(expr) {
1863
+ if (typeof expr !== "string" && !Array.isArray(expr)) {
1864
+ throw new TypeError('String or string array expected for parameter "expr"');
1865
+ }
1790
1866
  return evaluate(expr, this.scope);
1791
1867
  };
1792
1868
  Parser.prototype.get = function(name47) {
1869
+ if (typeof name47 !== "string") {
1870
+ throw new TypeError('String expected for parameter "name"');
1871
+ }
1793
1872
  return this.scope.has(name47) ? this.scope.get(name47) : void 0;
1794
1873
  };
1795
1874
  Parser.prototype.getAll = function() {
@@ -1973,6 +2052,516 @@ var createHelpClass = /* @__PURE__ */ factory(
1973
2052
  { isClass: true }
1974
2053
  );
1975
2054
 
2055
+ // src/embeddedDocs/physicalConstants/speedOfLight.ts
2056
+ var speedOfLightDocs = {
2057
+ name: "speedOfLight",
2058
+ category: "Physical Constants",
2059
+ syntax: ["speedOfLight"],
2060
+ description: "Speed of light in vacuum",
2061
+ examples: ["speedOfLight"],
2062
+ seealso: []
2063
+ };
2064
+
2065
+ // src/embeddedDocs/physicalConstants/gravitationConstant.ts
2066
+ var gravitationConstantDocs = {
2067
+ name: "gravitationConstant",
2068
+ category: "Physical Constants",
2069
+ syntax: ["gravitationConstant"],
2070
+ description: "Newtonian constant of gravitation",
2071
+ examples: ["gravitationConstant"],
2072
+ seealso: []
2073
+ };
2074
+
2075
+ // src/embeddedDocs/physicalConstants/planckConstant.ts
2076
+ var planckConstantDocs = {
2077
+ name: "planckConstant",
2078
+ category: "Physical Constants",
2079
+ syntax: ["planckConstant"],
2080
+ description: "Planck constant",
2081
+ examples: ["planckConstant"],
2082
+ seealso: []
2083
+ };
2084
+
2085
+ // src/embeddedDocs/physicalConstants/reducedPlanckConstant.ts
2086
+ var reducedPlanckConstantDocs = {
2087
+ name: "reducedPlanckConstant",
2088
+ category: "Physical Constants",
2089
+ syntax: ["reducedPlanckConstant"],
2090
+ description: "Reduced Planck constant",
2091
+ examples: ["reducedPlanckConstant"],
2092
+ seealso: []
2093
+ };
2094
+
2095
+ // src/embeddedDocs/physicalConstants/magneticConstant.ts
2096
+ var magneticConstantDocs = {
2097
+ name: "magneticConstant",
2098
+ category: "Physical Constants",
2099
+ syntax: ["magneticConstant"],
2100
+ description: "Magnetic constant (vacuum permeability)",
2101
+ examples: ["magneticConstant"],
2102
+ seealso: []
2103
+ };
2104
+
2105
+ // src/embeddedDocs/physicalConstants/electricConstant.ts
2106
+ var electricConstantDocs = {
2107
+ name: "electricConstant",
2108
+ category: "Physical Constants",
2109
+ syntax: ["electricConstant"],
2110
+ description: "Electric constant (vacuum permeability)",
2111
+ examples: ["electricConstant"],
2112
+ seealso: []
2113
+ };
2114
+
2115
+ // src/embeddedDocs/physicalConstants/vacuumImpedance.ts
2116
+ var vacuumImpedanceDocs = {
2117
+ name: "vacuumImpedance",
2118
+ category: "Physical Constants",
2119
+ syntax: ["vacuumImpedance"],
2120
+ description: "Characteristic impedance of vacuum",
2121
+ examples: ["vacuumImpedance"],
2122
+ seealso: []
2123
+ };
2124
+
2125
+ // src/embeddedDocs/physicalConstants/coulomb.ts
2126
+ var coulombDocs = {
2127
+ name: "coulomb",
2128
+ category: "Physical Constants",
2129
+ syntax: ["coulomb"],
2130
+ description: "Coulomb's constant. Deprecated in favor of coulombConstant",
2131
+ examples: ["coulomb"],
2132
+ seealso: []
2133
+ };
2134
+
2135
+ // src/embeddedDocs/physicalConstants/coulombConstant.ts
2136
+ var coulombConstantDocs = {
2137
+ name: "coulombConstant",
2138
+ category: "Physical Constants",
2139
+ syntax: ["coulombConstant"],
2140
+ description: "Coulomb's constant",
2141
+ examples: ["coulombConstant"],
2142
+ seealso: []
2143
+ };
2144
+
2145
+ // src/embeddedDocs/physicalConstants/elementaryCharge.ts
2146
+ var elementaryChargeDocs = {
2147
+ name: "elementaryCharge",
2148
+ category: "Physical Constants",
2149
+ syntax: ["elementaryCharge"],
2150
+ description: "Elementary charge",
2151
+ examples: ["elementaryCharge"],
2152
+ seealso: []
2153
+ };
2154
+
2155
+ // src/embeddedDocs/physicalConstants/bohrMagneton.ts
2156
+ var bohrMagnetonDocs = {
2157
+ name: "bohrMagneton",
2158
+ category: "Physical Constants",
2159
+ syntax: ["bohrMagneton"],
2160
+ description: "Bohr magneton",
2161
+ examples: ["bohrMagneton"],
2162
+ seealso: []
2163
+ };
2164
+
2165
+ // src/embeddedDocs/physicalConstants/conductanceQuantum.ts
2166
+ var conductanceQuantumDocs = {
2167
+ name: "conductanceQuantum",
2168
+ category: "Physical Constants",
2169
+ syntax: ["conductanceQuantum"],
2170
+ description: "Conductance quantum",
2171
+ examples: ["conductanceQuantum"],
2172
+ seealso: []
2173
+ };
2174
+
2175
+ // src/embeddedDocs/physicalConstants/inverseConductanceQuantum.ts
2176
+ var inverseConductanceQuantumDocs = {
2177
+ name: "inverseConductanceQuantum",
2178
+ category: "Physical Constants",
2179
+ syntax: ["inverseConductanceQuantum"],
2180
+ description: "Inverse conductance quantum",
2181
+ examples: ["inverseConductanceQuantum"],
2182
+ seealso: []
2183
+ };
2184
+
2185
+ // src/embeddedDocs/physicalConstants/magneticFluxQuantum.ts
2186
+ var magneticFluxQuantumDocs = {
2187
+ name: "magneticFluxQuantum",
2188
+ category: "Physical Constants",
2189
+ syntax: ["magneticFluxQuantum"],
2190
+ description: "Magnetic flux quantum",
2191
+ examples: ["magneticFluxQuantum"],
2192
+ seealso: []
2193
+ };
2194
+
2195
+ // src/embeddedDocs/physicalConstants/nuclearMagneton.ts
2196
+ var nuclearMagnetonDocs = {
2197
+ name: "nuclearMagneton",
2198
+ category: "Physical Constants",
2199
+ syntax: ["nuclearMagneton"],
2200
+ description: "Nuclear magneton",
2201
+ examples: ["nuclearMagneton"],
2202
+ seealso: []
2203
+ };
2204
+
2205
+ // src/embeddedDocs/physicalConstants/klitzing.ts
2206
+ var klitzingDocs = {
2207
+ name: "klitzing",
2208
+ category: "Physical Constants",
2209
+ syntax: ["klitzing"],
2210
+ description: "Von Klitzing constant",
2211
+ examples: ["klitzing"],
2212
+ seealso: []
2213
+ };
2214
+
2215
+ // src/embeddedDocs/physicalConstants/bohrRadius.ts
2216
+ var bohrRadiusDocs = {
2217
+ name: "bohrRadius",
2218
+ category: "Physical Constants",
2219
+ syntax: ["bohrRadius"],
2220
+ description: "Bohr radius",
2221
+ examples: ["bohrRadius"],
2222
+ seealso: []
2223
+ };
2224
+
2225
+ // src/embeddedDocs/physicalConstants/classicalElectronRadius.ts
2226
+ var classicalElectronRadiusDocs = {
2227
+ name: "classicalElectronRadius",
2228
+ category: "Physical Constants",
2229
+ syntax: ["classicalElectronRadius"],
2230
+ description: "Classical electron radius",
2231
+ examples: ["classicalElectronRadius"],
2232
+ seealso: []
2233
+ };
2234
+
2235
+ // src/embeddedDocs/physicalConstants/electronMass.ts
2236
+ var electronMassDocs = {
2237
+ name: "electronMass",
2238
+ category: "Physical Constants",
2239
+ syntax: ["electronMass"],
2240
+ description: "Electron mass",
2241
+ examples: ["electronMass"],
2242
+ seealso: []
2243
+ };
2244
+
2245
+ // src/embeddedDocs/physicalConstants/fermiCoupling.ts
2246
+ var fermiCouplingDocs = {
2247
+ name: "fermiCoupling",
2248
+ category: "Physical Constants",
2249
+ syntax: ["fermiCoupling"],
2250
+ description: "Fermi coupling constant",
2251
+ examples: ["fermiCoupling"],
2252
+ seealso: []
2253
+ };
2254
+
2255
+ // src/embeddedDocs/physicalConstants/fineStructure.ts
2256
+ var fineStructureDocs = {
2257
+ name: "fineStructure",
2258
+ category: "Physical Constants",
2259
+ syntax: ["fineStructure"],
2260
+ description: "Fine-structure constant",
2261
+ examples: ["fineStructure"],
2262
+ seealso: []
2263
+ };
2264
+
2265
+ // src/embeddedDocs/physicalConstants/hartreeEnergy.ts
2266
+ var hartreeEnergyDocs = {
2267
+ name: "hartreeEnergy",
2268
+ category: "Physical Constants",
2269
+ syntax: ["hartreeEnergy"],
2270
+ description: "Hartree energy",
2271
+ examples: ["hartreeEnergy"],
2272
+ seealso: []
2273
+ };
2274
+
2275
+ // src/embeddedDocs/physicalConstants/protonMass.ts
2276
+ var protonMassDocs = {
2277
+ name: "protonMass",
2278
+ category: "Physical Constants",
2279
+ syntax: ["protonMass"],
2280
+ description: "Proton mass",
2281
+ examples: ["protonMass"],
2282
+ seealso: []
2283
+ };
2284
+
2285
+ // src/embeddedDocs/physicalConstants/deuteronMass.ts
2286
+ var deuteronMassDocs = {
2287
+ name: "deuteronMass",
2288
+ category: "Physical Constants",
2289
+ syntax: ["deuteronMass"],
2290
+ description: "Deuteron Mass",
2291
+ examples: ["deuteronMass"],
2292
+ seealso: []
2293
+ };
2294
+
2295
+ // src/embeddedDocs/physicalConstants/neutronMass.ts
2296
+ var neutronMassDocs = {
2297
+ name: "neutronMass",
2298
+ category: "Physical Constants",
2299
+ syntax: ["neutronMass"],
2300
+ description: "Neutron mass",
2301
+ examples: ["neutronMass"],
2302
+ seealso: []
2303
+ };
2304
+
2305
+ // src/embeddedDocs/physicalConstants/quantumOfCirculation.ts
2306
+ var quantumOfCirculationDocs = {
2307
+ name: "quantumOfCirculation",
2308
+ category: "Physical Constants",
2309
+ syntax: ["quantumOfCirculation"],
2310
+ description: "Quantum of circulation",
2311
+ examples: ["quantumOfCirculation"],
2312
+ seealso: []
2313
+ };
2314
+
2315
+ // src/embeddedDocs/physicalConstants/rydberg.ts
2316
+ var rydbergDocs = {
2317
+ name: "rydberg",
2318
+ category: "Physical Constants",
2319
+ syntax: ["rydberg"],
2320
+ description: "Rydberg constant",
2321
+ examples: ["rydberg"],
2322
+ seealso: []
2323
+ };
2324
+
2325
+ // src/embeddedDocs/physicalConstants/thomsonCrossSection.ts
2326
+ var thomsonCrossSectionDocs = {
2327
+ name: "thomsonCrossSection",
2328
+ category: "Physical Constants",
2329
+ syntax: ["thomsonCrossSection"],
2330
+ description: "Thomson cross section",
2331
+ examples: ["thomsonCrossSection"],
2332
+ seealso: []
2333
+ };
2334
+
2335
+ // src/embeddedDocs/physicalConstants/weakMixingAngle.ts
2336
+ var weakMixingAngleDocs = {
2337
+ name: "weakMixingAngle",
2338
+ category: "Physical Constants",
2339
+ syntax: ["weakMixingAngle"],
2340
+ description: "Weak mixing angle",
2341
+ examples: ["weakMixingAngle"],
2342
+ seealso: []
2343
+ };
2344
+
2345
+ // src/embeddedDocs/physicalConstants/efimovFactor.ts
2346
+ var efimovFactorDocs = {
2347
+ name: "efimovFactor",
2348
+ category: "Physical Constants",
2349
+ syntax: ["efimovFactor"],
2350
+ description: "Efimov factor",
2351
+ examples: ["efimovFactor"],
2352
+ seealso: []
2353
+ };
2354
+
2355
+ // src/embeddedDocs/physicalConstants/atomicMass.ts
2356
+ var atomicMassDocs = {
2357
+ name: "atomicMass",
2358
+ category: "Physical Constants",
2359
+ syntax: ["atomicMass"],
2360
+ description: "Atomic mass constant",
2361
+ examples: ["atomicMass"],
2362
+ seealso: []
2363
+ };
2364
+
2365
+ // src/embeddedDocs/physicalConstants/avogadro.ts
2366
+ var avogadroDocs = {
2367
+ name: "avogadro",
2368
+ category: "Physical Constants",
2369
+ syntax: ["avogadro"],
2370
+ description: "Avogadro's number",
2371
+ examples: ["avogadro"],
2372
+ seealso: []
2373
+ };
2374
+
2375
+ // src/embeddedDocs/physicalConstants/boltzmann.ts
2376
+ var boltzmannDocs = {
2377
+ name: "boltzmann",
2378
+ category: "Physical Constants",
2379
+ syntax: ["boltzmann"],
2380
+ description: "Boltzmann constant",
2381
+ examples: ["boltzmann"],
2382
+ seealso: []
2383
+ };
2384
+
2385
+ // src/embeddedDocs/physicalConstants/faraday.ts
2386
+ var faradayDocs = {
2387
+ name: "faraday",
2388
+ category: "Physical Constants",
2389
+ syntax: ["faraday"],
2390
+ description: "Faraday constant",
2391
+ examples: ["faraday"],
2392
+ seealso: []
2393
+ };
2394
+
2395
+ // src/embeddedDocs/physicalConstants/firstRadiation.ts
2396
+ var firstRadiationDocs = {
2397
+ name: "firstRadiation",
2398
+ category: "Physical Constants",
2399
+ syntax: ["firstRadiation"],
2400
+ description: "First radiation constant",
2401
+ examples: ["firstRadiation"],
2402
+ seealso: []
2403
+ };
2404
+
2405
+ // src/embeddedDocs/physicalConstants/loschmidt.ts
2406
+ var loschmidtDocs = {
2407
+ name: "loschmidt",
2408
+ category: "Physical Constants",
2409
+ syntax: ["loschmidt"],
2410
+ description: "Loschmidt constant at T=273.15 K and p=101.325 kPa",
2411
+ examples: ["loschmidt"],
2412
+ seealso: []
2413
+ };
2414
+
2415
+ // src/embeddedDocs/physicalConstants/gasConstant.ts
2416
+ var gasConstantDocs = {
2417
+ name: "gasConstant",
2418
+ category: "Physical Constants",
2419
+ syntax: ["gasConstant"],
2420
+ description: "Gas constant",
2421
+ examples: ["gasConstant"],
2422
+ seealso: []
2423
+ };
2424
+
2425
+ // src/embeddedDocs/physicalConstants/molarPlanckConstant.ts
2426
+ var molarPlanckConstantDocs = {
2427
+ name: "molarPlanckConstant",
2428
+ category: "Physical Constants",
2429
+ syntax: ["molarPlanckConstant"],
2430
+ description: "Molar Planck constant",
2431
+ examples: ["molarPlanckConstant"],
2432
+ seealso: []
2433
+ };
2434
+
2435
+ // src/embeddedDocs/physicalConstants/molarVolume.ts
2436
+ var molarVolumeDocs = {
2437
+ name: "molarVolume",
2438
+ category: "Physical Constants",
2439
+ syntax: ["molarVolume"],
2440
+ description: "Molar volume of an ideal gas at T=273.15 K and p=101.325 kPa",
2441
+ examples: ["molarVolume"],
2442
+ seealso: []
2443
+ };
2444
+
2445
+ // src/embeddedDocs/physicalConstants/sackurTetrode.ts
2446
+ var sackurTetrodeDocs = {
2447
+ name: "sackurTetrode",
2448
+ category: "Physical Constants",
2449
+ syntax: ["sackurTetrode"],
2450
+ description: "Sackur-Tetrode constant at T=1 K and p=101.325 kPa",
2451
+ examples: ["sackurTetrode"],
2452
+ seealso: []
2453
+ };
2454
+
2455
+ // src/embeddedDocs/physicalConstants/secondRadiation.ts
2456
+ var secondRadiationDocs = {
2457
+ name: "secondRadiation",
2458
+ category: "Physical Constants",
2459
+ syntax: ["secondRadiation"],
2460
+ description: "Second radiation constant",
2461
+ examples: ["secondRadiation"],
2462
+ seealso: []
2463
+ };
2464
+
2465
+ // src/embeddedDocs/physicalConstants/stefanBoltzmann.ts
2466
+ var stefanBoltzmannDocs = {
2467
+ name: "stefanBoltzmann",
2468
+ category: "Physical Constants",
2469
+ syntax: ["stefanBoltzmann"],
2470
+ description: "Stefan-Boltzmann constant",
2471
+ examples: ["stefanBoltzmann"],
2472
+ seealso: []
2473
+ };
2474
+
2475
+ // src/embeddedDocs/physicalConstants/wienDisplacement.ts
2476
+ var wienDisplacementDocs = {
2477
+ name: "wienDisplacement",
2478
+ category: "Physical Constants",
2479
+ syntax: ["wienDisplacement"],
2480
+ description: "Wien displacement law constant",
2481
+ examples: ["wienDisplacement"],
2482
+ seealso: []
2483
+ };
2484
+
2485
+ // src/embeddedDocs/physicalConstants/molarMass.ts
2486
+ var molarMassDocs = {
2487
+ name: "molarMass",
2488
+ category: "Physical Constants",
2489
+ syntax: ["molarMass"],
2490
+ description: "Molar mass constant",
2491
+ examples: ["molarMass"],
2492
+ seealso: []
2493
+ };
2494
+
2495
+ // src/embeddedDocs/physicalConstants/molarMassC12.ts
2496
+ var molarMassC12Docs = {
2497
+ name: "molarMassC12",
2498
+ category: "Physical Constants",
2499
+ syntax: ["molarMassC12"],
2500
+ description: "Molar mass constant of carbon-12",
2501
+ examples: ["molarMassC12"],
2502
+ seealso: []
2503
+ };
2504
+
2505
+ // src/embeddedDocs/physicalConstants/gravity.ts
2506
+ var gravityDocs = {
2507
+ name: "gravity",
2508
+ category: "Physical Constants",
2509
+ syntax: ["gravity"],
2510
+ description: "Standard acceleration of gravity (standard acceleration of free-fall on Earth)",
2511
+ examples: ["gravity"],
2512
+ seealso: []
2513
+ };
2514
+
2515
+ // src/embeddedDocs/physicalConstants/planckLength.ts
2516
+ var planckLengthDocs = {
2517
+ name: "planckLength",
2518
+ category: "Physical Constants",
2519
+ syntax: ["planckLength"],
2520
+ description: "Planck length",
2521
+ examples: ["planckLength"],
2522
+ seealso: []
2523
+ };
2524
+
2525
+ // src/embeddedDocs/physicalConstants/planckMass.ts
2526
+ var planckMassDocs = {
2527
+ name: "planckMass",
2528
+ category: "Physical Constants",
2529
+ syntax: ["planckMass"],
2530
+ description: "Planck mass",
2531
+ examples: ["planckMass"],
2532
+ seealso: []
2533
+ };
2534
+
2535
+ // src/embeddedDocs/physicalConstants/planckTime.ts
2536
+ var planckTimeDocs = {
2537
+ name: "planckTime",
2538
+ category: "Physical Constants",
2539
+ syntax: ["planckTime"],
2540
+ description: "Planck time",
2541
+ examples: ["planckTime"],
2542
+ seealso: []
2543
+ };
2544
+
2545
+ // src/embeddedDocs/physicalConstants/planckCharge.ts
2546
+ var planckChargeDocs = {
2547
+ name: "planckCharge",
2548
+ category: "Physical Constants",
2549
+ syntax: ["planckCharge"],
2550
+ description: "Planck charge",
2551
+ examples: ["planckCharge"],
2552
+ seealso: []
2553
+ };
2554
+
2555
+ // src/embeddedDocs/physicalConstants/planckTemperature.ts
2556
+ var planckTemperatureDocs = {
2557
+ name: "planckTemperature",
2558
+ category: "Physical Constants",
2559
+ syntax: ["planckTemperature"],
2560
+ description: "Planck temperature",
2561
+ examples: ["planckTemperature"],
2562
+ seealso: []
2563
+ };
2564
+
1976
2565
  // src/embeddedDocs/constants/e.ts
1977
2566
  var eDocs = {
1978
2567
  name: "e",
@@ -6275,102 +6864,59 @@ var embeddedDocs = {
6275
6864
  true: trueDocs,
6276
6865
  version: versionDocs,
6277
6866
  // physical constants
6278
- // TODO: more detailed docs for physical constants
6279
- speedOfLight: { description: "Speed of light in vacuum", examples: ["speedOfLight"] },
6280
- gravitationConstant: {
6281
- description: "Newtonian constant of gravitation",
6282
- examples: ["gravitationConstant"]
6283
- },
6284
- planckConstant: { description: "Planck constant", examples: ["planckConstant"] },
6285
- reducedPlanckConstant: {
6286
- description: "Reduced Planck constant",
6287
- examples: ["reducedPlanckConstant"]
6288
- },
6289
- magneticConstant: {
6290
- description: "Magnetic constant (vacuum permeability)",
6291
- examples: ["magneticConstant"]
6292
- },
6293
- electricConstant: {
6294
- description: "Electric constant (vacuum permeability)",
6295
- examples: ["electricConstant"]
6296
- },
6297
- vacuumImpedance: {
6298
- description: "Characteristic impedance of vacuum",
6299
- examples: ["vacuumImpedance"]
6300
- },
6301
- coulomb: {
6302
- description: "Coulomb's constant. Deprecated in favor of coulombConstant",
6303
- examples: ["coulombConstant"]
6304
- },
6305
- coulombConstant: { description: "Coulomb's constant", examples: ["coulombConstant"] },
6306
- elementaryCharge: { description: "Elementary charge", examples: ["elementaryCharge"] },
6307
- bohrMagneton: { description: "Bohr magneton", examples: ["bohrMagneton"] },
6308
- conductanceQuantum: { description: "Conductance quantum", examples: ["conductanceQuantum"] },
6309
- inverseConductanceQuantum: {
6310
- description: "Inverse conductance quantum",
6311
- examples: ["inverseConductanceQuantum"]
6312
- },
6867
+ speedOfLight: speedOfLightDocs,
6868
+ gravitationConstant: gravitationConstantDocs,
6869
+ planckConstant: planckConstantDocs,
6870
+ reducedPlanckConstant: reducedPlanckConstantDocs,
6871
+ magneticConstant: magneticConstantDocs,
6872
+ electricConstant: electricConstantDocs,
6873
+ vacuumImpedance: vacuumImpedanceDocs,
6874
+ coulomb: coulombDocs,
6875
+ coulombConstant: coulombConstantDocs,
6876
+ elementaryCharge: elementaryChargeDocs,
6877
+ bohrMagneton: bohrMagnetonDocs,
6878
+ conductanceQuantum: conductanceQuantumDocs,
6879
+ inverseConductanceQuantum: inverseConductanceQuantumDocs,
6313
6880
  // josephson: {description: 'Josephson constant', examples: ['josephson']},
6314
- magneticFluxQuantum: { description: "Magnetic flux quantum", examples: ["magneticFluxQuantum"] },
6315
- nuclearMagneton: { description: "Nuclear magneton", examples: ["nuclearMagneton"] },
6316
- klitzing: { description: "Von Klitzing constant", examples: ["klitzing"] },
6317
- bohrRadius: { description: "Bohr radius", examples: ["bohrRadius"] },
6318
- classicalElectronRadius: {
6319
- description: "Classical electron radius",
6320
- examples: ["classicalElectronRadius"]
6321
- },
6322
- electronMass: { description: "Electron mass", examples: ["electronMass"] },
6323
- fermiCoupling: { description: "Fermi coupling constant", examples: ["fermiCoupling"] },
6324
- fineStructure: { description: "Fine-structure constant", examples: ["fineStructure"] },
6325
- hartreeEnergy: { description: "Hartree energy", examples: ["hartreeEnergy"] },
6326
- protonMass: { description: "Proton mass", examples: ["protonMass"] },
6327
- deuteronMass: { description: "Deuteron Mass", examples: ["deuteronMass"] },
6328
- neutronMass: { description: "Neutron mass", examples: ["neutronMass"] },
6329
- quantumOfCirculation: {
6330
- description: "Quantum of circulation",
6331
- examples: ["quantumOfCirculation"]
6332
- },
6333
- rydberg: { description: "Rydberg constant", examples: ["rydberg"] },
6334
- thomsonCrossSection: { description: "Thomson cross section", examples: ["thomsonCrossSection"] },
6335
- weakMixingAngle: { description: "Weak mixing angle", examples: ["weakMixingAngle"] },
6336
- efimovFactor: { description: "Efimov factor", examples: ["efimovFactor"] },
6337
- atomicMass: { description: "Atomic mass constant", examples: ["atomicMass"] },
6338
- avogadro: { description: "Avogadro's number", examples: ["avogadro"] },
6339
- boltzmann: { description: "Boltzmann constant", examples: ["boltzmann"] },
6340
- faraday: { description: "Faraday constant", examples: ["faraday"] },
6341
- firstRadiation: { description: "First radiation constant", examples: ["firstRadiation"] },
6342
- loschmidt: {
6343
- description: "Loschmidt constant at T=273.15 K and p=101.325 kPa",
6344
- examples: ["loschmidt"]
6345
- },
6346
- gasConstant: { description: "Gas constant", examples: ["gasConstant"] },
6347
- molarPlanckConstant: { description: "Molar Planck constant", examples: ["molarPlanckConstant"] },
6348
- molarVolume: {
6349
- description: "Molar volume of an ideal gas at T=273.15 K and p=101.325 kPa",
6350
- examples: ["molarVolume"]
6351
- },
6352
- sackurTetrode: {
6353
- description: "Sackur-Tetrode constant at T=1 K and p=101.325 kPa",
6354
- examples: ["sackurTetrode"]
6355
- },
6356
- secondRadiation: { description: "Second radiation constant", examples: ["secondRadiation"] },
6357
- stefanBoltzmann: { description: "Stefan-Boltzmann constant", examples: ["stefanBoltzmann"] },
6358
- wienDisplacement: {
6359
- description: "Wien displacement law constant",
6360
- examples: ["wienDisplacement"]
6361
- },
6881
+ magneticFluxQuantum: magneticFluxQuantumDocs,
6882
+ nuclearMagneton: nuclearMagnetonDocs,
6883
+ klitzing: klitzingDocs,
6884
+ bohrRadius: bohrRadiusDocs,
6885
+ classicalElectronRadius: classicalElectronRadiusDocs,
6886
+ electronMass: electronMassDocs,
6887
+ fermiCoupling: fermiCouplingDocs,
6888
+ fineStructure: fineStructureDocs,
6889
+ hartreeEnergy: hartreeEnergyDocs,
6890
+ protonMass: protonMassDocs,
6891
+ deuteronMass: deuteronMassDocs,
6892
+ neutronMass: neutronMassDocs,
6893
+ quantumOfCirculation: quantumOfCirculationDocs,
6894
+ rydberg: rydbergDocs,
6895
+ thomsonCrossSection: thomsonCrossSectionDocs,
6896
+ weakMixingAngle: weakMixingAngleDocs,
6897
+ efimovFactor: efimovFactorDocs,
6898
+ atomicMass: atomicMassDocs,
6899
+ avogadro: avogadroDocs,
6900
+ boltzmann: boltzmannDocs,
6901
+ faraday: faradayDocs,
6902
+ firstRadiation: firstRadiationDocs,
6903
+ loschmidt: loschmidtDocs,
6904
+ gasConstant: gasConstantDocs,
6905
+ molarPlanckConstant: molarPlanckConstantDocs,
6906
+ molarVolume: molarVolumeDocs,
6907
+ sackurTetrode: sackurTetrodeDocs,
6908
+ secondRadiation: secondRadiationDocs,
6909
+ stefanBoltzmann: stefanBoltzmannDocs,
6910
+ wienDisplacement: wienDisplacementDocs,
6362
6911
  // spectralRadiance: {description: 'First radiation constant for spectral radiance', examples: ['spectralRadiance']},
6363
- molarMass: { description: "Molar mass constant", examples: ["molarMass"] },
6364
- molarMassC12: { description: "Molar mass constant of carbon-12", examples: ["molarMassC12"] },
6365
- gravity: {
6366
- description: "Standard acceleration of gravity (standard acceleration of free-fall on Earth)",
6367
- examples: ["gravity"]
6368
- },
6369
- planckLength: { description: "Planck length", examples: ["planckLength"] },
6370
- planckMass: { description: "Planck mass", examples: ["planckMass"] },
6371
- planckTime: { description: "Planck time", examples: ["planckTime"] },
6372
- planckCharge: { description: "Planck charge", examples: ["planckCharge"] },
6373
- planckTemperature: { description: "Planck temperature", examples: ["planckTemperature"] },
6912
+ molarMass: molarMassDocs,
6913
+ molarMassC12: molarMassC12Docs,
6914
+ gravity: gravityDocs,
6915
+ planckLength: planckLengthDocs,
6916
+ planckMass: planckMassDocs,
6917
+ planckTime: planckTimeDocs,
6918
+ planckCharge: planckChargeDocs,
6919
+ planckTemperature: planckTemperatureDocs,
6374
6920
  // functions - algebra
6375
6921
  derivative: derivativeDocs,
6376
6922
  lsolve: lsolveDocs,
@@ -6710,75 +7256,6 @@ var embeddedDocs = {
6710
7256
  gammainc: gammaincDocs
6711
7257
  };
6712
7258
 
6713
- // src/utils/customs.ts
6714
- function getSafeProperty(object, prop) {
6715
- if (isSafeProperty(object, prop)) {
6716
- return object[prop];
6717
- }
6718
- if (typeof object[prop] === "function" && isSafeMethod(object, prop)) {
6719
- throw new Error('Cannot access method "' + String(prop) + '" as a property');
6720
- }
6721
- throw new Error('No access to property "' + String(prop) + '"');
6722
- }
6723
- function setSafeProperty(object, prop, value) {
6724
- if (isSafeProperty(object, prop)) {
6725
- object[prop] = value;
6726
- return value;
6727
- }
6728
- throw new Error('No access to property "' + String(prop) + '"');
6729
- }
6730
- function isSafeProperty(object, prop) {
6731
- if (!isPlainObject(object) && !Array.isArray(object)) {
6732
- return false;
6733
- }
6734
- if (hasOwnProperty(safeNativeProperties, prop)) {
6735
- return true;
6736
- }
6737
- if (prop in Object.prototype) {
6738
- return false;
6739
- }
6740
- if (prop in Function.prototype) {
6741
- return false;
6742
- }
6743
- return true;
6744
- }
6745
- function getSafeMethod(object, method) {
6746
- if (!isSafeMethod(object, method)) {
6747
- throw new Error('No access to method "' + String(method) + '"');
6748
- }
6749
- return object[method];
6750
- }
6751
- function isSafeMethod(object, method) {
6752
- if (object === null || object === void 0 || typeof object[method] !== "function") {
6753
- return false;
6754
- }
6755
- if (hasOwnProperty(object, method) && Object.getPrototypeOf && method in Object.getPrototypeOf(object)) {
6756
- return false;
6757
- }
6758
- if (hasOwnProperty(safeNativeMethods, method)) {
6759
- return true;
6760
- }
6761
- if (method in Object.prototype) {
6762
- return false;
6763
- }
6764
- if (method in Function.prototype) {
6765
- return false;
6766
- }
6767
- return true;
6768
- }
6769
- function isPlainObject(object) {
6770
- return typeof object === "object" && !!object && object.constructor === Object;
6771
- }
6772
- var safeNativeProperties = {
6773
- length: true,
6774
- name: true
6775
- };
6776
- var safeNativeMethods = {
6777
- toString: true,
6778
- valueOf: true,
6779
- toLocaleString: true
6780
- };
6781
-
6782
7259
  // src/compiler/compile.ts
6783
7260
  function compile(node, mathScope) {
6784
7261
  const evalFn = compileNode(node, mathScope, {});
@@ -7860,6 +8337,72 @@ function errorTransform(err) {
7860
8337
  return err;
7861
8338
  }
7862
8339
 
8340
+ // src/utils/array.ts
8341
+ import {
8342
+ arraySize,
8343
+ validate,
8344
+ validateIndexSourceSize,
8345
+ validateIndex,
8346
+ isEmptyIndex,
8347
+ resize,
8348
+ reshape,
8349
+ processSizesWildcard,
8350
+ squeeze,
8351
+ unsqueeze,
8352
+ flatten,
8353
+ map,
8354
+ forEach,
8355
+ filter,
8356
+ filterRegExp,
8357
+ join,
8358
+ identify,
8359
+ generalize,
8360
+ getArrayDataType,
8361
+ last,
8362
+ initial,
8363
+ concat,
8364
+ broadcastSizes,
8365
+ checkBroadcastingRules,
8366
+ broadcastTo,
8367
+ broadcastArrays,
8368
+ stretch,
8369
+ getArrayElement,
8370
+ deepMapArray,
8371
+ deepForEachArray,
8372
+ cloneArray
8373
+ } from "@danielsimonjr/mathts-core/internal";
8374
+
8375
+ // src/error/DimensionError.ts
8376
+ import { DimensionError } from "@danielsimonjr/mathts-core/internal";
8377
+
8378
+ // src/node/utils/stringSubset.ts
8379
+ function getStringSubset(str, index) {
8380
+ if (!isIndex(index)) {
8381
+ throw new TypeError("Index expected");
8382
+ }
8383
+ if (isEmptyIndex(index)) {
8384
+ return "";
8385
+ }
8386
+ validateIndexSourceSize(Array.from(str), index);
8387
+ if (index.size().length !== 1) {
8388
+ throw new DimensionError(index.size().length, 1);
8389
+ }
8390
+ const strLen = str.length;
8391
+ validateIndex(index.min()[0], strLen);
8392
+ validateIndex(index.max()[0], strLen);
8393
+ const range = index.dimension(0);
8394
+ let substr = "";
8395
+ function callback(v) {
8396
+ substr += str.charAt(v);
8397
+ }
8398
+ if (Number.isInteger(range)) {
8399
+ callback(range);
8400
+ } else {
8401
+ range.forEach(callback);
8402
+ }
8403
+ return substr;
8404
+ }
8405
+
7863
8406
  // src/node/utils/access.ts
7864
8407
  function accessFactory({ subset }) {
7865
8408
  return function access(object, index) {
@@ -7869,7 +8412,7 @@ function accessFactory({ subset }) {
7869
8412
  } else if (object && typeof object.subset === "function") {
7870
8413
  return object.subset(index);
7871
8414
  } else if (typeof object === "string") {
7872
- return subset(object, index);
8415
+ return getStringSubset(object, index);
7873
8416
  } else if (typeof object === "object") {
7874
8417
  if (!index.isObjectProperty()) {
7875
8418
  throw new TypeError("Cannot apply a numeric index as object property");
@@ -8085,41 +8628,6 @@ var createAccessorNode = /* @__PURE__ */ factory(
8085
8628
  { isClass: true, isNode: true }
8086
8629
  );
8087
8630
 
8088
- // src/utils/array.ts
8089
- import {
8090
- arraySize,
8091
- validate,
8092
- validateIndexSourceSize,
8093
- validateIndex,
8094
- isEmptyIndex,
8095
- resize,
8096
- reshape,
8097
- processSizesWildcard,
8098
- squeeze,
8099
- unsqueeze,
8100
- flatten,
8101
- map,
8102
- forEach,
8103
- filter,
8104
- filterRegExp,
8105
- join,
8106
- identify,
8107
- generalize,
8108
- getArrayDataType,
8109
- last,
8110
- initial,
8111
- concat,
8112
- broadcastSizes,
8113
- checkBroadcastingRules,
8114
- broadcastTo,
8115
- broadcastArrays,
8116
- stretch,
8117
- getArrayElement,
8118
- deepMapArray,
8119
- deepForEachArray,
8120
- cloneArray
8121
- } from "@danielsimonjr/mathts-core/internal";
8122
-
8123
8631
  // src/node/ArrayNode.ts
8124
8632
  var name7 = "ArrayNode";
8125
8633
  var dependencies7 = ["Node"];
@@ -10432,14 +10940,14 @@ var createObjectNode = /* @__PURE__ */ factory(
10432
10940
  const stringifiedKey = stringify(key);
10433
10941
  const parsedKey = JSON.parse(stringifiedKey);
10434
10942
  const prop = getSafeProperty(this.properties, key);
10435
- evalEntries[parsedKey] = prop._compile(math, argNames);
10943
+ setSafeProperty(evalEntries, parsedKey, prop._compile(math, argNames));
10436
10944
  }
10437
10945
  }
10438
10946
  return function evalObjectNode(scope, args, context) {
10439
10947
  const obj = {};
10440
10948
  for (const key in evalEntries) {
10441
10949
  if (hasOwnProperty(evalEntries, key)) {
10442
- obj[key] = evalEntries[key](scope, args, context);
10950
+ setSafeProperty(obj, key, evalEntries[key](scope, args, context));
10443
10951
  }
10444
10952
  }
10445
10953
  return obj;