cafe-utility 9.4.1 → 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 +10 -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 = ''
@@ -2395,7 +2403,8 @@ exports.Objects = {
2395
2403
  diffKeys,
2396
2404
  pickRandomKey,
2397
2405
  mapRandomKey,
2398
- fromObjectString
2406
+ fromObjectString,
2407
+ toQueryString
2399
2408
  }
2400
2409
 
2401
2410
  exports.Pagination = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "9.4.1",
3
+ "version": "9.5.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {