Files
30-seconds-of-code/node_modules/remark-stringify/lib/util/entity-prefix-length.js
2019-08-20 15:52:05 +02:00

24 lines
543 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
var decode = require('parse-entities');
module.exports = length;
/* Returns the length of HTML entity that is a prefix of
* the given string (excluding the ampersand), 0 if it
* does not start with an entity. */
function length(value) {
var prefix;
/* istanbul ignore if - Currently also tested for at
* implemention, but we keep it here because thats
* proper. */
if (value.charAt(0) !== '&') {
return 0;
}
prefix = value.split('&', 2).join('&');
return prefix.length - decode(prefix).length;
}