@miso.ai/server-commons 0.6.0-beta.1 → 0.6.0

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/package.json CHANGED
@@ -20,5 +20,5 @@
20
20
  "uuid": "^9.0.0",
21
21
  "yargs": "^17.5.1"
22
22
  },
23
- "version": "0.6.0-beta.1"
23
+ "version": "0.6.0"
24
24
  }
@@ -60,3 +60,19 @@ export function transform(fn, { transform: _, ...options } = {}) {
60
60
  },
61
61
  });
62
62
  }
63
+
64
+ export function take(n, { transform: _, ...options } = {}) {
65
+ let count = 0;
66
+ return new Transform({
67
+ ...options,
68
+ transform (chunk, _, next) {
69
+ if (count > n) {
70
+ next(undefined);
71
+ this.end();
72
+ } else {
73
+ next(undefined, chunk);
74
+ }
75
+ count++;
76
+ }
77
+ });
78
+ }
package/src/string.js CHANGED
@@ -30,3 +30,11 @@ export function padLeft(val, num, str) {
30
30
  export function padRight(val, num, str) {
31
31
  return pad(false, val, num, str);
32
32
  }
33
+
34
+ export function encodeURIIfNecessary(str) {
35
+ return typeof str === 'string' && !str.includes('%') ? encodeURI(str) : str;
36
+ }
37
+
38
+ export function encodeURIComponentIfNecessary(str) {
39
+ return typeof str === 'string' && !str.includes('%') ? encodeURIComponent(str) : str;
40
+ }