@scalar/helpers 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scalar/helpers
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#7489](https://github.com/scalar/scalar/pull/7489) [`21aa62e`](https://github.com/scalar/scalar/commit/21aa62e2ebdd262cb5aa53658c3b659736660722) Thanks [@amritk](https://github.com/amritk)! - feat: added new helpers for building client v2 requests
8
+
3
9
  ## 0.2.0
4
10
 
5
11
  ### Minor Changes
@@ -2,4 +2,8 @@
2
2
  * This function takes a string and replace {variables} with given values.
3
3
  */
4
4
  export declare function replaceVariables(value: string, variablesOrCallback: Record<string, string | number> | ((match: string) => string)): string;
5
+ /** Replace {path} variables with their values */
6
+ export declare const replacePathVariables: (path: string, variables?: Record<string, string>) => string;
7
+ /** Replace {{env}} variables with their values */
8
+ export declare const replaceEnvVariables: (path: string, variables?: Record<string, string>) => string;
5
9
  //# sourceMappingURL=replace-variables.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replace-variables.d.ts","sourceRoot":"","sources":["../../src/regex/replace-variables.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,UAenF"}
1
+ {"version":3,"file":"replace-variables.d.ts","sourceRoot":"","sources":["../../src/regex/replace-variables.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,UAenF;AAED,iDAAiD;AACjD,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,EAAE,YAAW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,WACtB,CAAA;AAEnE,kDAAkD;AAClD,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,EAAE,YAAW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,WAChB,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { REGEX } from "../regex/regex-helpers.js";
1
2
  function replaceVariables(value, variablesOrCallback) {
2
3
  const doubleCurlyBrackets = /{{\s*([\w.-]+)\s*}}/g;
3
4
  const singleCurlyBrackets = /{\s*([\w.-]+)\s*}/g;
@@ -9,7 +10,11 @@ function replaceVariables(value, variablesOrCallback) {
9
10
  };
10
11
  return value.replace(doubleCurlyBrackets, callback).replace(singleCurlyBrackets, callback);
11
12
  }
13
+ const replacePathVariables = (path, variables = {}) => path.replace(REGEX.PATH, (match, key) => variables[key] ?? match);
14
+ const replaceEnvVariables = (path, variables = {}) => path.replace(REGEX.VARIABLES, (match, key) => variables[key] ?? match);
12
15
  export {
16
+ replaceEnvVariables,
17
+ replacePathVariables,
13
18
  replaceVariables
14
19
  };
15
20
  //# sourceMappingURL=replace-variables.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/regex/replace-variables.ts"],
4
- "sourcesContent": ["/**\n * This function takes a string and replace {variables} with given values.\n */\nexport function replaceVariables(\n value: string,\n variablesOrCallback: Record<string, string | number> | ((match: string) => string),\n) {\n // Replace all variables (example: {{ baseurl }} with an HTML tag)\n const doubleCurlyBrackets = /{{\\s*([\\w.-]+)\\s*}}/g\n const singleCurlyBrackets = /{\\s*([\\w.-]+)\\s*}/g\n\n const callback = (_: string, match: string): string => {\n if (typeof variablesOrCallback === 'function') {\n return variablesOrCallback(match)\n }\n return variablesOrCallback[match]?.toString() || `{${match}}`\n }\n\n // Loop through all matches and replace the match with the variable value\n return value.replace(doubleCurlyBrackets, callback).replace(singleCurlyBrackets, callback)\n}\n"],
5
- "mappings": "AAGO,SAAS,iBACd,OACA,qBACA;AAEA,QAAM,sBAAsB;AAC5B,QAAM,sBAAsB;AAE5B,QAAM,WAAW,CAAC,GAAW,UAA0B;AACrD,QAAI,OAAO,wBAAwB,YAAY;AAC7C,aAAO,oBAAoB,KAAK;AAAA,IAClC;AACA,WAAO,oBAAoB,KAAK,GAAG,SAAS,KAAK,IAAI,KAAK;AAAA,EAC5D;AAGA,SAAO,MAAM,QAAQ,qBAAqB,QAAQ,EAAE,QAAQ,qBAAqB,QAAQ;AAC3F;",
4
+ "sourcesContent": ["import { REGEX } from '@/regex/regex-helpers'\n\n/**\n * This function takes a string and replace {variables} with given values.\n */\nexport function replaceVariables(\n value: string,\n variablesOrCallback: Record<string, string | number> | ((match: string) => string),\n) {\n // Replace all variables (example: {{ baseurl }} with an HTML tag)\n const doubleCurlyBrackets = /{{\\s*([\\w.-]+)\\s*}}/g\n const singleCurlyBrackets = /{\\s*([\\w.-]+)\\s*}/g\n\n const callback = (_: string, match: string): string => {\n if (typeof variablesOrCallback === 'function') {\n return variablesOrCallback(match)\n }\n return variablesOrCallback[match]?.toString() || `{${match}}`\n }\n\n // Loop through all matches and replace the match with the variable value\n return value.replace(doubleCurlyBrackets, callback).replace(singleCurlyBrackets, callback)\n}\n\n/** Replace {path} variables with their values */\nexport const replacePathVariables = (path: string, variables: Record<string, string> = {}) =>\n path.replace(REGEX.PATH, (match, key) => variables[key] ?? match)\n\n/** Replace {{env}} variables with their values */\nexport const replaceEnvVariables = (path: string, variables: Record<string, string> = {}) =>\n path.replace(REGEX.VARIABLES, (match, key) => variables[key] ?? match)\n"],
5
+ "mappings": "AAAA,SAAS,aAAa;AAKf,SAAS,iBACd,OACA,qBACA;AAEA,QAAM,sBAAsB;AAC5B,QAAM,sBAAsB;AAE5B,QAAM,WAAW,CAAC,GAAW,UAA0B;AACrD,QAAI,OAAO,wBAAwB,YAAY;AAC7C,aAAO,oBAAoB,KAAK;AAAA,IAClC;AACA,WAAO,oBAAoB,KAAK,GAAG,SAAS,KAAK,IAAI,KAAK;AAAA,EAC5D;AAGA,SAAO,MAAM,QAAQ,qBAAqB,QAAQ,EAAE,QAAQ,qBAAqB,QAAQ;AAC3F;AAGO,MAAM,uBAAuB,CAAC,MAAc,YAAoC,CAAC,MACtF,KAAK,QAAQ,MAAM,MAAM,CAAC,OAAO,QAAQ,UAAU,GAAG,KAAK,KAAK;AAG3D,MAAM,sBAAsB,CAAC,MAAc,YAAoC,CAAC,MACrF,KAAK,QAAQ,MAAM,WAAW,CAAC,OAAO,QAAQ,UAAU,GAAG,KAAK,KAAK;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "helpers",
15
15
  "js"
16
16
  ],
17
- "version": "0.2.0",
17
+ "version": "0.2.1",
18
18
  "engines": {
19
19
  "node": ">=20"
20
20
  },