Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: align naming with OpenAPI nomenclature #16

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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