@scalar/oas-utils 0.2.74 → 0.2.75

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/oas-utils
2
2
 
3
+ ## 0.2.75
4
+
5
+ ### Patch Changes
6
+
7
+ - 49ccdee: refactor: updates regexHelpers
8
+
3
9
  ## 0.2.74
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"findVariables.d.ts","sourceRoot":"","sources":["../../src/helpers/findVariables.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,aAO1C,CAAA"}
1
+ {"version":3,"file":"findVariables.d.ts","sourceRoot":"","sources":["../../src/helpers/findVariables.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,aAM1C,CAAA"}
@@ -1,12 +1,10 @@
1
+ import { REGEX } from './regexHelpers.js';
2
+
1
3
  /**
2
4
  * Find all strings wrapped in {} or {{}} in value.
3
5
  */
4
6
  const findVariables = (value) => {
5
- // Wrapped in single or double curly braces.
6
- // Ignores whitespace
7
- // Works with lowercase, uppercase, numbers, dashes, underscores
8
- const regex = /(?:\{+)\s*(\w+)\s*(?:\}+)/g;
9
- return [...value.matchAll(regex)].map((match) => match[1]?.trim()) || [];
7
+ return ([...value.matchAll(REGEX.PATH), ...value.matchAll(REGEX.VARIABLES)].map((match) => match[1]?.trim()) || []);
10
8
  };
11
9
 
12
10
  export { findVariables };
@@ -16,7 +16,7 @@ export { getObjectKeys, objectMerge } from './object.js';
16
16
  export { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse.js';
17
17
  export { prettyPrintJson, replaceCircularDependencies } from './prettyPrintJson.js';
18
18
  export { isRelativePath, redirectToProxy, shouldUseProxy } from './redirectToProxy.js';
19
- export { pathRegex, variableRegex } from './regexHelpers.js';
19
+ export { REGEX } from './regexHelpers.js';
20
20
  export { replaceVariables } from './replaceVariables.js';
21
21
  export { schemaModel } from './schema-model.js';
22
22
  export { defaultStateFactory, ssrState } from './ssrState.js';
@@ -1,3 +1,5 @@
1
- export declare const variableRegex: RegExp;
2
- export declare const pathRegex: RegExp;
1
+ export declare const REGEX: {
2
+ readonly VARIABLES: RegExp;
3
+ readonly PATH: RegExp;
4
+ };
3
5
  //# sourceMappingURL=regexHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regexHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/regexHelpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAA+B,CAAA;AACzD,eAAO,MAAM,SAAS,QAAyB,CAAA"}
1
+ {"version":3,"file":"regexHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/regexHelpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;CAGR,CAAA"}
@@ -1,4 +1,6 @@
1
- const variableRegex = /{{((?:[^{}]|{[^{}]*})*)}}/g;
2
- const pathRegex = /(?:{)([^{}]+)}(?!})/g;
1
+ const REGEX = {
2
+ VARIABLES: /{{((?:[^{}]|{[^{}]*})*)}}/g,
3
+ PATH: /(?:{)([^{}]+)}(?!})/g,
4
+ };
3
5
 
4
- export { pathRegex, variableRegex };
6
+ export { REGEX };
@@ -1 +1 @@
1
- {"version":3,"file":"getRequestFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAK7B,eAAO,MAAM,uBAAuB,cACvB,oBAAoB,YACrB;IACR;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,uBACoB,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,kBAAkB,CA4D5B,CAAA"}
1
+ {"version":3,"file":"getRequestFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAM7B,eAAO,MAAM,uBAAuB,cACvB,oBAAoB,YACrB;IACR;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,uBACoB,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,kBAAkB,CA4D5B,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import { getParametersFromOperation } from './getParametersFromOperation.js';
2
2
  import { getRequestBodyFromOperation } from './getRequestBodyFromOperation.js';
3
+ import { REGEX } from '../helpers/regexHelpers.js';
3
4
 
4
5
  const getRequestFromOperation = (operation, options, selectedExampleKey) => {
5
6
  // Replace all variables of the format {something} with the uppercase variable name without the brackets
@@ -7,7 +8,7 @@ const getRequestFromOperation = (operation, options, selectedExampleKey) => {
7
8
  // {id} -> 123
8
9
  const pathParameters = getParametersFromOperation(operation, 'path', false);
9
10
  if (pathParameters.length) {
10
- const pathVariables = path.match(/{(.*?)}/g);
11
+ const pathVariables = path.match(REGEX.PATH);
11
12
  if (pathVariables) {
12
13
  pathVariables.forEach((variable) => {
13
14
  const variableName = variable.replace(/{|}/g, '');
@@ -22,7 +23,7 @@ const getRequestFromOperation = (operation, options, selectedExampleKey) => {
22
23
  }
23
24
  // {id} -> __ID__
24
25
  if (options?.replaceVariables === true) {
25
- const pathVariables = path.match(/{(.*?)}/g);
26
+ const pathVariables = path.match(REGEX.PATH);
26
27
  if (pathVariables) {
27
28
  pathVariables.forEach((variable) => {
28
29
  const variableName = variable.replace(/{|}/g, '');
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.2.74",
19
+ "version": "0.2.75",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -116,9 +116,9 @@
116
116
  "vite": "^5.4.9",
117
117
  "vitest": "^1.6.0",
118
118
  "zod-to-ts": "^1.2.0",
119
+ "@scalar/openapi-types": "0.1.5",
119
120
  "@scalar/openapi-parser": "0.8.9",
120
- "@scalar/build-tooling": "0.1.12",
121
- "@scalar/openapi-types": "0.1.5"
121
+ "@scalar/build-tooling": "0.1.12"
122
122
  },
123
123
  "scripts": {
124
124
  "build": "scalar-build-rollup",