@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.js CHANGED
@@ -76,16 +76,29 @@ function numOr(v, fallback) {
76
76
  function strOrUndef(v) {
77
77
  return typeof v === "string" ? v : void 0;
78
78
  }
79
+ var MAX_SCALE_POINTS = 101;
80
+ var MAX_SCALE_ABS = 1e3;
81
+ var MAX_STARS = 100;
82
+ var MAX_OPTIONS = 100;
83
+ function boundedScale(min, max) {
84
+ const lo = Math.min(Math.max(min, -MAX_SCALE_ABS), MAX_SCALE_ABS);
85
+ let hi = Math.min(Math.max(max, -MAX_SCALE_ABS), MAX_SCALE_ABS);
86
+ if (hi - lo > MAX_SCALE_POINTS - 1) hi = lo + MAX_SCALE_POINTS - 1;
87
+ return { min: lo, max: hi };
88
+ }
89
+ function boundedOptions(raw) {
90
+ return Array.isArray(raw) ? raw.slice(0, MAX_OPTIONS) : [];
91
+ }
79
92
  function normalizeConfig(type, raw) {
80
93
  switch (type) {
81
94
  case "NPS":
82
- return { kind: "scale", min: numOr(raw.min, 0), max: numOr(raw.max, 10), minLabel: strOrUndef(raw.minLabel), maxLabel: strOrUndef(raw.maxLabel) };
95
+ return { kind: "scale", ...boundedScale(numOr(raw.min, 0), numOr(raw.max, 10)), minLabel: strOrUndef(raw.minLabel), maxLabel: strOrUndef(raw.maxLabel) };
83
96
  case "CES":
84
- return { kind: "scale", min: numOr(raw.min, 1), max: numOr(raw.max, 7), minLabel: strOrUndef(raw.minLabel), maxLabel: strOrUndef(raw.maxLabel) };
97
+ return { kind: "scale", ...boundedScale(numOr(raw.min, 1), numOr(raw.max, 7)), minLabel: strOrUndef(raw.minLabel), maxLabel: strOrUndef(raw.maxLabel) };
85
98
  case "CSAT_STAR":
86
- return { kind: "stars", count: numOr(raw.count, 5) };
99
+ return { kind: "stars", count: Math.min(numOr(raw.count, 5), MAX_STARS) };
87
100
  case "CSAT_EMOJI": {
88
- const opts = Array.isArray(raw.options) ? raw.options : [];
101
+ const opts = boundedOptions(raw.options);
89
102
  const options = opts.map((o) => {
90
103
  const oo = asObject(o);
91
104
  return { value: String(oo.value ?? ""), emoji: typeof oo.emoji === "string" ? oo.emoji : "", label: strOrUndef(oo.label) };
@@ -95,7 +108,7 @@ function normalizeConfig(type, raw) {
95
108
  case "THUMBS":
96
109
  return { kind: "thumbs" };
97
110
  case "SINGLE_CHOICE": {
98
- const opts = Array.isArray(raw.options) ? raw.options : [];
111
+ const opts = boundedOptions(raw.options);
99
112
  const options = opts.map((o) => {
100
113
  const oo = asObject(o);
101
114
  const value = String(oo.value ?? "");