mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add TupleKey method to convert string key back to tuple
This commit is contained in:
@@ -16,4 +16,9 @@ export class TupleKey<T extends any[]> {
|
||||
valueOf(): string {
|
||||
return this.strKey;
|
||||
}
|
||||
|
||||
static fromExistingStringKey(strKey: string) {
|
||||
const tuple = strKey.split(separator);
|
||||
return new TupleKey(...tuple);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,18 @@ describe("TupleKey", () => {
|
||||
expect(sampleObject[tupleKey1.toString()]).toEqual("value1");
|
||||
expect(sampleObject[(new TupleKey("1", "2")).toString()]).toEqual("value1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("fromExistingStringKey", () => {
|
||||
it("creates a new TupleKey from an existing string key", () => {
|
||||
const strKey = "hello|there";
|
||||
const tupleKey = TupleKey.fromExistingStringKey(strKey);
|
||||
expect(tupleKey.toString()).toEqual(strKey);
|
||||
});
|
||||
|
||||
it("creates an empty tuple if there is no string", () => {
|
||||
const strKey = "";
|
||||
const tupleKey = TupleKey.fromExistingStringKey(strKey);
|
||||
expect(tupleKey.toString()).toEqual(strKey);
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user