@wordpress/token-list
Advanced tools
Comparing version
@@ -48,5 +48,45 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
_createClass(TokenList, [{ | ||
key: "item", | ||
key: "toString", | ||
/** | ||
* Returns the stringified form of the TokenList. | ||
* | ||
* @link https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior | ||
* @link https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
value: function toString() { | ||
return this.value; | ||
} | ||
/** | ||
* Returns an iterator for the TokenList, iterating items of the set. | ||
* | ||
* @link https://dom.spec.whatwg.org/#domtokenlist | ||
* | ||
* @return {Generator} TokenList iterator. | ||
*/ | ||
}, { | ||
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); | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, value, this); | ||
}) | ||
/** | ||
* Returns the token with index `index`. | ||
@@ -60,2 +100,5 @@ * | ||
*/ | ||
}, { | ||
key: "item", | ||
value: function item(index) { | ||
@@ -62,0 +105,0 @@ return this._valueAsArray[index]; |
@@ -57,5 +57,45 @@ "use strict"; | ||
(0, _createClass2.default)(TokenList, [{ | ||
key: "item", | ||
key: "toString", | ||
/** | ||
* Returns the stringified form of the TokenList. | ||
* | ||
* @link https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior | ||
* @link https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
value: function toString() { | ||
return this.value; | ||
} | ||
/** | ||
* Returns an iterator for the TokenList, iterating items of the set. | ||
* | ||
* @link https://dom.spec.whatwg.org/#domtokenlist | ||
* | ||
* @return {Generator} TokenList iterator. | ||
*/ | ||
}, { | ||
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); | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, value, this); | ||
}) | ||
/** | ||
* Returns the token with index `index`. | ||
@@ -69,2 +109,5 @@ * | ||
*/ | ||
}, { | ||
key: "item", | ||
value: function item(index) { | ||
@@ -71,0 +114,0 @@ return this._valueAsArray[index]; |
@@ -0,3 +1,10 @@ | ||
## 1.1.0 (Unreleased) | ||
### Enhancements | ||
- Implements missing stringification behavior (i.e. `toString`), as prescribed in the standard to be the `value` property (the interface's `stringifier`) | ||
- Implements missing iterator behavior | ||
## 1.0.0 (2018-09-05) | ||
- Initial release |
{ | ||
"name": "@wordpress/token-list", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Constructable, plain JavaScript DOMTokenList implementation, supporting non-browser runtimes.", | ||
@@ -27,3 +27,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "0aa5c4340f57a69ab935f9e819d74958aad2e022" | ||
"gitHead": "a1a350839cc7f6e6fb07d03e0b54dd7e9a9bc6cf" | ||
} |
@@ -63,2 +63,25 @@ /** | ||
/** | ||
* Returns the stringified form of the TokenList. | ||
* | ||
* @link https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior | ||
* @link https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring | ||
* | ||
* @return {string} Token set as string. | ||
*/ | ||
toString() { | ||
return this.value; | ||
} | ||
/** | ||
* Returns an iterator for the TokenList, iterating items of the set. | ||
* | ||
* @link https://dom.spec.whatwg.org/#domtokenlist | ||
* | ||
* @return {Generator} TokenList iterator. | ||
*/ | ||
* [ Symbol.iterator ]() { | ||
return yield* this._valueAsArray; | ||
} | ||
/** | ||
* Returns the token with index `index`. | ||
@@ -65,0 +88,0 @@ * |
@@ -28,5 +28,39 @@ /** | ||
} ); | ||
describe( 'array method inheritence', () => { | ||
it( 'entries', () => { | ||
const list = new TokenList( 'abc ' ); | ||
expect( [ ...list.entries() ] ).toEqual( [ [ 0, 'abc' ] ] ); | ||
} ); | ||
it( 'forEach', () => { | ||
expect.assertions( 1 ); | ||
const list = new TokenList( 'abc ' ); | ||
list.forEach( ( item ) => expect( item ).toBe( 'abc' ) ); | ||
} ); | ||
it( 'values', () => { | ||
const list = new TokenList( 'abc ' ); | ||
expect( [ ...list.values() ] ).toEqual( [ 'abc' ] ); | ||
} ); | ||
it( 'keys', () => { | ||
const list = new TokenList( 'abc ' ); | ||
expect( [ ...list.keys() ] ).toEqual( [ 0 ] ); | ||
} ); | ||
} ); | ||
} ); | ||
describe( 'value', () => { | ||
it( 'gets the stringified value', () => { | ||
const list = new TokenList( 'abc ' ); | ||
expect( list.value ).toBe( 'abc' ); | ||
} ); | ||
it( 'sets to stringified value', () => { | ||
@@ -38,4 +72,30 @@ const list = new TokenList(); | ||
} ); | ||
it( 'is the stringifier of the instance', () => { | ||
const list = new TokenList( 'abc ' ); | ||
expect( String( list ) ).toBe( 'abc' ); | ||
} ); | ||
} ); | ||
describe( 'Symbol.iterator', () => { | ||
it( 'returns a generator', () => { | ||
const list = new TokenList(); | ||
expect( list[ Symbol.iterator ]().next ).toEqual( expect.any( Function ) ); | ||
} ); | ||
it( 'yields entries', () => { | ||
expect.assertions( 2 ); | ||
const classes = [ 'abc', 'def' ]; | ||
const list = new TokenList( classes.join( ' ' ) ); | ||
let i = 0; | ||
for ( const item of list ) { | ||
expect( item ).toBe( classes[ i++ ] ); | ||
} | ||
} ); | ||
} ); | ||
describe( 'item', () => { | ||
@@ -42,0 +102,0 @@ it( 'should return undefined if item at index does not exist', () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
62979
10.44%860
19.61%1
Infinity%