Skip to content

Commit

Permalink
fix: allow passing numbers as path template parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster committed Mar 24, 2020
1 parent 836e81b commit 0d931e7
Show file tree
Hide file tree
Showing 2 changed files with 12 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
10 changes: 10 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,16 @@ 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 0d931e7

Please sign in to comment.