Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
// MODULES //

var logger = require( 'debug' );
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var isUndefined = require( '@stdlib/assert/is-undefined' );
var isFontStyle = require( '@stdlib/plot/vega/base/assert/is-font-style' );
var join = require( '@stdlib/array/base/join' );
var fontStyles = require( '@stdlib/plot/vega/base/font-styles' );
var format = require( '@stdlib/string/format' );
var changeEvent = require( './../change_event.js' );
var prop = require( './properties.js' );
Expand All @@ -42,16 +44,16 @@
*
* ## Notes
*
* - Providing `undefined` "unsets" the configured value.

Check warning on line 47 in lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-style/set.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "unsets"
*
* @private
* @param {(string|void)} value - input value
* @throws {TypeError} must be a string
* @throws {TypeError} must be a valid font style
* @returns {void}
*/
function set( value ) {
if ( !isString( value ) && !isUndefined( value ) ) {
throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', prop.name, value ) );
if ( !isUndefined( value ) && !isFontStyle( value ) ) {
throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( fontStyles(), '", "' ), value ) );
}
if ( value !== this[ prop.private ] ) {
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
// MODULES //

var logger = require( 'debug' );
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var isUndefined = require( '@stdlib/assert/is-undefined' );
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
var isFontWeight = require( '@stdlib/plot/vega/base/assert/is-font-weight' );
var join = require( '@stdlib/array/base/join' );
var fontWeights = require( '@stdlib/plot/vega/base/font-weights' );
var format = require( '@stdlib/string/format' );
var changeEvent = require( './../change_event.js' );
var prop = require( './properties.js' );
Expand All @@ -43,16 +45,19 @@
*
* ## Notes
*
* - Providing `undefined` "unsets" the configured value.

Check warning on line 48 in lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-weight/set.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "unsets"
*
* @private
* @param {(number|string|void)} value - input value
* @throws {TypeError} must be a number or string
* @throws {TypeError} must be a valid font weight
* @returns {void}
*/
function set( value ) {
if ( !isNumber( value ) && !isString( value ) && !isUndefined( value ) ) {
throw new TypeError( format( 'invalid assignment. `%s` must be a number or string. Value: `%s`.', prop.name, value ) );
if ( isNonNegativeInteger( value ) ) {
value = String( value );
}
if ( !isUndefined( value ) && !isFontWeight( value ) ) {
throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( fontWeights(), '", "' ), value ) );
}
if ( value !== this[ prop.private ] ) {
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tape( 'the constructor returns an instance which has a `fontStyle` property', fu
t.strictEqual( isUndefined( v.fontStyle ), true, 'returns expected value' );

v = new Title({
'fontStyle': 'Arial'
'fontStyle': 'italic'
});
t.strictEqual( isString( v.fontStyle ), true, 'returns expected value' );

Expand All @@ -55,6 +55,8 @@ tape( 'the constructor returns an instance having a `fontStyle` property which t
var i;

values = [
'Arial',
'foo',
5,
NaN,
null,
Expand Down Expand Up @@ -82,26 +84,26 @@ tape( 'the constructor returns an instance having a `fontStyle` property', funct
t.strictEqual( isUndefined( title.fontStyle ), true, 'returns expected value' );

title = new Title({
'fontStyle': 'Arial'
'fontStyle': 'italic'
});
t.strictEqual( title.fontStyle, 'Arial', 'returns expected value' );
t.strictEqual( title.fontStyle, 'italic', 'returns expected value' );

title = new Title({
'fontStyle': 'Sans'
'fontStyle': 'oblique'
});
t.strictEqual( title.fontStyle, 'Sans', 'returns expected value' );
t.strictEqual( title.fontStyle, 'oblique', 'returns expected value' );

t.end();
});

tape( 'the constructor returns an instance having a `fontStyle` property which can be set to a valid value', function test( t ) {
var title = new Title();

title.fontStyle = 'Arial';
t.strictEqual( title.fontStyle, 'Arial', 'returns expected value' );
title.fontStyle = 'italic';
t.strictEqual( title.fontStyle, 'italic', 'returns expected value' );

title.fontStyle = 'Sans';
t.strictEqual( title.fontStyle, 'Sans', 'returns expected value' );
title.fontStyle = 'oblique';
t.strictEqual( title.fontStyle, 'oblique', 'returns expected value' );

t.end();
});
Expand All @@ -115,14 +117,14 @@ tape( 'the constructor returns an instance which emits an event when the `fontSt

title.on( 'change', onChange );

title.fontStyle = 'Sans';
title.fontStyle = 'italic';
t.strictEqual( count, 1, 'returns expected value' );

title.fontStyle = 'Arial';
title.fontStyle = 'oblique';
t.strictEqual( count, 2, 'returns expected value' );

// Setting to the same value should not emit an event:
title.fontStyle = 'Arial';
title.fontStyle = 'oblique';
t.strictEqual( count, 2, 'returns expected value' );

t.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var isUndefined = require( '@stdlib/assert/is-undefined' );
var hasProp = require( '@stdlib/assert/has-property' );
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
var Title = require( './../lib' );


Expand All @@ -49,9 +48,9 @@ tape( 'the constructor returns an instance which has a `fontWeight` property', f
t.strictEqual( isString( v.fontWeight ), true, 'returns expected value' );

v = new Title({
'fontWeight': 6
'fontWeight': 600
});
t.strictEqual( isNumber( v.fontWeight ), true, 'returns expected value' );
t.strictEqual( isString( v.fontWeight ), true, 'returns expected value' );

t.end();
});
Expand All @@ -61,6 +60,9 @@ tape( 'the constructor returns an instance having a `fontWeight` property which
var i;

values = [
'foo',
6,
NaN,
null,
true,
false,
Expand Down Expand Up @@ -91,19 +93,19 @@ tape( 'the constructor returns an instance having a `fontWeight` property', func
t.strictEqual( title.fontWeight, 'bold', 'returns expected value' );

title = new Title({
'fontWeight': 'light'
'fontWeight': 'lighter'
});
t.strictEqual( title.fontWeight, 'light', 'returns expected value' );
t.strictEqual( title.fontWeight, 'lighter', 'returns expected value' );

title = new Title({
'fontWeight': 6
'fontWeight': '600'
});
t.strictEqual( title.fontWeight, 6, 'returns expected value' );
t.strictEqual( title.fontWeight, '600', 'returns expected value' );

title = new Title({
'fontWeight': 8
'fontWeight': 800
});
t.strictEqual( title.fontWeight, 8, 'returns expected value' );
t.strictEqual( title.fontWeight, '800', 'returns expected value' );

t.end();
});
Expand All @@ -114,14 +116,14 @@ tape( 'the constructor returns an instance having a `fontWeight` property which
title.fontWeight = 'bold';
t.strictEqual( title.fontWeight, 'bold', 'returns expected value' );

title.fontWeight = 'light';
t.strictEqual( title.fontWeight, 'light', 'returns expected value' );
title.fontWeight = 'lighter';
t.strictEqual( title.fontWeight, 'lighter', 'returns expected value' );

title.fontWeight = 6;
t.strictEqual( title.fontWeight, 6, 'returns expected value' );
title.fontWeight = '600';
t.strictEqual( title.fontWeight, '600', 'returns expected value' );

title.fontWeight = 8;
t.strictEqual( title.fontWeight, 8, 'returns expected value' );
title.fontWeight = 800;
t.strictEqual( title.fontWeight, '800', 'returns expected value' );

t.end();
});
Expand All @@ -135,7 +137,7 @@ tape( 'the constructor returns an instance which emits an event when the `fontWe

title.on( 'change', onChange );

title.fontWeight = 'light';
title.fontWeight = 'lighter';
t.strictEqual( count, 1, 'returns expected value' );

title.fontWeight = 'bold';
Expand Down
9 changes: 7 additions & 2 deletions lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ tape( 'the constructor throws an error if provided an invalid `fontStyle` option
var i;

values = [
'Arial',
'foo',
5,
NaN,
null,
Expand Down Expand Up @@ -408,6 +410,9 @@ tape( 'the constructor throws an error if provided an invalid `fontWeight` optio
var i;

values = [
'foo',
6,
NaN,
null,
true,
false,
Expand Down Expand Up @@ -903,7 +908,7 @@ tape( 'the constructor returns an instance having a `toJSON` method for serializ
},
'font': 'Arial',
'fontSize': 12,
'fontStyle': 'Arial',
'fontStyle': 'italic',
'fontWeight': 'bold',
'frame': 'group',
'limit': 100,
Expand Down Expand Up @@ -942,7 +947,7 @@ tape( 'the constructor returns an instance having a `toJSON` method for serializ
},
'font': 'Arial',
'fontSize': 12,
'fontStyle': 'Arial',
'fontStyle': 'italic',
'fontWeight': 'bold',
'frame': 'group',
'limit': 100,
Expand Down
Loading