|
@ -11,20 +11,18 @@ function isString(obj) { return _class(obj) === '[object String]'; } |
|
|
//
|
|
|
//
|
|
|
function assign(obj /*from1, from2, from3, ...*/) { |
|
|
function assign(obj /*from1, from2, from3, ...*/) { |
|
|
var sources = Array.prototype.slice.call(arguments, 1); |
|
|
var sources = Array.prototype.slice.call(arguments, 1); |
|
|
while (sources.length) { |
|
|
|
|
|
var source = sources.shift(); |
|
|
sources.forEach(function (source) { |
|
|
if (!source) { continue; } |
|
|
if (!source) { return; } |
|
|
|
|
|
|
|
|
if (typeof source !== 'object') { |
|
|
if (typeof source !== 'object') { |
|
|
throw new TypeError(source + 'must be object'); |
|
|
throw new TypeError(source + 'must be object'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (var p in source) { |
|
|
Object.keys(source).forEach(function (key) { |
|
|
if (source.hasOwnProperty(p)) { |
|
|
obj[key] = source[key]; |
|
|
obj[p] = source[p]; |
|
|
}); |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return obj; |
|
|
return obj; |
|
|
} |
|
|
} |
|
@ -66,18 +64,31 @@ function fromCodePoint(c) { |
|
|
return String.fromCharCode(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'); |
|
|
var entities = require('./entities'); |
|
|
|
|
|
|
|
|
function replaceEntities(str) { |
|
|
function replaceEntityPattern(match, name) { |
|
|
if (str.indexOf('&') < 0) { return str; } |
|
|
var code = 0; |
|
|
|
|
|
|
|
|
return str.replace(NAMED_ENTITY_RE, function(match, name) { |
|
|
|
|
|
if (entities.hasOwnProperty(name)) { |
|
|
if (entities.hasOwnProperty(name)) { |
|
|
return entities[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; |
|
|
return match; |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function replaceEntities(str) { |
|
|
|
|
|
if (str.indexOf('&') < 0) { return str; } |
|
|
|
|
|
|
|
|
|
|
|
return str.replace(NAMED_ENTITY_RE, replaceEntityPattern); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|