diff --git a/lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-style/set.js b/lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-style/set.js index 50b65947a854..65345a6708dc 100644 --- a/lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-style/set.js +++ b/lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-style/set.js @@ -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' ); @@ -46,12 +48,12 @@ var debug = logger( 'vega:title:set:'+prop.name ); * * @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 ); diff --git a/lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-weight/set.js b/lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-weight/set.js index 2d105394e6d8..ac841716d904 100644 --- a/lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-weight/set.js +++ b/lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-weight/set.js @@ -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' ); @@ -47,12 +49,15 @@ var debug = logger( 'vega:title:set:'+prop.name ); * * @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 ); diff --git a/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.font_style.js b/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.font_style.js index 937e9cb8bac9..f4c1d50fb9bc 100644 --- a/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.font_style.js +++ b/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.font_style.js @@ -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' ); @@ -55,6 +55,8 @@ tape( 'the constructor returns an instance having a `fontStyle` property which t var i; values = [ + 'Arial', + 'foo', 5, NaN, null, @@ -82,14 +84,14 @@ 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(); }); @@ -97,11 +99,11 @@ tape( 'the constructor returns an instance having a `fontStyle` property', funct 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(); }); @@ -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(); diff --git a/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.font_weight.js b/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.font_weight.js index 9ef9cd6a4339..763531d226c5 100644 --- a/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.font_weight.js +++ b/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.font_weight.js @@ -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' ); @@ -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(); }); @@ -61,6 +60,9 @@ tape( 'the constructor returns an instance having a `fontWeight` property which var i; values = [ + 'foo', + 6, + NaN, null, true, false, @@ -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(); }); @@ -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(); }); @@ -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'; diff --git a/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.js b/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.js index eeaba0114550..11cfcad05fde 100644 --- a/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.js +++ b/lib/node_modules/@stdlib/plot/vega/title/ctor/test/test.js @@ -380,6 +380,8 @@ tape( 'the constructor throws an error if provided an invalid `fontStyle` option var i; values = [ + 'Arial', + 'foo', 5, NaN, null, @@ -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, @@ -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, @@ -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,