Skip to content

Commit

Permalink
refactor: align naming with OpenAPI nomenclature (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Jun 6, 2024
1 parent d9d51cc commit dc97b9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/substitute.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import parse from './parse/index.js';

const isEncoded = (serverVariable) => {
const isEncoded = (serverVariableValue) => {
try {
return (
typeof serverVariable === 'string' && decodeURIComponent(serverVariable) !== serverVariable
typeof serverVariableValue === 'string' &&
decodeURIComponent(serverVariableValue) !== serverVariableValue
);
} catch {
return false;
}
};

export const encodeServerVariable = (serverVariable) => {
if (isEncoded(serverVariable)) {
return serverVariable;
export const encodeServerVariable = (serverVariableValue) => {
if (isEncoded(serverVariableValue)) {
return serverVariableValue;
}

return encodeURIComponent(serverVariable).replace(/%5B/g, '[').replace(/%5D/g, ']');
return encodeURIComponent(serverVariableValue).replace(/%5B/g, '[').replace(/%5D/g, ']');
};

const significantTypes = ['literals', 'server-variable-name'];
Expand Down
2 changes: 1 addition & 1 deletion src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import parse from './parse/index.js';
/**
* Test if a string is a server URL template.
*
* @param {string} str
* @param {string} serverURLTemplate
* @param {Object} [options={}] - An object.
* @param {boolean} [options.strict=true] - A boolean indicating presence of at least one `Server Variable` AST node.
* @returns {boolean}
Expand Down

0 comments on commit dc97b9e

Please sign in to comment.