'use strict';

// MODULES //

var isString = require( '@stdlib/utils/is-string' ).isPrimitive;


// VARIABLES //

var CAPITALS_REGEX = /^[A-Z]/;


// MAIN //

/**
* Tests if a value is a string having an uppercase first character.
*
* @param {*} value - value to test
* @returns {boolean} boolean indicating whether value is a string with an uppercase first character
*
* @example
* var bool = isCapitalized( 'Hello' );
* // returns true
* @example
* var bool = isCapitalized( 'WORLD' );
* // returns true
* @example
* var bool = isCapitalized( '!' );
* // returns false
* @example
* var bool = isCapitalized( 'salt and light' );
* // returns false
*/
function isCapitalized( value ) {
	if ( isString( value ) ) {
		return CAPITALS_REGEX.test( value );
	}
	return false;
} // end FUNCTION isCapitalized()


// EXPORTS //

module.exports = isCapitalized;

'use strict';

// MODULES //

var lowercase = require( '@stdlib/string/lowercase' );
var uppercase = require( '@stdlib/string/uppercase' );
var isString = require( '@stdlib/utils/is-string' ).isPrimitive;


// MAIN //

/**
* Tests if a value is a string having an uppercase first character.
*
* @param {*} value - value to test
* @returns {boolean} boolean indicating whether value is a string with an uppercase first character
*
* @example
* var bool = isCapitalized( 'Hello' );
* // returns true
* @example
* var bool = isCapitalized( 'WORLD' );
* // returns true
* @example
* var bool = isCapitalized( '!' );
* // returns false
* @example
* var bool = isCapitalized( 'salt and light' );
* // returns false
*/
function isCapitalized( value ) {
	var ch;
	if ( isString( value ) && value !== '' ) {
		ch = value[ 0 ];
		return ( ch === uppercase( ch ) && ch !== lowercase( ch ) );
	}
	return false;
} // end FUNCTION isCapitalized()


// EXPORTS //

module.exports = isCapitalized;

Refactor implementation