All files / src Filter.js

100% Statements 4/4
100% Branches 4/4
100% Functions 2/2
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28                        144x 1x     143x               1x      
/**
 * @copyright   2016, Miles Johnson
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */
 
import { ATTRIBUTES } from './constants';
 
export default class Filter {
  attribute: string;
 
  constructor(attribute: string) {
    if (!attribute || !ATTRIBUTES[attribute]) {
      throw new Error(`Attribute "${attribute}" is not supported.`);
    }
 
    this.attribute = attribute;
  }
 
  /**
   * Filter and clean an attribute value if applicable.
   * Can return an empty value to omit the attribute.
   */
  filter(value: string): string {
    throw new Error(`${this.constructor.name} must define a filter.`);
  }
}