Skip to content

Commit 5c99ca8

Browse files
committed
refactor: use isFontStyle,isFontWeight in title setters
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent fa696ef commit 5c99ca8

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

  • lib/node_modules/@stdlib/plot/vega/title/ctor/lib

lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-style/set.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
// MODULES //
2424

2525
var logger = require( 'debug' );
26-
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
27-
var isUndefined = require( '@stdlib/assert/is-undefined' );
26+
var isFontStyle = require( '@stdlib/plot/vega/base/assert/is-font-style' );
27+
var join = require( '@stdlib/array/base/join' );
28+
var fontStyles = require( '@stdlib/plot/vega/base/font-styles' );
2829
var format = require( '@stdlib/string/format' );
2930
var changeEvent = require( './../change_event.js' );
3031
var prop = require( './properties.js' );
@@ -40,18 +41,14 @@ var debug = logger( 'vega:title:set:'+prop.name );
4041
/**
4142
* Sets the font style of the title text.
4243
*
43-
* ## Notes
44-
*
45-
* - Providing `undefined` "unsets" the configured value.
46-
*
4744
* @private
48-
* @param {(string|void)} value - input value
49-
* @throws {TypeError} must be a string
45+
* @param {string} value - input value
46+
* @throws {TypeError} must be a valid font style
5047
* @returns {void}
5148
*/
5249
function set( value ) {
53-
if ( !isString( value ) && !isUndefined( value ) ) {
54-
throw new TypeError( format( 'invalid assignment. `%s` must be a string. Value: `%s`.', prop.name, value ) );
50+
if ( !isFontStyle( value ) ) {
51+
throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( fontStyles(), '", "' ), value ) );
5552
}
5653
if ( value !== this[ prop.private ] ) {
5754
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );

lib/node_modules/@stdlib/plot/vega/title/ctor/lib/font-weight/set.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
// MODULES //
2424

2525
var logger = require( 'debug' );
26-
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
27-
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
28-
var isUndefined = require( '@stdlib/assert/is-undefined' );
26+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
27+
var isFontWeight = require( '@stdlib/plot/vega/base/assert/is-font-weight' );
28+
var join = require( '@stdlib/array/base/join' );
29+
var fontWeights = require( '@stdlib/plot/vega/base/font-weights' );
2930
var format = require( '@stdlib/string/format' );
3031
var changeEvent = require( './../change_event.js' );
3132
var prop = require( './properties.js' );
@@ -43,16 +44,19 @@ var debug = logger( 'vega:title:set:'+prop.name );
4344
*
4445
* ## Notes
4546
*
46-
* - Providing `undefined` "unsets" the configured value.
47+
* - If provided a number, the value is converted to a string.
4748
*
4849
* @private
49-
* @param {(number|string|void)} value - input value
50-
* @throws {TypeError} must be a number or string
50+
* @param {(number|string)} value - input value
51+
* @throws {TypeError} must be a valid font weight
5152
* @returns {void}
5253
*/
5354
function set( value ) {
54-
if ( !isNumber( value ) && !isString( value ) && !isUndefined( value ) ) {
55-
throw new TypeError( format( 'invalid assignment. `%s` must be a number or string. Value: `%s`.', prop.name, value ) );
55+
if ( isNonNegativeInteger( value ) ) {
56+
value = String( value );
57+
}
58+
if ( !isFontWeight( value ) ) {
59+
throw new TypeError( format( 'invalid assignment. `%s` must be one of the following: "%s". Value: `%s`.', prop.name, join( fontWeights(), '", "' ), value ) );
5660
}
5761
if ( value !== this[ prop.private ] ) {
5862
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );

0 commit comments

Comments
 (0)