textiletag
v0.1.0
Published
Encode, decode, and validate 14-character TextileTag clothing codes
Maintainers
Readme
TextileTag JavaScript SDK
Encode, decode, and validate 14-character TextileTag clothing codes.
Install
npm install textiletagUsage
const { encode, decode, validate, describe } = require("textiletag");
// Encode a garment
const code = encode({
garmentType: "TP", material: "CO", wash: "N", temp: "C",
dry: "T", color: "W", size: "3", iron: 1, bleach: 2,
dryclean: 0, country: "US",
});
console.log(code); // 01TPCONCTW3AUS
// Decode a code
const result = decode("01TPCONCTW3AUS");
console.log(result.garmentTypeLabel); // Top
console.log(result.materialLabel); // Cotton
// Get human-readable description
console.log(describe("01TPCONCTW3AUS"));
// M white cotton top. Wash: Normal, cold water. Dry: Tumble Dry. ...
// Validate a code
console.log(validate("INVALID")); // ['Must be 14 characters, got 7']
console.log(validate("01TPCONCTW3AUS")); // [] (empty = valid)TypeScript
TypeScript definitions are included (textiletag.d.ts).
API
| Function | Description |
|---|---|
| encode(opts) | Encode garment attributes into a 14-character code |
| decode(code) | Decode a code into an object with fields and labels |
| validate(code) | Return an array of validation errors (empty = valid) |
| describe(code) | Return a human-readable description string |
| encodeFlags(iron, bleach, dryclean) | Pack care flags into one character |
| decodeFlags(char) | Unpack a care flags character |
