@wordpress/token-list
Advanced tools
Comparing version 1.15.3 to 2.0.0
@@ -1,5 +0,1 @@ | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
/** | ||
@@ -15,3 +11,3 @@ * External dependencies | ||
var TokenList = /*#__PURE__*/function () { | ||
export default class TokenList { | ||
/** | ||
@@ -22,7 +18,3 @@ * Constructs a new instance of TokenList. | ||
*/ | ||
function TokenList() { | ||
var initialValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
_classCallCheck(this, TokenList); | ||
constructor(initialValue = '') { | ||
this.value = initialValue; // Disable reason: These are type hints on the class. | ||
@@ -45,262 +37,211 @@ | ||
_createClass(TokenList, [{ | ||
key: "entries", | ||
value: function entries() { | ||
var _this$_valueAsArray; | ||
entries(...args) { | ||
return this._valueAsArray.entries(...args); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['forEach']>} args | ||
*/ | ||
return (_this$_valueAsArray = this._valueAsArray).entries.apply(_this$_valueAsArray, arguments); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['forEach']>} args | ||
*/ | ||
}, { | ||
key: "forEach", | ||
value: function forEach() { | ||
var _this$_valueAsArray2; | ||
forEach(...args) { | ||
return this._valueAsArray.forEach(...args); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['keys']>} args | ||
*/ | ||
return (_this$_valueAsArray2 = this._valueAsArray).forEach.apply(_this$_valueAsArray2, arguments); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['keys']>} args | ||
*/ | ||
}, { | ||
key: "keys", | ||
value: function keys() { | ||
var _this$_valueAsArray3; | ||
keys(...args) { | ||
return this._valueAsArray.keys(...args); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['values']>} args | ||
*/ | ||
return (_this$_valueAsArray3 = this._valueAsArray).keys.apply(_this$_valueAsArray3, arguments); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['values']>} args | ||
*/ | ||
}, { | ||
key: "values", | ||
value: function values() { | ||
var _this$_valueAsArray4; | ||
values(...args) { | ||
return this._valueAsArray.values(...args); | ||
} | ||
/** | ||
* Returns the associated set as string. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
return (_this$_valueAsArray4 = this._valueAsArray).values.apply(_this$_valueAsArray4, arguments); | ||
} | ||
/** | ||
* Returns the associated set as string. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
}, { | ||
key: "value", | ||
get: function get() { | ||
return this._currentValue; | ||
} | ||
/** | ||
* Replaces the associated set with a new string value. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value | ||
* | ||
* @param {string} value New token set as string. | ||
*/ | ||
, | ||
set: function set(value) { | ||
value = String(value); | ||
this._valueAsArray = uniq(compact(value.split(/\s+/g))); | ||
this._currentValue = this._valueAsArray.join(' '); | ||
} | ||
/** | ||
* Returns the number of tokens. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-length | ||
* | ||
* @return {number} Number of tokens. | ||
*/ | ||
get value() { | ||
return this._currentValue; | ||
} | ||
/** | ||
* Replaces the associated set with a new string value. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value | ||
* | ||
* @param {string} value New token set as string. | ||
*/ | ||
}, { | ||
key: "length", | ||
get: function get() { | ||
return this._valueAsArray.length; | ||
} | ||
/** | ||
* Returns the stringified form of the TokenList. | ||
* | ||
* @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior | ||
* @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
return this.value; | ||
} | ||
/** | ||
* Returns an iterator for the TokenList, iterating items of the set. | ||
* | ||
* @see https://dom.spec.whatwg.org/#domtokenlist | ||
* | ||
* @return {IterableIterator<string>} TokenList iterator. | ||
*/ | ||
set value(value) { | ||
value = String(value); | ||
this._valueAsArray = uniq(compact(value.split(/\s+/g))); | ||
this._currentValue = this._valueAsArray.join(' '); | ||
} | ||
/** | ||
* Returns the number of tokens. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-length | ||
* | ||
* @return {number} Number of tokens. | ||
*/ | ||
}, { | ||
key: Symbol.iterator, | ||
value: | ||
/*#__PURE__*/ | ||
_regeneratorRuntime.mark(function value() { | ||
return _regeneratorRuntime.wrap(function value$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.delegateYield(this._valueAsArray, "t0", 1); | ||
case 1: | ||
return _context.abrupt("return", _context.t0); | ||
get length() { | ||
return this._valueAsArray.length; | ||
} | ||
/** | ||
* Returns the stringified form of the TokenList. | ||
* | ||
* @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior | ||
* @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, value, this); | ||
}) | ||
/** | ||
* Returns the token with index `index`. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-item | ||
* | ||
* @param {number} index Index at which to return token. | ||
* | ||
* @return {string|undefined} Token at index. | ||
*/ | ||
}, { | ||
key: "item", | ||
value: function item(index) { | ||
return this._valueAsArray[index]; | ||
} | ||
/** | ||
* Returns true if `token` is present, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains | ||
* | ||
* @param {string} item Token to test. | ||
* | ||
* @return {boolean} Whether token is present. | ||
*/ | ||
toString() { | ||
return this.value; | ||
} | ||
/** | ||
* Returns an iterator for the TokenList, iterating items of the set. | ||
* | ||
* @see https://dom.spec.whatwg.org/#domtokenlist | ||
* | ||
* @return {IterableIterator<string>} TokenList iterator. | ||
*/ | ||
}, { | ||
key: "contains", | ||
value: function contains(item) { | ||
return this._valueAsArray.indexOf(item) !== -1; | ||
} | ||
/** | ||
* Adds all arguments passed, except those already present. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-add | ||
* | ||
* @param {...string} items Items to add. | ||
*/ | ||
}, { | ||
key: "add", | ||
value: function add() { | ||
for (var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++) { | ||
items[_key] = arguments[_key]; | ||
} | ||
*[Symbol.iterator]() { | ||
return yield* this._valueAsArray; | ||
} | ||
/** | ||
* Returns the token with index `index`. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-item | ||
* | ||
* @param {number} index Index at which to return token. | ||
* | ||
* @return {string|undefined} Token at index. | ||
*/ | ||
this.value += ' ' + items.join(' '); | ||
} | ||
/** | ||
* Removes arguments passed, if they are present. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove | ||
* | ||
* @param {...string} items Items to remove. | ||
*/ | ||
}, { | ||
key: "remove", | ||
value: function remove() { | ||
for (var _len2 = arguments.length, items = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
items[_key2] = arguments[_key2]; | ||
} | ||
item(index) { | ||
return this._valueAsArray[index]; | ||
} | ||
/** | ||
* Returns true if `token` is present, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains | ||
* | ||
* @param {string} item Token to test. | ||
* | ||
* @return {boolean} Whether token is present. | ||
*/ | ||
this.value = without.apply(void 0, [this._valueAsArray].concat(items)).join(' '); | ||
} | ||
/** | ||
* If `force` is not given, "toggles" `token`, removing it if it’s present | ||
* and adding it if it’s not present. If `force` is true, adds token (same | ||
* as add()). If force is false, removes token (same as remove()). Returns | ||
* true if `token` is now present, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle | ||
* | ||
* @param {string} token Token to toggle. | ||
* @param {boolean} [force] Presence to force. | ||
* | ||
* @return {boolean} Whether token is present after toggle. | ||
*/ | ||
}, { | ||
key: "toggle", | ||
value: function toggle(token, force) { | ||
if (undefined === force) { | ||
force = !this.contains(token); | ||
} | ||
contains(item) { | ||
return this._valueAsArray.indexOf(item) !== -1; | ||
} | ||
/** | ||
* Adds all arguments passed, except those already present. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-add | ||
* | ||
* @param {...string} items Items to add. | ||
*/ | ||
if (force) { | ||
this.add(token); | ||
} else { | ||
this.remove(token); | ||
} | ||
return force; | ||
add(...items) { | ||
this.value += ' ' + items.join(' '); | ||
} | ||
/** | ||
* Removes arguments passed, if they are present. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove | ||
* | ||
* @param {...string} items Items to remove. | ||
*/ | ||
remove(...items) { | ||
this.value = without(this._valueAsArray, ...items).join(' '); | ||
} | ||
/** | ||
* If `force` is not given, "toggles" `token`, removing it if it’s present | ||
* and adding it if it’s not present. If `force` is true, adds token (same | ||
* as add()). If force is false, removes token (same as remove()). Returns | ||
* true if `token` is now present, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle | ||
* | ||
* @param {string} token Token to toggle. | ||
* @param {boolean} [force] Presence to force. | ||
* | ||
* @return {boolean} Whether token is present after toggle. | ||
*/ | ||
toggle(token, force) { | ||
if (undefined === force) { | ||
force = !this.contains(token); | ||
} | ||
/** | ||
* Replaces `token` with `newToken`. Returns true if `token` was replaced | ||
* with `newToken`, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace | ||
* | ||
* @param {string} token Token to replace with `newToken`. | ||
* @param {string} newToken Token to use in place of `token`. | ||
* | ||
* @return {boolean} Whether replacement occurred. | ||
*/ | ||
}, { | ||
key: "replace", | ||
value: function replace(token, newToken) { | ||
if (!this.contains(token)) { | ||
return false; | ||
} | ||
if (force) { | ||
this.add(token); | ||
} else { | ||
this.remove(token); | ||
this.add(newToken); | ||
return true; | ||
} | ||
/** | ||
* Returns true if `token` is in the associated attribute’s supported | ||
* tokens. Returns false otherwise. | ||
* | ||
* Always returns `true` in this implementation. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports | ||
* | ||
* @return {boolean} Whether token is supported. | ||
*/ | ||
}, { | ||
key: "supports", | ||
value: function supports() { | ||
return true; | ||
return force; | ||
} | ||
/** | ||
* Replaces `token` with `newToken`. Returns true if `token` was replaced | ||
* with `newToken`, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace | ||
* | ||
* @param {string} token Token to replace with `newToken`. | ||
* @param {string} newToken Token to use in place of `token`. | ||
* | ||
* @return {boolean} Whether replacement occurred. | ||
*/ | ||
replace(token, newToken) { | ||
if (!this.contains(token)) { | ||
return false; | ||
} | ||
}]); | ||
return TokenList; | ||
}(); | ||
this.remove(token); | ||
this.add(newToken); | ||
return true; | ||
} | ||
/** | ||
* Returns true if `token` is in the associated attribute’s supported | ||
* tokens. Returns false otherwise. | ||
* | ||
* Always returns `true` in this implementation. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports | ||
* | ||
* @return {boolean} Whether token is supported. | ||
*/ | ||
export { TokenList as default }; | ||
supports() { | ||
return true; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,8 +8,2 @@ value: true | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _lodash = require("lodash"); | ||
@@ -28,3 +20,3 @@ | ||
*/ | ||
var TokenList = /*#__PURE__*/function () { | ||
class TokenList { | ||
/** | ||
@@ -35,5 +27,3 @@ * Constructs a new instance of TokenList. | ||
*/ | ||
function TokenList() { | ||
var initialValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
(0, _classCallCheck2.default)(this, TokenList); | ||
constructor(initialValue = '') { | ||
this.value = initialValue; // Disable reason: These are type hints on the class. | ||
@@ -56,261 +46,213 @@ | ||
(0, _createClass2.default)(TokenList, [{ | ||
key: "entries", | ||
value: function entries() { | ||
var _this$_valueAsArray; | ||
entries(...args) { | ||
return this._valueAsArray.entries(...args); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['forEach']>} args | ||
*/ | ||
return (_this$_valueAsArray = this._valueAsArray).entries.apply(_this$_valueAsArray, arguments); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['forEach']>} args | ||
*/ | ||
}, { | ||
key: "forEach", | ||
value: function forEach() { | ||
var _this$_valueAsArray2; | ||
forEach(...args) { | ||
return this._valueAsArray.forEach(...args); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['keys']>} args | ||
*/ | ||
return (_this$_valueAsArray2 = this._valueAsArray).forEach.apply(_this$_valueAsArray2, arguments); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['keys']>} args | ||
*/ | ||
}, { | ||
key: "keys", | ||
value: function keys() { | ||
var _this$_valueAsArray3; | ||
keys(...args) { | ||
return this._valueAsArray.keys(...args); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['values']>} args | ||
*/ | ||
return (_this$_valueAsArray3 = this._valueAsArray).keys.apply(_this$_valueAsArray3, arguments); | ||
} | ||
/** | ||
* @param {Parameters<Array<string>['values']>} args | ||
*/ | ||
}, { | ||
key: "values", | ||
value: function values() { | ||
var _this$_valueAsArray4; | ||
values(...args) { | ||
return this._valueAsArray.values(...args); | ||
} | ||
/** | ||
* Returns the associated set as string. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
return (_this$_valueAsArray4 = this._valueAsArray).values.apply(_this$_valueAsArray4, arguments); | ||
} | ||
/** | ||
* Returns the associated set as string. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
}, { | ||
key: "value", | ||
get: function get() { | ||
return this._currentValue; | ||
} | ||
/** | ||
* Replaces the associated set with a new string value. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value | ||
* | ||
* @param {string} value New token set as string. | ||
*/ | ||
, | ||
set: function set(value) { | ||
value = String(value); | ||
this._valueAsArray = (0, _lodash.uniq)((0, _lodash.compact)(value.split(/\s+/g))); | ||
this._currentValue = this._valueAsArray.join(' '); | ||
} | ||
/** | ||
* Returns the number of tokens. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-length | ||
* | ||
* @return {number} Number of tokens. | ||
*/ | ||
get value() { | ||
return this._currentValue; | ||
} | ||
/** | ||
* Replaces the associated set with a new string value. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value | ||
* | ||
* @param {string} value New token set as string. | ||
*/ | ||
}, { | ||
key: "length", | ||
get: function get() { | ||
return this._valueAsArray.length; | ||
} | ||
/** | ||
* Returns the stringified form of the TokenList. | ||
* | ||
* @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior | ||
* @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
}, { | ||
key: "toString", | ||
value: function toString() { | ||
return this.value; | ||
} | ||
/** | ||
* Returns an iterator for the TokenList, iterating items of the set. | ||
* | ||
* @see https://dom.spec.whatwg.org/#domtokenlist | ||
* | ||
* @return {IterableIterator<string>} TokenList iterator. | ||
*/ | ||
set value(value) { | ||
value = String(value); | ||
this._valueAsArray = (0, _lodash.uniq)((0, _lodash.compact)(value.split(/\s+/g))); | ||
this._currentValue = this._valueAsArray.join(' '); | ||
} | ||
/** | ||
* Returns the number of tokens. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-length | ||
* | ||
* @return {number} Number of tokens. | ||
*/ | ||
}, { | ||
key: Symbol.iterator, | ||
value: | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function value() { | ||
return _regenerator.default.wrap(function value$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.delegateYield(this._valueAsArray, "t0", 1); | ||
case 1: | ||
return _context.abrupt("return", _context.t0); | ||
get length() { | ||
return this._valueAsArray.length; | ||
} | ||
/** | ||
* Returns the stringified form of the TokenList. | ||
* | ||
* @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior | ||
* @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, value, this); | ||
}) | ||
/** | ||
* Returns the token with index `index`. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-item | ||
* | ||
* @param {number} index Index at which to return token. | ||
* | ||
* @return {string|undefined} Token at index. | ||
*/ | ||
}, { | ||
key: "item", | ||
value: function item(index) { | ||
return this._valueAsArray[index]; | ||
} | ||
/** | ||
* Returns true if `token` is present, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains | ||
* | ||
* @param {string} item Token to test. | ||
* | ||
* @return {boolean} Whether token is present. | ||
*/ | ||
toString() { | ||
return this.value; | ||
} | ||
/** | ||
* Returns an iterator for the TokenList, iterating items of the set. | ||
* | ||
* @see https://dom.spec.whatwg.org/#domtokenlist | ||
* | ||
* @return {IterableIterator<string>} TokenList iterator. | ||
*/ | ||
}, { | ||
key: "contains", | ||
value: function contains(item) { | ||
return this._valueAsArray.indexOf(item) !== -1; | ||
} | ||
/** | ||
* Adds all arguments passed, except those already present. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-add | ||
* | ||
* @param {...string} items Items to add. | ||
*/ | ||
}, { | ||
key: "add", | ||
value: function add() { | ||
for (var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++) { | ||
items[_key] = arguments[_key]; | ||
} | ||
*[Symbol.iterator]() { | ||
return yield* this._valueAsArray; | ||
} | ||
/** | ||
* Returns the token with index `index`. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-item | ||
* | ||
* @param {number} index Index at which to return token. | ||
* | ||
* @return {string|undefined} Token at index. | ||
*/ | ||
this.value += ' ' + items.join(' '); | ||
} | ||
/** | ||
* Removes arguments passed, if they are present. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove | ||
* | ||
* @param {...string} items Items to remove. | ||
*/ | ||
}, { | ||
key: "remove", | ||
value: function remove() { | ||
for (var _len2 = arguments.length, items = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
items[_key2] = arguments[_key2]; | ||
} | ||
item(index) { | ||
return this._valueAsArray[index]; | ||
} | ||
/** | ||
* Returns true if `token` is present, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains | ||
* | ||
* @param {string} item Token to test. | ||
* | ||
* @return {boolean} Whether token is present. | ||
*/ | ||
this.value = _lodash.without.apply(void 0, [this._valueAsArray].concat(items)).join(' '); | ||
} | ||
/** | ||
* If `force` is not given, "toggles" `token`, removing it if it’s present | ||
* and adding it if it’s not present. If `force` is true, adds token (same | ||
* as add()). If force is false, removes token (same as remove()). Returns | ||
* true if `token` is now present, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle | ||
* | ||
* @param {string} token Token to toggle. | ||
* @param {boolean} [force] Presence to force. | ||
* | ||
* @return {boolean} Whether token is present after toggle. | ||
*/ | ||
}, { | ||
key: "toggle", | ||
value: function toggle(token, force) { | ||
if (undefined === force) { | ||
force = !this.contains(token); | ||
} | ||
contains(item) { | ||
return this._valueAsArray.indexOf(item) !== -1; | ||
} | ||
/** | ||
* Adds all arguments passed, except those already present. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-add | ||
* | ||
* @param {...string} items Items to add. | ||
*/ | ||
if (force) { | ||
this.add(token); | ||
} else { | ||
this.remove(token); | ||
} | ||
return force; | ||
add(...items) { | ||
this.value += ' ' + items.join(' '); | ||
} | ||
/** | ||
* Removes arguments passed, if they are present. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove | ||
* | ||
* @param {...string} items Items to remove. | ||
*/ | ||
remove(...items) { | ||
this.value = (0, _lodash.without)(this._valueAsArray, ...items).join(' '); | ||
} | ||
/** | ||
* If `force` is not given, "toggles" `token`, removing it if it’s present | ||
* and adding it if it’s not present. If `force` is true, adds token (same | ||
* as add()). If force is false, removes token (same as remove()). Returns | ||
* true if `token` is now present, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle | ||
* | ||
* @param {string} token Token to toggle. | ||
* @param {boolean} [force] Presence to force. | ||
* | ||
* @return {boolean} Whether token is present after toggle. | ||
*/ | ||
toggle(token, force) { | ||
if (undefined === force) { | ||
force = !this.contains(token); | ||
} | ||
/** | ||
* Replaces `token` with `newToken`. Returns true if `token` was replaced | ||
* with `newToken`, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace | ||
* | ||
* @param {string} token Token to replace with `newToken`. | ||
* @param {string} newToken Token to use in place of `token`. | ||
* | ||
* @return {boolean} Whether replacement occurred. | ||
*/ | ||
}, { | ||
key: "replace", | ||
value: function replace(token, newToken) { | ||
if (!this.contains(token)) { | ||
return false; | ||
} | ||
if (force) { | ||
this.add(token); | ||
} else { | ||
this.remove(token); | ||
this.add(newToken); | ||
return true; | ||
} | ||
/** | ||
* Returns true if `token` is in the associated attribute’s supported | ||
* tokens. Returns false otherwise. | ||
* | ||
* Always returns `true` in this implementation. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports | ||
* | ||
* @return {boolean} Whether token is supported. | ||
*/ | ||
}, { | ||
key: "supports", | ||
value: function supports() { | ||
return true; | ||
return force; | ||
} | ||
/** | ||
* Replaces `token` with `newToken`. Returns true if `token` was replaced | ||
* with `newToken`, and false otherwise. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace | ||
* | ||
* @param {string} token Token to replace with `newToken`. | ||
* @param {string} newToken Token to use in place of `token`. | ||
* | ||
* @return {boolean} Whether replacement occurred. | ||
*/ | ||
replace(token, newToken) { | ||
if (!this.contains(token)) { | ||
return false; | ||
} | ||
}]); | ||
return TokenList; | ||
}(); | ||
this.remove(token); | ||
this.add(newToken); | ||
return true; | ||
} | ||
/** | ||
* Returns true if `token` is in the associated attribute’s supported | ||
* tokens. Returns false otherwise. | ||
* | ||
* Always returns `true` in this implementation. | ||
* | ||
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports | ||
* | ||
* @return {boolean} Whether token is supported. | ||
*/ | ||
supports() { | ||
return true; | ||
} | ||
} | ||
exports.default = TokenList; | ||
//# sourceMappingURL=index.js.map |
@@ -5,2 +5,9 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. --> | ||
## 2.0.0 (2021-05-14) | ||
### Breaking Changes | ||
- Drop support for Internet Explorer 11 ([#31110](https://github.com/WordPress/gutenberg/pull/31110)). Learn more at https://make.wordpress.org/core/2021/04/22/ie-11-support-phase-out-plan/. | ||
- Increase the minimum Node.js version to v12 matching Long Term Support releases ([#31270](https://github.com/WordPress/gutenberg/pull/31270)). Learn more at https://nodejs.org/en/about/releases/. | ||
## 1.15.0 (2021-03-17) | ||
@@ -7,0 +14,0 @@ |
{ | ||
"name": "@wordpress/token-list", | ||
"version": "1.15.3", | ||
"version": "2.0.0", | ||
"description": "Constructable, plain JavaScript DOMTokenList implementation, supporting non-browser runtimes.", | ||
@@ -21,2 +21,5 @@ "author": "The WordPress Contributors", | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"main": "build/index.js", | ||
@@ -28,3 +31,3 @@ "module": "build-module/index.js", | ||
"@babel/runtime": "^7.13.10", | ||
"lodash": "^4.17.19" | ||
"lodash": "^4.17.21" | ||
}, | ||
@@ -34,3 +37,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "4abe97cdbdf5e12bfc95b68c74cd0baa6583fc65" | ||
"gitHead": "0c80fbada8b86cd8e4b4892460caa3a5d0e5f583" | ||
} |
@@ -13,3 +13,3 @@ # Token List | ||
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. Learn more about it in [Babel docs](https://babeljs.io/docs/en/next/caveats)._ | ||
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as IE browsers then using [core-js](https://github.com/zloirock/core-js) will add polyfills for these methods._ | ||
@@ -16,0 +16,0 @@ ## Usage |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
132127
985
Updatedlodash@^4.17.21