'use strict';

// MODULES //

var fromString = require( '@stdlib/buffer/from-string' );


// MAIN //

/**
* Re-decodes a UTF-8 string according to a specified encoding.
*
* @private
* @param {string} str - UTF-8 string to decode
* @param {string} enc - string encoding
* @returns {string} decoded string
*/
function decode( str, enc ) {
	// Check if we need to re-decode the string to something other than 'utf8'...
	if ( enc === 'utf8' || enc === 'buffer' ) {
		return str;
	}
	str = fromString( str );
	return str.toString( enc );
} // end FUNCTION decode()


// EXPORTS //

module.exports = decode;

'use strict';

// MODULES //

var fromString = require( '@stdlib/buffer/from-string' );


// MAIN //

/**
* Re-decodes a UTF-8 string according to a specified encoding.
*
* @private
* @param {string} str - UTF-8 string to decode
* @param {string} enc - string encoding
* @returns {string} decoded string
*/
function decode( str, enc ) {
	// Check if we need to re-decode the string to something other than 'utf8'...
	if ( enc === 'utf8' || enc === 'buffer' ) {
		return str;
	}
	str = fromString( str );
	if ( enc ) {
		return str.toString( enc );
	}
	return str.toString();
} // end FUNCTION decode()


// EXPORTS //

module.exports = decode;

Fix bug when encoding is `null`
Fix bug when encoding is `null`
