Skip to content

Commit

Permalink
fix: not handing falsy values in template data
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanaubrey committed Jul 13, 2024
1 parent 16dfee5 commit fbb412d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 77 deletions.
68 changes: 34 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@
"lodash-es": "<5"
},
"devDependencies": {
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.8",
"@babel/eslint-parser": "^7.21.8",
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.22.15",
"@babel/plugin-proposal-decorators": "^7.23.3",
"@babel/plugin-syntax-import-assertions": "^7.20.0",
"@babel/plugin-syntax-import-assertions": "^7.22.5",
"@babel/plugin-transform-class-properties": "^7.23.3",
"@babel/plugin-transform-export-namespace-from": "^7.23.4",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@babel/runtime": "^7.21.5",
"@babel/plugin-transform-runtime": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.2",
"@babel/runtime": "^7.23.2",
"@cachemap/core": "^5.0.8",
"@cachemap/map": "^5.0.6",
"@commitlint/cli": "^17.6.3",
"@commitlint/config-conventional": "^17.6.3",
"@commitlint/prompt-cli": "^17.6.3",
"@jest/globals": "^29.5.0",
"@commitlint/cli": "^17.7.2",
"@commitlint/config-conventional": "^17.7.0",
"@commitlint/prompt-cli": "^17.7.2",
"@jest/globals": "^29.7.0",
"@repodog/babel-config": "^1.1.11",
"@repodog/cli": "^1.4.1",
"@repodog/commitlint-config": "^1.1.6",
Expand All @@ -83,31 +83,31 @@
"@repodog/rollup-config": "^1.1.8",
"@repodog/syncpack-config": "^1.2.3",
"@repodog/ts-config": "^1.3.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-image": "^3.0.2",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-terser": "^0.4.1",
"@types/jest": "^25.1.3",
"@rollup/plugin-image": "^3.0.3",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/jest": "^25.2.3",
"@types/lodash-es": "^4.17.9",
"@types/node": "^20.11.0",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"babel-jest": "^29.5.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"babel-jest": "^29.7.0",
"babel-plugin-codegen": "^4.1.5",
"babel-plugin-macros": "^3.1.0",
"core-js": "^3.27.2",
"core-js": "^3.33.0",
"cts-types": "^0.0.6",
"del-cli": "^5.1.0",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint": "^8.51.0",
"eslint-config-prettier": "^8.10.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.4.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-sort-class-members": "^1.18.0",
"eslint-plugin-sort-class-members": "^1.19.0",
"eslint-plugin-sort-destructure-keys": "^1.5.0",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-typescript-sort-keys": "^2.3.0",
Expand All @@ -116,22 +116,22 @@
"generate-changelog": "^1.8.0",
"husky": "^8.0.3",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.5.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-environment-node": "^29.7.0",
"jest-mock": "^29.7.0",
"lodash-es": "^4.17.21",
"markdownlint-cli": "^0.34.0",
"node-fetch": "^3.3.2",
"prettier": "^2.8.8",
"rollup": "^3.21.6",
"rollup": "^3.29.4",
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"suppress-experimental-warnings": "^1.1.17",
"syncpack": "^12.3.0",
"type-fest": "^3.10.0",
"typescript": "^5.0.3",
"type-fest": "^3.13.1",
"typescript": "^5.2.2",
"zod": "^3.22.4"
},
"keywords": [
Expand Down
80 changes: 40 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/helpers/defaultPathTemplateCallback/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ describe('defaultPathTemplateCallback', () => {
'/direct/rest/content/catalog/product/136-7317?format=standard'
);
});

it('SHOULD populate the path template correctly when the data value is a zero', () => {
expect(
defaultPathTemplateCallback(defaultPath, { ...defaultPathTemplateData, 'id,+': 0 }, DEFAULT_PATH_TEMPLATE_REGEX)
).toBe('/direct/rest/content/catalog/product/0?format=standard');
});
});
6 changes: 3 additions & 3 deletions src/helpers/defaultPathTemplateCallback/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export const defaultPathTemplateCallback = (
pathTemplate: string,
data: Record<string, string>,
data: Record<string, string | number | boolean>,
pathTemplateRegExp: RegExp
) => {
const dataKeys = Object.keys(data);

return pathTemplate.replace(pathTemplateRegExp, match => {
for (const key of dataKeys) {
if (match.includes(key) && data[key]) {
return data[key]!;
if (match.includes(key) && data[key] !== undefined) {
return String(data[key]);
}
}

Expand Down

0 comments on commit fbb412d

Please sign in to comment.