@zambezi/address
Advanced tools
Comparing version 2.1.0-real-urls.6 to 2.1.0
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(require("underscore"), require("@websdk/nap"), require("@websdk/rhumb"), require("lil-uri"), require("d3-dispatch")); | ||
module.exports = factory(require("underscore"), require("@websdk/nap"), require("@websdk/rhumb"), require("d3-dispatch")); | ||
else if(typeof define === 'function' && define.amd) | ||
define(["underscore", "@websdk/nap", "@websdk/rhumb", "lil-uri", "d3-dispatch"], factory); | ||
define(["underscore", "@websdk/nap", "@websdk/rhumb", "d3-dispatch"], factory); | ||
else if(typeof exports === 'object') | ||
exports["address"] = factory(require("underscore"), require("@websdk/nap"), require("@websdk/rhumb"), require("lil-uri"), require("d3-dispatch")); | ||
exports["address"] = factory(require("underscore"), require("@websdk/nap"), require("@websdk/rhumb"), require("d3-dispatch")); | ||
else | ||
root["address"] = factory(root["_"], root["nap"], root["rhumb"], root["lil-uri"], root["d3-dispatch"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_11__, __WEBPACK_EXTERNAL_MODULE_12__, __WEBPACK_EXTERNAL_MODULE_17__) { | ||
root["address"] = factory(root["_"], root["nap"], root["rhumb"], root["d3-dispatch"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_11__, __WEBPACK_EXTERNAL_MODULE_18__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -60,14 +60,14 @@ /******/ // The module cache | ||
address: __webpack_require__(1) | ||
, created: __webpack_require__(21) | ||
, error: __webpack_require__(16) | ||
, created: __webpack_require__(24) | ||
, error: __webpack_require__(17) | ||
, httpStatusCode: __webpack_require__(6) | ||
, interpolate: __webpack_require__(9) | ||
, into: __webpack_require__(22) | ||
, location: __webpack_require__(19) | ||
, middleware: __webpack_require__(23) | ||
, ok: __webpack_require__(24) | ||
, redirect: __webpack_require__(25) | ||
, response: __webpack_require__(26) | ||
, serialize: __webpack_require__(27) | ||
, stream: __webpack_require__(28) | ||
, into: __webpack_require__(25) | ||
, location: __webpack_require__(21) | ||
, middleware: __webpack_require__(20) | ||
, ok: __webpack_require__(26) | ||
, redirect: __webpack_require__(27) | ||
, response: __webpack_require__(28) | ||
, serialize: __webpack_require__(13) | ||
, stream: __webpack_require__(29) | ||
} | ||
@@ -91,10 +91,10 @@ }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
, compose = __webpack_require__(10) | ||
, wrapView = __webpack_require__(13) | ||
, invokeView = __webpack_require__(14) | ||
, toObject = __webpack_require__(15) | ||
, wrapView = __webpack_require__(14) | ||
, invokeView = __webpack_require__(15) | ||
, toObject = __webpack_require__(16) | ||
, parseUri = __webpack_require__(12) | ||
, error = __webpack_require__(16) | ||
, dispatch = __webpack_require__(17).dispatch | ||
, rebind = __webpack_require__(18) | ||
, location = __webpack_require__(19) | ||
, error = __webpack_require__(17) | ||
, dispatch = __webpack_require__(18).dispatch | ||
, rebind = __webpack_require__(19) | ||
, middleware = __webpack_require__(20) | ||
@@ -105,2 +105,3 @@ function address(r) { | ||
, web | ||
, location | ||
, method = "get" | ||
@@ -119,3 +120,3 @@ , headers = { accept : "application/x.nap.view" } | ||
uri = r | ||
query = parseUri(encodeURI(uri)).query() || query | ||
query = parseUri(uri).query() || query | ||
} else if(r && _.isObject(r)) { | ||
@@ -150,3 +151,4 @@ uri = r.uri || uri | ||
if(!arguments.length) return web | ||
web = w | ||
web = augmentWeb(w) | ||
location = __webpack_require__(21)(web, address) | ||
return api | ||
@@ -293,6 +295,5 @@ } | ||
var interpolatedUri = interpolate(web, uri, params) | ||
// As lil-uri always decodes the URI, encode it. | ||
, parsedUri = parseUri(encodeURI(interpolatedUri)) | ||
, parsedUri = parseUri(interpolatedUri) | ||
, q = _.extend({}, parsedUri.query(), query) | ||
, mergedUri = (_.isEmpty(q) ? parsedUri : parsedUri.query(q)).build() | ||
, mergedUri = (_.isEmpty(q) ? parsedUri : parsedUri.query(q)).path() | ||
@@ -313,10 +314,9 @@ if (!zapp.isRoot(context)) return mergedUri | ||
function handleResponse(req, callback, err, res) { | ||
// deprecated // | ||
callback && callback(err, res) | ||
if(err) return dispatcher.err(err), null | ||
if (err) return dispatcher.err(err), null | ||
if(isView(res)) { | ||
if(res.statusCode != 302) wrapView(location, req, res) | ||
if (isView(res)) { | ||
if (res.statusCode != 302) wrapView(location, req, res) | ||
req.context && invokeView(req, res) | ||
@@ -331,2 +331,3 @@ } | ||
codes(res.statusCode).concat(['done']).forEach(function(type) { | ||
@@ -338,2 +339,10 @@ dispatcher[type](res) | ||
function augmentWeb(web) { | ||
if (!web.use._address_decodeParams) { | ||
web.use._address_decodeParams = true | ||
web.use(middleware.decodeParams) | ||
} | ||
return web | ||
} | ||
return address | ||
@@ -549,52 +558,58 @@ }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var _ = __webpack_require__(2) | ||
, interpolate = __webpack_require__(9) | ||
, rhumb = __webpack_require__(11) | ||
, uri = __webpack_require__(12) | ||
var _ = __webpack_require__(2) | ||
, interpolate = __webpack_require__(9) | ||
, rhumb = __webpack_require__(11) | ||
, uri = __webpack_require__(12) | ||
return function(web, requestedUri, currentUri) { | ||
return function(web, requestedUri, currentUri) { | ||
if(!currentUri || requestedUri == currentUri) return requestedUri | ||
if(!currentUri || requestedUri == currentUri) return requestedUri | ||
var currentResource = web.find(currentUri) | ||
, requestedResource = web.find(requestedUri) | ||
var currentResource = web.find(currentUri) | ||
, requestedResource = web.find(requestedUri) | ||
if(!currentResource || !requestedResource) return requestedUri | ||
if(!currentResource || !requestedResource) return requestedUri | ||
var composedParams = _.extend(currentResource.params, requestedResource.params) | ||
, redirect = currentResource.redirects[requestedResource.path] | ||
, composes = _.contains(currentResource.composes, requestedResource.path) | ||
, rewritePath = redirect || currentResource.path | ||
, shouldRewrite = redirect || composes | ||
var composedParams | ||
, redirect = currentResource.redirects[requestedResource.path] | ||
, composes = _.contains(currentResource.composes, requestedResource.path) | ||
, rewritePath = redirect || currentResource.path | ||
, shouldRewrite = redirect || composes | ||
if(shouldRewrite) return rewrite(web, rewritePath, composedParams) | ||
return requestedUri | ||
if(shouldRewrite) { | ||
composedParams = _.extend( | ||
_.mapObject(currentResource.params, uri.decode) | ||
, _.mapObject(requestedResource.params, uri.decode) | ||
) | ||
return rewrite(web, rewritePath, composedParams) | ||
} | ||
function rewrite(web, path, params) { | ||
var alreadyInterpolated = _.chain(rhumb._parse(path)) | ||
.flatten() | ||
.filter(byInterpolated) | ||
.map('input') | ||
.value() | ||
, query = _.reduce(params, buildQuery, {}) | ||
, rewritten = interpolate(web, path, params) | ||
, url = uri(rewritten) | ||
return requestedUri | ||
} | ||
if (!_.isEmpty(query)) url.query(_.extend({}, url.query(), query)) | ||
function rewrite(web, path, params) { | ||
var alreadyInterpolated = _.chain(rhumb._parse(path)) | ||
.flatten() | ||
.filter(byInterpolated) | ||
.map('input') | ||
.value() | ||
, query = _.reduce(params, buildQuery, {}) | ||
, rewritten = interpolate(web, path, params) | ||
, url = uri(rewritten) | ||
return url.build() | ||
if (!_.isEmpty(query)) url.query(_.extend({}, url.query(), query)) | ||
function byInterpolated(part) { | ||
return part.type == 'var' | ||
} | ||
return url.path() | ||
function buildQuery(q, v, k) { | ||
if (_.contains(alreadyInterpolated, k)) return q | ||
q[k] = v | ||
return q | ||
} | ||
function byInterpolated(part) { | ||
return part.type == 'var' | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
function buildQuery(q, v, k) { | ||
if (_.contains(alreadyInterpolated, k)) return q | ||
q[k] = v | ||
return q | ||
} | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
@@ -610,5 +625,124 @@ | ||
/* 12 */ | ||
/***/ function(module, exports) { | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_12__; | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) { | ||
var _ = __webpack_require__(2) | ||
, serialize = __webpack_require__(13) | ||
, serializeEncoder = _.compose(String, encode) | ||
uri.decode = decode | ||
uri.encode = encode | ||
return uri | ||
function uri(url) { | ||
var api = { | ||
query: setQuery | ||
, search: setSearch | ||
, path: setPath | ||
, pathname: setPathname | ||
, hash: setHash | ||
, toString: build | ||
} | ||
, pathname = '' | ||
, query = {} | ||
, hash = '' | ||
return url ? parse(url) : api | ||
function setQuery(value) { | ||
if (!arguments.length) return query | ||
if (!_.isObject(value)) return query[value] | ||
query = _.extend(query, value) | ||
return api | ||
} | ||
function setPathname(value) { | ||
if (!arguments.length) return pathname | ||
pathname = value | ||
return api | ||
} | ||
function setHash(value) { | ||
if (!arguments.length) return hash | ||
hash = value | ||
return api | ||
} | ||
function setSearch(queryString) { | ||
if (!arguments.length) return serialize(query, serializeEncoder) | ||
query = parseQueryString(queryString.charAt(0) === '?' | ||
? queryString.slice(1) | ||
: queryString | ||
) | ||
return api | ||
} | ||
function setPath(url) { | ||
return !arguments.length ? build() : parse(url) | ||
} | ||
function build() { | ||
var currentPathname = pathname.replace(/[?#]/g, encode) | ||
, currentHash = hash && hash.charAt(0) !== '#' ? '#' + hash : hash | ||
, search = setSearch().replace(/#/g, encode) | ||
return currentPathname + search + currentHash | ||
} | ||
function parse(url) { | ||
var parts = url.match(/^(.*?)(\?.*?)?(#.*?)?$/) | ||
, search = parts[2] ? parts[2].slice(1) : '' | ||
pathname = parts[1] || '' | ||
hash = parts[3] ? parts[3].slice(1) : '' | ||
return setSearch(search) | ||
} | ||
} | ||
function parseQueryString(queryString, decoder) { | ||
var sep = '&' | ||
, eq = '=' | ||
, query = {} | ||
, regexp = /\+/g | ||
, decodedKey, decodedValue, fragment, parts | ||
if (!queryString) return query | ||
var queryFragments = queryString.split(sep) | ||
, len = queryFragments.length | ||
for (var i = 0; i < len; ++i) { | ||
fragment = queryFragments[i].replace(regexp, '%20') | ||
parts = fragment.split(eq) | ||
decodedKey = decode(parts.shift()) | ||
decodedValue = decode(parts.join(eq)) | ||
if (!Object.prototype.hasOwnProperty.call(query, decodedKey)) { | ||
query[decodedKey] = decodedValue | ||
} else if (_.isArray(query[decodedKey])) { | ||
query[decodedKey].push(decodedValue) | ||
} else { | ||
query[decodedKey] = [query[decodedKey], decodedValue] | ||
} | ||
} | ||
return query | ||
} | ||
function encode(value) { | ||
return value ? encodeURIComponent(value) : '' | ||
} | ||
function decode(value) { | ||
if (value) { | ||
return String(value).replace(/%[0-9a-fA-F]{2}/g, function(match) { | ||
return decodeURIComponent(match) | ||
}) | ||
} else { | ||
return '' | ||
} | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
@@ -620,3 +754,30 @@ /***/ }, | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var _ = __webpack_require__(2) | ||
return function(query, encode) { | ||
encode = encode || _.identity | ||
var params = Object.keys(query).reduce(reduceQuery, []) | ||
return params.length ? '?' + params.join('&') : '' | ||
function reduceQuery(list, key) { | ||
var value = query[key] | ||
if (_.isUndefined(value)) return list | ||
if (_.isArray(value)) return list.concat(value.map(encodeKV)) | ||
return list.concat(encodeKV(value)) | ||
function encodeKV(v) { | ||
return v? encode(key) + '=' + encode(v) : encode(key) | ||
} | ||
} | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
/***/ }, | ||
/* 14 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var _ = __webpack_require__(2) | ||
@@ -668,3 +829,3 @@ , zapp = __webpack_require__(4) | ||
/***/ }, | ||
/* 14 */ | ||
/* 15 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -685,3 +846,3 @@ | ||
/***/ }, | ||
/* 15 */ | ||
/* 16 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -703,3 +864,3 @@ | ||
/***/ }, | ||
/* 16 */ | ||
/* 17 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -719,9 +880,9 @@ | ||
/***/ }, | ||
/* 17 */ | ||
/* 18 */ | ||
/***/ function(module, exports) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_17__; | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_18__; | ||
/***/ }, | ||
/* 18 */ | ||
/* 19 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -777,183 +938,186 @@ | ||
/***/ }, | ||
/* 19 */ | ||
/* 20 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var findClosest = __webpack_require__(5) | ||
, rebind = __webpack_require__(18) | ||
, dispatcher = __webpack_require__(17).dispatch('statechange') | ||
, history = window.history | ||
, location = window.location | ||
, on = __webpack_require__(20) | ||
, base = '' | ||
on.call(window, 'popstate.location', handleStateChange) | ||
on.call(document, 'click.location', handleClick) | ||
var error = __webpack_require__(17) | ||
, uri = __webpack_require__(12) | ||
if (isHashPath(location.hash)) { | ||
// Redirect current hash fragment location to "real" path | ||
history.replaceState(null, null, rebase(fullPath(location))) | ||
} | ||
return { | ||
var api = | ||
{ getState: getState | ||
, setState: setState | ||
, pushState: pushState | ||
, openNewWindow: openNewWindow | ||
, basePath: basePath | ||
} | ||
requestTimeout : function(req, res, next) { | ||
return rebind(api, dispatcher, 'on') | ||
var responded | ||
, timeout = setTimeout(function() { | ||
responded = true | ||
res(null, error(408)) | ||
}, 30000) | ||
function getState() { | ||
return unbase(fullPath(location)) | ||
} | ||
next(req, function(err, data) { | ||
clearTimeout(timeout) | ||
!responded && res(err, data) | ||
}) | ||
} | ||
, decodeParams : function(req, res, next) { | ||
if (req.params) { | ||
req.params = _.mapObject(req.params, uri.decode) | ||
} | ||
next(req, res) | ||
} | ||
function setState(path) { | ||
var actual = pushState(path) | ||
if (actual) { | ||
dispatcher.statechange(actual) | ||
return actual | ||
} else { | ||
return false | ||
, logger : function(log) { | ||
return function logger(req, res, next) { | ||
next(req, function(err, data) { | ||
if(data.statusCode == 302) log.debug(data.statusCode, req.uri, data.headers.location) | ||
if(data.statusCode >= 400) { | ||
log.debug(data.statusCode, 'address failed to load resource:', req.uri, req.method, data.body || '') | ||
} | ||
res(err, data) | ||
}) | ||
} | ||
} | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
function pushState(path) { | ||
if (~path.indexOf('#/')) { | ||
path = '/' + trimSlashes(path.split('#/')[1]) | ||
} | ||
/***/ }, | ||
/* 21 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var location = __webpack_require__(22) | ||
, state = location.state() | ||
, findClosest = __webpack_require__(5) | ||
, rebind = __webpack_require__(19) | ||
, dispatch = __webpack_require__(18).dispatch | ||
, dispatcher = dispatch('statechange') | ||
, on = __webpack_require__(23) | ||
, ignoreFlag = false | ||
path = unbase(path) | ||
location.on('statechange.location', handleStateChange) | ||
if (path === getState()) { | ||
return false | ||
} else { | ||
history.pushState({ base: base, path: path }, null, rebase(path)) | ||
return path | ||
} | ||
function handleStateChange() { | ||
if(ignore()) return ignore(false) | ||
setState(location.state()) | ||
ignore(false) | ||
} | ||
function openNewWindow(path, target) { | ||
return window.open(rebase(path), target, '') | ||
function ignore(value) { | ||
if(!arguments.length) return ignoreFlag | ||
ignoreFlag = value | ||
} | ||
function basePath(path) { | ||
if (arguments.length === 0) return base | ||
function pushState(value) { | ||
if(isCurrentState(value)) return | ||
ignore(true) | ||
currentState(value) | ||
location.state(value) | ||
return true | ||
} | ||
var cwd = unbase(fullPath(location)) | ||
function setState(value) { | ||
var pushed = pushState(value) | ||
if (pushed) dispatcher.statechange(value) | ||
} | ||
path = trimSlashes(path) | ||
base = path? '/' + path : '' | ||
function currentState(value) { | ||
if(!arguments.length) return state | ||
state = value | ||
} | ||
history.replaceState(null, null, rebase(cwd)) | ||
function isCurrentState(value) { | ||
return value == currentState() | ||
} | ||
function handleClick(event) { | ||
var a | ||
, target = event.target | ||
, path | ||
return function createComponent(web, address) { | ||
var api = {} | ||
if (event.ctrlKey) return // Ignore ctrl+click | ||
if (event.button !== 0) return // Ignore clicks by buttons other than primary (usually left button) | ||
on.call(document, 'click.location', handleClick) | ||
a = findClosest.anchor(target) | ||
api.getState = function() { return currentState() } | ||
api.setState = setState | ||
api.pushState = pushState | ||
api.openNewWindow = openNewWindow | ||
if (!a) return // Ignore non-anchor clicks | ||
if (!!a.target) return // Ignore anchors with specified targets | ||
if (!isSameOrigin(a, location)) return // Ignore links to different origins | ||
return rebind(api, dispatcher, 'on') | ||
var path | ||
if (isHashPath(a.hash)) { | ||
path = rebase(a.hash.slice(1)) | ||
} else if (a.hash) { | ||
return // Ignore links with a non-path hash | ||
} else { | ||
path = rebase(fullPath(a)) | ||
function openNewWindow(path, target) { | ||
window.open(location.hrefFromPath(path), target, '') | ||
} | ||
if (path) { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
var actual = pushState(path) | ||
function handleClick(event) { | ||
var anchor | ||
, target = event.target | ||
, path | ||
if (actual) { | ||
dispatcher.statechange(actual) | ||
} | ||
} | ||
} | ||
if (event.ctrlKey) return | ||
if (event.button == 1) return | ||
anchor = findClosest.anchor(target) | ||
if (!anchor) return | ||
if (!!anchor.target) return | ||
if (location.shouldIgnoreHref(anchor.href)) return | ||
function handleStateChange(event) { | ||
var path, base = (event.state && event.state.base) || '' | ||
path = location.pathFromHref(anchor.href) | ||
if (isHashPath(location.hash)) { | ||
// "Redirect" current location to a proper path | ||
path = location.hash.slice(1) | ||
if (!path) return | ||
if (!web.find(path)) return | ||
if (path) { | ||
var state = { base: base, path: path } | ||
history.replaceState(state, null, rebase(path)) | ||
} | ||
} else { | ||
path = fullPath(location) | ||
event.preventDefault() | ||
event.stopPropagation() | ||
address(path).origin(target).navigate() | ||
} | ||
dispatcher.statechange(unbase(path)) | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
/***/ }, | ||
/* 22 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
function isHashPath(hash) { | ||
return (hash || '').slice(0, 2) === '#/' | ||
} | ||
var on = __webpack_require__(23) | ||
, rebind = __webpack_require__(19) | ||
, dispatch = __webpack_require__(18).dispatch | ||
, dispatcher = dispatch('statechange') | ||
, api = {} | ||
function isSameOrigin(a, x) { | ||
var o = origin(x) | ||
return a.href.slice(0, o.length) === o | ||
} | ||
on.call(window, 'hashchange.location-hash', dispatcher.statechange) | ||
function origin(url) { | ||
if (url.origin) { | ||
return url.origin | ||
} else { | ||
var port | ||
api.state = state | ||
api.hrefFromPath = hrefFromPath | ||
api.pathFromHref = pathFromHref | ||
api.shouldIgnoreHref = shouldIgnoreHref | ||
if (url.port && !~url.href.indexOf(':' + url.port)) { | ||
// IE defaults port values based on protocol, which messes things up | ||
port = '' | ||
} else { | ||
port = ':' + url.port | ||
} | ||
return rebind(api, dispatcher, 'on') | ||
return url.protocol + "//" + url.hostname + port | ||
} | ||
function state(value) { | ||
if (!arguments.length) return pathFromHref(loc_href()) | ||
document.location.hash = value | ||
return api | ||
} | ||
function fullPath(url) { | ||
if (isHashPath(url.hash)) { | ||
return url.hash.slice(1) | ||
} else { | ||
return url.href.slice(origin(url).length) | ||
} | ||
function hrefFromPath(path) { | ||
var hash = '#' + path | ||
return /#/.test(loc_href()) ? loc_href().replace(/#.*/, hash) : loc_href() + hash | ||
} | ||
function rebase(path) { | ||
return base + '/' + trimSlashes(unbase(path)) | ||
function loc_href() { | ||
return document.location.href | ||
} | ||
function unbase(path) { | ||
if (path.slice(0, base.length) === base) { | ||
return path.slice(base.length) | ||
} else { | ||
return path | ||
} | ||
function pathFromHref(href) { | ||
return href.split('#')[1] ||'' | ||
} | ||
function trimSlashes(path) { | ||
return (path || '').replace(/^\/+/, '').replace(/\/+$/, '') | ||
function shouldIgnoreHref(href) { | ||
return !~href.indexOf('#') | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
/***/ }, | ||
/* 20 */ | ||
/* 23 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1010,3 +1174,3 @@ | ||
/***/ }, | ||
/* 21 */ | ||
/* 24 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1028,3 +1192,3 @@ | ||
/***/ }, | ||
/* 22 */ | ||
/* 25 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1042,45 +1206,5 @@ | ||
/***/ }, | ||
/* 23 */ | ||
/* 26 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var error = __webpack_require__(16) | ||
return { | ||
requestTimeout : function(req, res, next) { | ||
var responded | ||
, timeout = setTimeout(function() { | ||
responded = true | ||
res(null, error(408)) | ||
}, 30000) | ||
next(req, function(err, data) { | ||
clearTimeout(timeout) | ||
!responded && res(err, data) | ||
}) | ||
} | ||
, logger : function(log) { | ||
return function(req, res, next) { | ||
next(req, function(err, data) { | ||
if(data.statusCode == 302) log.debug(data.statusCode, req.uri, data.headers.location) | ||
if(data.statusCode >= 400) { | ||
log.debug(data.statusCode, 'address failed to load resource:', req.uri, req.method, data.body || '') | ||
} | ||
res(err, data) | ||
}) | ||
} | ||
} | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
/***/ }, | ||
/* 24 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(3) | ||
@@ -1094,19 +1218,20 @@ ], __WEBPACK_AMD_DEFINE_RESULT__ = function(nap) { | ||
/***/ }, | ||
/* 25 */ | ||
/* 27 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() { | ||
return function(location) { | ||
return { | ||
statusCode : 302 | ||
, headers : { | ||
location : location | ||
} | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function(require) { | ||
var uri = __webpack_require__(12) | ||
return function(location) { | ||
return { | ||
statusCode : 302 | ||
, headers : { | ||
location : uri(location, String).toString() | ||
} | ||
} | ||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
} | ||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
/***/ }, | ||
/* 26 */ | ||
/* 28 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1125,25 +1250,9 @@ | ||
/***/ }, | ||
/* 27 */ | ||
/* 29 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() { | ||
return function(query) { | ||
var params = Object.keys(query).reduce(function(a,k) { | ||
a.push(k + '=' + query[k]) | ||
return a | ||
},[]) | ||
return params.length ? '?' + params.join('&') : '' | ||
} | ||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) | ||
/***/ }, | ||
/* 28 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) { | ||
var dispatch = __webpack_require__(29) | ||
, redispatch = __webpack_require__(30) | ||
, rebind = __webpack_require__(18) | ||
var dispatch = __webpack_require__(30) | ||
, redispatch = __webpack_require__(31) | ||
, rebind = __webpack_require__(19) | ||
@@ -1170,3 +1279,3 @@ return function createStream() { | ||
/***/ }, | ||
/* 29 */ | ||
/* 30 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1176,3 +1285,3 @@ | ||
var _ = __webpack_require__(2) | ||
, dispatch = __webpack_require__(17) | ||
, dispatch = __webpack_require__(18).dispatch | ||
@@ -1225,4 +1334,5 @@ return function createDispatcher(/* types */) { | ||
/***/ }, | ||
/* 30 */ | ||
/* 31 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1232,3 +1342,3 @@ | ||
var _ = __webpack_require__(2) | ||
, dispatch = __webpack_require__(17) | ||
, dispatch = __webpack_require__(18).dispatch | ||
@@ -1239,6 +1349,6 @@ return function redispatch() { | ||
function redispatch() { | ||
var dispatch = dispatch.apply(null, dispatchers.reduce(types, [])) | ||
var dispatcher = dispatch.apply(null, dispatchers.reduce(types, [])) | ||
dispatchers.forEach(proxyEvents) | ||
return dispatch | ||
return dispatcher | ||
@@ -1248,3 +1358,3 @@ function proxyEvents(d) { | ||
function proxyEvent(type) { | ||
d.dispatcher.on(type + '.redispatch', dispatch[type]) | ||
d.dispatcher.on(type + '.redispatch', dispatcher[type]) | ||
} | ||
@@ -1279,2 +1389,3 @@ } | ||
/***/ } | ||
@@ -1281,0 +1392,0 @@ /******/ ]) |
{ | ||
"name": "@zambezi/address", | ||
"version": "2.1.0-real-urls.6", | ||
"version": "2.1.0", | ||
"description": "API for nap resources", | ||
@@ -18,3 +18,2 @@ "main": "lib/address.js", | ||
"sinon": "^1.14.1", | ||
"squirejs": "^0.2.1", | ||
"webpack": "^1.12.2" | ||
@@ -24,3 +23,2 @@ }, | ||
"test": "karma start --single-run", | ||
"test:debug": "karma start --debug", | ||
"prepublish": "npm run build", | ||
@@ -37,3 +35,2 @@ "build": "rimraf lib && webpack" | ||
"d3-dispatch": "^0.2.6", | ||
"lil-uri": "^0.2.0", | ||
"underscore": "^1.8.3" | ||
@@ -40,0 +37,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4
12
1087
1
89504
4
2
0
- Removedlil-uri@^0.2.0
- Removedlil-uri@0.2.2(transitive)