lib/polyfills/dom-token-list.js
function Polyfill(object, key) {
  nodsl.check(typeof object === 'object', 'object must be an object; got ', object);
  nodsl.check(typeof key === 'string', 'key must be a string; got ', key);
  nodsl.check(typeof object[key] === 'string', 'object.', key, ' must be a string; got ', object[key]);

  var that = this;

  that.add = function() {
    var tokens = [].slice.apply(arguments);
    tokens.forEach(function(token, i) {
      nodsl.check(typeof token === 'string', 'tokens[', i, '] must be a string; got ', token);
    });
    object[key] += (object[key].length ?' ' :'') + tokens.join(' ');
  };
  that.remove = function(token) {
    nodsl.check(typeof token === 'string', 'token must be a string; got ', token);
    object[key] = object[key].replace(new RegExp('\\b'+ token +'\\b\\s*'), '').replace(/^\\s*/, '');
  };
  that.contains = function(token) {
    nodsl.check(typeof token === 'string', 'token must be a string; got ', token);
    return object[key].search(new RegExp('\\b'+ token +'\\b')) !== -1;
  };
  Object.defineProperty(that, 'length', {
    get: function() {
      return (object[key].match(/[^\s]+/g) || []).length;
    },
  });

  return that;
}
function Polyfill(object, key) {
  nodsl.check(typeof object === 'object', 'object must be an object; got ', object);
  nodsl.check(typeof key === 'string', 'key must be a string; got ', key);
  nodsl.check(typeof object[key] === 'string', 'object.', key, ' must be a string; got ', object[key]);

  var that = this;

  that.add = function() {
    var tokens = [].slice.apply(arguments);
    tokens.forEach(function(token, i) {
      nodsl.check(typeof token === 'string', 'tokens[', i, '] must be a string; got ', token);
    });
    object[key] += (object[key].length ?' ' :'') + tokens.join(' ');
  };
  that.remove = function(token) {
    nodsl.check(typeof token === 'string', 'token must be a string; got ', token);
    object[key] = object[key].replace(new RegExp('\\b'+ token +'\\b\\s*'), '').replace(/^\\s*/, '');
  };
  that.contains = function(token) {
    nodsl.check(typeof token === 'string', 'token must be a string; got ', token);
    return object[key].search(new RegExp('\\b'+ token +'\\b')) !== -1;
  };
  Object.defineProperty(that, 'length', {
    get: function() {
      return (object[key].match(/[^\s]+/g) || []).length;
    },
  });

  return that;
}
function Polyfill ( object , key ) { nodsl . check ( typeof object === 'object' , 'object must be an object; got ' , object ) ; nodsl . check ( typeof key === 'string' , 'key must be a string; got ' , key ) ; nodsl . check ( typeof object [ key ] === 'string' , 'object.' , key , ' must be a string; got ' , object [ key ] ) ; var that = this ; that . add = function ( ) { var tokens = [ ] . slice . apply ( arguments ) ; tokens . forEach ( function ( token , i ) { nodsl . check ( typeof token === 'string' , 'tokens[' , i , '] must be a string; got ' , token ) ; } ) ; object [ key ] += ( object [ key ] . length ? ' ' : '' ) + tokens . join ( ' ' ) ; } ; that . remove = function ( token ) { nodsl . check ( typeof token === 'string' , 'token must be a string; got ' , token ) ; object [ key ] = object [ key ] . replace ( new RegExp ( '\\b' + token + '\\b\\s*' ) , '' ) . replace ( / ^\\s* / , '' ) ; } ; that . contains = function ( token ) { nodsl . check ( typeof token === 'string' , 'token must be a string; got ' , token ) ; return object [ key ] . search ( new RegExp ( '\\b' + token + '\\b' ) ) !== - 1 ; } ; Object . defineProperty ( that , 'length' , { get : function ( ) { return ( object [ key ] . match ( / [^\s]+ / g ) || [ ] ) . length ; } , } ) ; return that ; }
Constructs Polyfill of DOMTokenList.

The list will be represented as a string located in given **object**
under property of name **key**.

@see https://developer.mozilla.org/pl/docs/Web/API/DOMTokenList
Constructs Polyfill of DOMTokenList .