Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Added iterator interface to the Config class. #316

Merged
merged 3 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ export default class Config {
return this._getFromSource( this._config, name );
}

/**
* Iterates over all top level configuration names.
*
* @returns {Iterable.<String>}
*/
* names() {
for ( const name of Object.keys( this._config ) ) {
yield name;
}
}

/**
* Saves passed configuration to the specified target (nested object).
*
Expand Down
6 changes: 6 additions & 0 deletions tests/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,10 @@ describe( 'Config', () => {
expect( nodesAgain ).to.deep.equal( nodes );
} );
} );

describe( 'names()', () => {
it( 'should return an iterator of top level names of the configuration', () => {
expect( Array.from( config.names() ) ).to.be.deep.equal( [ 'creator', 'language', 'resize', 'toolbar', 'options' ] );
} );
} );
} );