|
|
@ -11,20 +11,18 @@ function isString(obj) { return _class(obj) === '[object String]'; } |
|
|
|
//
|
|
|
|
function assign(obj /*from1, from2, from3, ...*/) { |
|
|
|
var sources = Array.prototype.slice.call(arguments, 1); |
|
|
|
while (sources.length) { |
|
|
|
var source = sources.shift(); |
|
|
|
if (!source) { continue; } |
|
|
|
|
|
|
|
sources.forEach(function (source) { |
|
|
|
if (!source) { return; } |
|
|
|
|
|
|
|
if (typeof source !== 'object') { |
|
|
|
throw new TypeError(source + 'must be object'); |
|
|
|
} |
|
|
|
|
|
|
|
for (var p in source) { |
|
|
|
if (source.hasOwnProperty(p)) { |
|
|
|
obj[p] = source[p]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Object.keys(source).forEach(function (key) { |
|
|
|
obj[key] = source[key]; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
return obj; |
|
|
|
} |
|
|
@ -66,18 +64,31 @@ function fromCodePoint(c) { |
|
|
|
return String.fromCharCode(c); |
|
|
|
} |
|
|
|
|
|
|
|
var NAMED_ENTITY_RE = /&([a-z][a-z0-9]{1,31});/gi; |
|
|
|
var NAMED_ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi; |
|
|
|
var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i; |
|
|
|
var entities = require('./entities'); |
|
|
|
|
|
|
|
function replaceEntities(str) { |
|
|
|
if (str.indexOf('&') < 0) { return str; } |
|
|
|
function replaceEntityPattern(match, name) { |
|
|
|
var code = 0; |
|
|
|
|
|
|
|
return str.replace(NAMED_ENTITY_RE, function(match, name) { |
|
|
|
if (entities.hasOwnProperty(name)) { |
|
|
|
return entities[name]; |
|
|
|
} else if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { |
|
|
|
code = name[1].toLowerCase() === 'x' ? |
|
|
|
parseInt(name.slice(2), 16) |
|
|
|
: |
|
|
|
parseInt(name.slice(1), 10); |
|
|
|
if (isValidEntityCode(code)) { |
|
|
|
return fromCodePoint(code); |
|
|
|
} |
|
|
|
} |
|
|
|
return match; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function replaceEntities(str) { |
|
|
|
if (str.indexOf('&') < 0) { return str; } |
|
|
|
|
|
|
|
return str.replace(NAMED_ENTITY_RE, replaceEntityPattern); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|