Skip to content

Commit

Permalink
Merge pull request #259 from prenaissance/sku-overload
Browse files Browse the repository at this point in the history
feat(static): added sku overload to stringify function
  • Loading branch information
danocmx authored Jul 3, 2023
2 parents e1760f1 + 9c79c6e commit 975da3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,20 @@ export class Format {

stringify(
attributes: StrigifySKUAttributes | ItemAttributes,
options: StringifyOptions & { useDefindexes: true }
): string;
stringify(
sku: string,
options: StringifyOptions & { useDefindexes: true }
): string;
stringify(
attributesOrSku: StrigifySKUAttributes | ItemAttributes | string,
options: StringifyOptions = {}
): string {
const attributes =
typeof attributesOrSku === 'string'
? parseSKU(attributesOrSku)
: attributesOrSku;
return stringify(this.schema, attributes, options);
}

Expand Down
18 changes: 16 additions & 2 deletions test/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,13 @@ describe('stringify from defindexes and numbers.', () => {
it('Case #32 - Red Rock Roscoe texture', () => {
const itemString = stringify({ name: 'Pistol', quality: 'Decorated Weapon', craftable: true, wear: 'Field-Tested', festivized: true, killstreak: 'Specialized Killstreak', texture: 0 });

assert.equal(itemString, 'Festivized Specialized Killstreak Red Rock Roscoe Pistol (Field-Tested)');
assert.equal(itemString, 'Festivized Specialized Killstreak Red Rock Roscoe Pistol (Field-Tested)');
});

it('Case #33 - Bat', () => {
const itemString = stringify({ defindex: 0, quality: 'Unique', craftable: true });

assert.equal(itemString, 'Bat');
assert.equal(itemString, 'Bat');
})

it('Case #34 - Bat output', () => {
Expand Down Expand Up @@ -605,3 +605,17 @@ describe('stringify from defindexes and numbers.', () => {
assert.deepEqual(itemString, "Haunted Kraken Rotation Sensation");
});
});

describe("stringify SKU", () => {
it("Case #1", () => {
const itemString = stringify("5050;6");

assert.equal(itemString, "Backpack Expander");
});

it("Case #2", () => {
const itemString = stringify("1071;11;kt-3");

assert.equal(itemString, "Strange Professional Killstreak Golden Frying Pan");
});
})

0 comments on commit 975da3d

Please sign in to comment.