UNPKG

simplehtm

Version:
24 lines (17 loc) 478 B
const CyclicEncoder = require('./cyclicScalar') class CategoryEncoder extends CyclicEncoder { constructor(opts) { super({ w: opts.w, n: opts.categories.length * opts.w, min: 0, max: opts.categories.length, }) this.categories = opts.categories } encode(value) { let index = this.categories.indexOf(value) return super.encode(index) } } module.exports = CategoryEncoder