@microsurveysai/react-native 0.1.1 → 0.1.2

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.
package/dist/index.cjs CHANGED
@@ -117,16 +117,29 @@ function numOr(v, fallback) {
117
117
  function strOrUndef(v) {
118
118
  return typeof v === "string" ? v : void 0;
119
119
  }
120
+ var MAX_SCALE_POINTS = 101;
121
+ var MAX_SCALE_ABS = 1e3;
122
+ var MAX_STARS = 100;
123
+ var MAX_OPTIONS = 100;
124
+ function boundedScale(min, max) {
125
+ const lo = Math.min(Math.max(min, -MAX_SCALE_ABS), MAX_SCALE_ABS);
126
+ let hi = Math.min(Math.max(max, -MAX_SCALE_ABS), MAX_SCALE_ABS);
127
+ if (hi - lo > MAX_SCALE_POINTS - 1) hi = lo + MAX_SCALE_POINTS - 1;
128
+ return { min: lo, max: hi };
129
+ }
130
+ function boundedOptions(raw) {
131
+ return Array.isArray(raw) ? raw.slice(0, MAX_OPTIONS) : [];
132
+ }
120
133
  function normalizeConfig(type, raw) {
121
134
  switch (type) {
122
135
  case "NPS":
123
- return { kind: "scale", min: numOr(raw.min, 0), max: numOr(raw.max, 10), minLabel: strOrUndef(raw.minLabel), maxLabel: strOrUndef(raw.maxLabel) };
136
+ return { kind: "scale", ...boundedScale(numOr(raw.min, 0), numOr(raw.max, 10)), minLabel: strOrUndef(raw.minLabel), maxLabel: strOrUndef(raw.maxLabel) };
124
137
  case "CES":
125
- return { kind: "scale", min: numOr(raw.min, 1), max: numOr(raw.max, 7), minLabel: strOrUndef(raw.minLabel), maxLabel: strOrUndef(raw.maxLabel) };
138
+ return { kind: "scale", ...boundedScale(numOr(raw.min, 1), numOr(raw.max, 7)), minLabel: strOrUndef(raw.minLabel), maxLabel: strOrUndef(raw.maxLabel) };
126
139
  case "CSAT_STAR":
127
- return { kind: "stars", count: numOr(raw.count, 5) };
140
+ return { kind: "stars", count: Math.min(numOr(raw.count, 5), MAX_STARS) };
128
141
  case "CSAT_EMOJI": {
129
- const opts = Array.isArray(raw.options) ? raw.options : [];
142
+ const opts = boundedOptions(raw.options);
130
143
  const options = opts.map((o) => {
131
144
  const oo = asObject(o);
132
145
  return { value: String(oo.value ?? ""), emoji: typeof oo.emoji === "string" ? oo.emoji : "", label: strOrUndef(oo.label) };
@@ -136,7 +149,7 @@ function normalizeConfig(type, raw) {
136
149
  case "THUMBS":
137
150
  return { kind: "thumbs" };
138
151
  case "SINGLE_CHOICE": {
139
- const opts = Array.isArray(raw.options) ? raw.options : [];
152
+ const opts = boundedOptions(raw.options);
140
153
  const options = opts.map((o) => {
141
154
  const oo = asObject(o);
142
155
  const value = String(oo.value ?? "");