Skip to content

Commit

Permalink
fix: allow passing numbers as path template parameters (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster authored Mar 25, 2020
1 parent 836e81b commit c466d3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pathTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Segment {
}

export interface Bindings {
[index: string]: string;
[index: string]: string | number;
}

export class PathTemplate {
Expand Down Expand Up @@ -129,7 +129,7 @@ export class PathTemplate {
);
throw new TypeError(msg);
}
const tmp = new PathTemplate(bindings[segment.literal]);
const tmp = new PathTemplate(bindings[segment.literal].toString());
Array.prototype.push.apply(out, tmp.segments);
inABinding = true;
} else if (segment.kind === extras.END_BINDING) {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/path_template.ts → test/unit/pathTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ describe('PathTemplate', () => {
const want = 'bar/1/2/foo/3';
expect(template.render(params)).to.eql(want);
});

it('should accept both strings and numbers as values', () => {
const template = new PathTemplate(
'projects/{project}/sessions/{session}'
);
const params = {
project: 'testProject',
session: 123,
};
const want = 'projects/testProject/sessions/123';
expect(template.render(params)).to.eql(want);
});
});

describe('method `inspect`', () => {
Expand Down

0 comments on commit c466d3d

Please sign in to comment.