cafe-utility 9.4.0 → 9.5.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.
Files changed (3) hide show
  1. package/index.d.ts +2 -0
  2. package/index.js +11 -1
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -159,6 +159,7 @@ declare function resolveVariables(string: string, variables: Record<string, stri
159
159
  declare function resolveVariableWithDefaultSyntax(string: string, key: string, value: string, prefix?: string, separator?: string): string;
160
160
  declare function resolveRemainingVariablesWithDefaults(string: string, prefix?: string, separator?: string): string;
161
161
  declare function resolveMarkdownLinks(string: string, transformer: (label: string, link: string) => string): string;
162
+ declare function toQueryString(object: Record<string, any>, questionMark?: boolean): string;
162
163
  declare function parseCsv(string: string, delimiter?: string, quote?: string): string[];
163
164
  declare function humanizeProgress(state: Progress): string;
164
165
  declare function waitFor(predicate: () => Promise<boolean>, waitLength: number, maxWaits: number): Promise<boolean>;
@@ -452,6 +453,7 @@ export declare const Objects: {
452
453
  pickRandomKey: typeof pickRandomKey;
453
454
  mapRandomKey: typeof mapRandomKey;
454
455
  fromObjectString: typeof fromObjectString;
456
+ toQueryString: typeof toQueryString;
455
457
  };
456
458
  export declare const Pagination: {
457
459
  asPageNumber: typeof asPageNumber;
package/index.js CHANGED
@@ -1132,6 +1132,14 @@ function resolveMarkdownLinks(string, transformer) {
1132
1132
  return string
1133
1133
  }
1134
1134
 
1135
+ function toQueryString(object, questionMark = true) {
1136
+ const queryString = Object.entries(object)
1137
+ .filter(([_, value]) => value !== undefined && value !== null)
1138
+ .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
1139
+ .join('&')
1140
+ return queryString ? (questionMark ? '?' : '') + queryString : ''
1141
+ }
1142
+
1135
1143
  function parseCsv(string, delimiter = ',', quote = '"') {
1136
1144
  const items = []
1137
1145
  let buffer = ''
@@ -1486,6 +1494,7 @@ function mapRandomKey(object, mapFunction) {
1486
1494
  }
1487
1495
 
1488
1496
  function fromObjectString(string) {
1497
+ string = string.replace(/\r\n/g, '\n')
1489
1498
  string = string.replace(/(\w+)\((.+)\)/g, (match, $1, $2) => {
1490
1499
  return `${$1}(${$2.replaceAll(',', '&comma;')})`
1491
1500
  })
@@ -2394,7 +2403,8 @@ exports.Objects = {
2394
2403
  diffKeys,
2395
2404
  pickRandomKey,
2396
2405
  mapRandomKey,
2397
- fromObjectString
2406
+ fromObjectString,
2407
+ toQueryString
2398
2408
  }
2399
2409
 
2400
2410
  exports.Pagination = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "9.4.0",
3
+ "version": "9.5.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {