Socket
Socket
Sign inDemoInstall

history

Package Overview
Dependencies
28
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.4.1

book.json

4

lib/Actions.js

@@ -9,8 +9,9 @@ /**

exports.PUSH = PUSH;
/**
* Indicates that navigation was caused by a call to history.replace.
*/
exports.PUSH = PUSH;
var REPLACE = 'REPLACE';
exports.REPLACE = REPLACE;
/**

@@ -24,3 +25,2 @@ * Indicates that navigation was caused by some other action such

*/
exports.REPLACE = REPLACE;
var POP = 'POP';

@@ -27,0 +27,0 @@

@@ -27,2 +27,4 @@ 'use strict';

var _createLocation2 = _interopRequireDefault(_createLocation);
/**

@@ -37,5 +39,2 @@ * Creates and returns a history object that uses HTML5's history API

*/
var _createLocation2 = _interopRequireDefault(_createLocation);
function createBrowserHistory(options) {

@@ -42,0 +41,0 @@ _invariant2['default'](_ExecutionEnvironment.canUseDOM, 'Browser history needs a DOM');

@@ -63,3 +63,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

var _createBrowserHistory = __webpack_require__(3);
var _createBrowserHistory = __webpack_require__(1);

@@ -82,3 +82,3 @@ var _createBrowserHistory2 = _interopRequireDefault(_createBrowserHistory);

var _createLocation2 = __webpack_require__(1);
var _createLocation2 = __webpack_require__(12);

@@ -95,3 +95,3 @@ var _createLocation3 = _interopRequireDefault(_createLocation2);

var _Actions2 = __webpack_require__(2);
var _Actions2 = __webpack_require__(3);

@@ -110,79 +110,2 @@ var _Actions3 = _interopRequireDefault(_Actions2);

var _Actions = __webpack_require__(2);
function createLocation() {
var path = arguments.length <= 0 || arguments[0] === undefined ? '/' : arguments[0];
var state = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var action = arguments.length <= 2 || arguments[2] === undefined ? _Actions.POP : arguments[2];
var key = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3];
var index = path.indexOf('?');
var pathname, search;
if (index !== -1) {
pathname = path.substring(0, index);
search = path.substring(index);
} else {
pathname = path;
search = '';
}
if (pathname === '') pathname = '/';
return {
pathname: pathname,
search: search,
state: state,
action: action,
key: key
};
}
exports['default'] = createLocation;
module.exports = exports['default'];
/***/ },
/* 2 */
/***/ function(module, exports) {
/**
* Indicates that navigation was caused by a call to history.push.
*/
'use strict';
exports.__esModule = true;
var PUSH = 'PUSH';
/**
* Indicates that navigation was caused by a call to history.replace.
*/
exports.PUSH = PUSH;
var REPLACE = 'REPLACE';
/**
* Indicates that navigation was caused by some other action such
* as using a browser's back/forward buttons and/or manually manipulating
* the URL in a browser's location bar. This is the default.
*
* See https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate
* for more information.
*/
exports.REPLACE = REPLACE;
var POP = 'POP';
exports.POP = POP;
exports['default'] = {
PUSH: PUSH,
REPLACE: REPLACE,
POP: POP
};
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -192,20 +115,22 @@

var _invariant = __webpack_require__(4);
var _invariant = __webpack_require__(2);
var _invariant2 = _interopRequireDefault(_invariant);
var _Actions = __webpack_require__(2);
var _Actions = __webpack_require__(3);
var _ExecutionEnvironment = __webpack_require__(5);
var _ExecutionEnvironment = __webpack_require__(4);
var _DOMUtils = __webpack_require__(6);
var _DOMUtils = __webpack_require__(5);
var _DOMStateStorage = __webpack_require__(7);
var _DOMStateStorage = __webpack_require__(6);
var _createDOMHistory = __webpack_require__(8);
var _createDOMHistory = __webpack_require__(7);
var _createDOMHistory2 = _interopRequireDefault(_createDOMHistory);
var _createLocation = __webpack_require__(1);
var _createLocation = __webpack_require__(12);
var _createLocation2 = _interopRequireDefault(_createLocation);
/**

@@ -220,5 +145,2 @@ * Creates and returns a history object that uses HTML5's history API

*/
var _createLocation2 = _interopRequireDefault(_createLocation);
function createBrowserHistory(options) {

@@ -326,3 +248,3 @@ _invariant2['default'](_ExecutionEnvironment.canUseDOM, 'Browser history needs a DOM');

/***/ },
/* 4 */
/* 2 */
/***/ function(module, exports, __webpack_require__) {

@@ -386,8 +308,44 @@

/***/ },
/* 5 */
/* 3 */
/***/ function(module, exports) {
/**
* Indicates that navigation was caused by a call to history.push.
*/
'use strict';
exports.__esModule = true;
var PUSH = 'PUSH';
exports.PUSH = PUSH;
/**
* Indicates that navigation was caused by a call to history.replace.
*/
var REPLACE = 'REPLACE';
exports.REPLACE = REPLACE;
/**
* Indicates that navigation was caused by some other action such
* as using a browser's back/forward buttons and/or manually manipulating
* the URL in a browser's location bar. This is the default.
*
* See https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate
* for more information.
*/
var POP = 'POP';
exports.POP = POP;
exports['default'] = {
PUSH: PUSH,
REPLACE: REPLACE,
POP: POP
};
/***/ },
/* 4 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);

@@ -397,3 +355,3 @@ exports.canUseDOM = canUseDOM;

/***/ },
/* 6 */
/* 5 */
/***/ function(module, exports) {

@@ -473,3 +431,3 @@

/***/ },
/* 7 */
/* 6 */
/***/ function(module, exports) {

@@ -507,3 +465,3 @@

/***/ },
/* 8 */
/* 7 */
/***/ function(module, exports, __webpack_require__) {

@@ -519,11 +477,11 @@

var _invariant = __webpack_require__(4);
var _invariant = __webpack_require__(2);
var _invariant2 = _interopRequireDefault(_invariant);
var _ExecutionEnvironment = __webpack_require__(5);
var _ExecutionEnvironment = __webpack_require__(4);
var _DOMUtils = __webpack_require__(6);
var _DOMUtils = __webpack_require__(5);
var _createHistory = __webpack_require__(9);
var _createHistory = __webpack_require__(8);

@@ -588,3 +546,3 @@ var _createHistory2 = _interopRequireDefault(_createHistory);

/***/ },
/* 9 */
/* 8 */
/***/ function(module, exports, __webpack_require__) {

@@ -600,13 +558,13 @@

var _invariant = __webpack_require__(4);
var _invariant = __webpack_require__(2);
var _invariant2 = _interopRequireDefault(_invariant);
var _deepEqual = __webpack_require__(10);
var _deepEqual = __webpack_require__(9);
var _deepEqual2 = _interopRequireDefault(_deepEqual);
var _Actions = __webpack_require__(2);
var _Actions = __webpack_require__(3);
var _createLocation = __webpack_require__(1);
var _createLocation = __webpack_require__(12);

@@ -809,8 +767,8 @@ var _createLocation2 = _interopRequireDefault(_createLocation);

/***/ },
/* 10 */
/* 9 */
/***/ function(module, exports, __webpack_require__) {
var pSlice = Array.prototype.slice;
var objectKeys = __webpack_require__(11);
var isArguments = __webpack_require__(12);
var objectKeys = __webpack_require__(10);
var isArguments = __webpack_require__(11);

@@ -910,3 +868,3 @@ var deepEqual = module.exports = function (actual, expected, opts) {

/***/ },
/* 11 */
/* 10 */
/***/ function(module, exports) {

@@ -926,3 +884,3 @@

/***/ },
/* 12 */
/* 11 */
/***/ function(module, exports) {

@@ -953,2 +911,43 @@

/***/ },
/* 12 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _Actions = __webpack_require__(3);
function createLocation() {
var path = arguments.length <= 0 || arguments[0] === undefined ? '/' : arguments[0];
var state = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var action = arguments.length <= 2 || arguments[2] === undefined ? _Actions.POP : arguments[2];
var key = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3];
var index = path.indexOf('?');
var pathname, search;
if (index !== -1) {
pathname = path.substring(0, index);
search = path.substring(index);
} else {
pathname = path;
search = '';
}
if (pathname === '') pathname = '/';
return {
pathname: pathname,
search: search,
state: state,
action: action,
key: key
};
}
exports['default'] = createLocation;
module.exports = exports['default'];
/***/ },
/* 13 */

@@ -969,19 +968,19 @@ /***/ function(module, exports, __webpack_require__) {

var _invariant = __webpack_require__(4);
var _invariant = __webpack_require__(2);
var _invariant2 = _interopRequireDefault(_invariant);
var _Actions = __webpack_require__(2);
var _Actions = __webpack_require__(3);
var _ExecutionEnvironment = __webpack_require__(5);
var _ExecutionEnvironment = __webpack_require__(4);
var _DOMUtils = __webpack_require__(6);
var _DOMUtils = __webpack_require__(5);
var _DOMStateStorage = __webpack_require__(7);
var _DOMStateStorage = __webpack_require__(6);
var _createDOMHistory = __webpack_require__(8);
var _createDOMHistory = __webpack_require__(7);
var _createDOMHistory2 = _interopRequireDefault(_createDOMHistory);
var _createLocation = __webpack_require__(1);
var _createLocation = __webpack_require__(12);

@@ -1232,13 +1231,13 @@ var _createLocation2 = _interopRequireDefault(_createLocation);

var _invariant = __webpack_require__(4);
var _invariant = __webpack_require__(2);
var _invariant2 = _interopRequireDefault(_invariant);
var _Actions = __webpack_require__(2);
var _Actions = __webpack_require__(3);
var _createLocation = __webpack_require__(1);
var _createLocation = __webpack_require__(12);
var _createLocation2 = _interopRequireDefault(_createLocation);
var _createHistory = __webpack_require__(9);
var _createHistory = __webpack_require__(8);

@@ -1245,0 +1244,0 @@ var _createHistory2 = _interopRequireDefault(_createHistory);

{
"name": "history",
"version": "1.4.0",
"version": "1.4.1",
"description": "A minimal, functional history implementation for JavaScript",

@@ -45,2 +45,3 @@ "main": "lib/index",

"mocha": "^2.0.1",
"rimraf": "^2.4.2",
"webpack": "^1.4.13",

@@ -47,0 +48,0 @@ "webpack-dev-server": "^1.10.1"

@@ -5,2 +5,4 @@ [![build status](https://img.shields.io/travis/rackt/history/master.svg?style=flat-square)](https://travis-ci.org/rackt/history)

## history
[`history`](https://www.npmjs.com/package/history) is a JavaScript library that lets you easily manage session history in browsers, testing environments, and (soon, via [React Native](https://facebook.github.io/react-native/)) native devices. `history` abstracts away the differences in these different platforms and provides a minimal API that lets you manage the history stack, navigate, confirm navigation, and persist state between sessions. `history` is library-agnostic and may easily be included in any JavaScript project.

@@ -12,12 +14,6 @@

### Getting Started
### Basic Usage
The first thing you'll need to do is create a history object. `history` provides several different `create*` methods that you can use depending on your environment.
A "history" encapsulates navigation between different screens in your app, and notifies listeners when the current screen changes.
- `createHistory` is for use in modern web browsers that support the [HTML5 history API](http://diveintohtml5.info/history.html)
- `createHashHistory` is for use in legacy web browsers (see [caniuse](http://caniuse.com/#feat=history) for compatibility)
- `createMemoryHistory` is used mainly for testing and does not persist across sessions
Once you get a `history` object, use `history.listen` to be notified when the `location` changes.
```js

@@ -34,2 +30,4 @@ import { createHistory } from 'history';

history.pushState({ the: 'state' }, '/the/path?a=query');
// When you're finished, stop the listener.

@@ -39,111 +37,4 @@ unlisten();

### Location
Read more about getting started [in the documentation](http://rackt.github.io/history/stable/GettingStarted.html)!
A `location` object is conceptually similar to [`document.location` in web browsers](https://developer.mozilla.org/en-US/docs/Web/API/Document/location), with a few extra goodies. `location` objects have the following properties:
```
pathname The pathname portion of the URL, without query string
search The query string portion of the URL, including the ?
state An object of data tied to this location
action One of PUSH, REPLACE, or POP
key A unique identifier for this location
```
Support for query string parsing is provided using the [`enableQueries` module](#query-support).
If you'd like, you can create a `location` object programmatically using `createLocation`.
```js
import { createLocation } from 'history';
var location = createLocation('/a/path?a=query', { some: 'state' });
```
### Navigation
You can also use a `history` object to programmatically change the current `location` using the following methods:
- `pushState(state, path)`
- `replaceState(state, path)`
- `setState(state)`
- `go(n)`
- `goBack()`
- `goForward()`
The `path` argument to `pushState` and `replaceState` represents a complete URL path, including the query string. The `state` argument should be a JSON-serializable object. In `setState`, the properties in `state` are shallowly merged into the current state.
```js
// Push a new entry onto the history stack.
history.pushState({ some: 'state' }, '/home');
// Replace the current entry on the history stack.
history.replaceState({ some: 'other state' }, '/profile');
// Go back to the previous history entry. The following
// two lines are synonymous.
history.go(-1);
history.goBack();
```
### Confirming Navigation
Sometimes you may want to prevent the user from going to a different page. For example, if they are halfway finished filling out a long form, and they click the back button (or try to close the tab), you may want to prompt them to confirm they actually want to leave the page before they lose the information they've already entered. For these cases, `history` lets you register transition hooks that return a prompt message you can show the user before the location changes. For example, you could do something like this:
```js
history.registerTransitionHook(function () {
if (input.value !== '')
return 'Are you sure you want to leave this page?';
});
```
You can also simply `return false` to prevent a transition.
In browsers, `history` uses [`window.confirm`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm) by default to display confirmation messages to users. However, you can provide your own custom confirmation dialog box using the `getUserConfirmation` hook when you create your `history` object.
```js
var history = createHistory({
getUserConfirmation: function (message, callback) {
callback(window.confirm(message)); // The default
}
});
```
### Query Support
Support for parsing and serializing URL queries is provided by the `enableQueries` function. Simply wrap your `history` object and you'll have a parsed `location.query` object inside `listen`.
```js
import { createHistory, enableQueries } from 'history';
var history = enableQueries(createHistory());
history.listen(function (location) {
console.log(location.query);
});
```
Query-enabled histories also accept URL queries as trailing arguments to `pushState`, `replaceState`, and `createHref`.
```js
history.pushState(null, '/the/path', { the: 'query' }); // /the/path?the=query
```
### Caveats of Hash History
Using `window.location.hash` is a common trick that is used to mimic the HTML5 history API in older browsers. It works for most use cases and provides good compatibility across a wide range of browsers. However, in order to preserve state across browser sessions we need a place to store some state. HTML5 gives us the `pushState` method and the `popstate` event, but in older browsers the only thing we have is the URL. So, when using hash history, you'll see an extra item in your query string that looks something like `_k=123abc`. This is a key that `history` uses to look up persistent state data in `window.sessionStorage` between page loads. If you prefer to use a different query parameter, or to opt-out of this behavior entirely, use the `queryKey` configuration option.
```js
// Use _key instead of _k.
var history = createHashHistory({
queryKey: '_key'
});
// Opt-out of persistent state, not recommended.
var history = createHashHistory({
queryKey: false
});
```
One other thing to keep in mind when using hash history is that you cannot also use `window.location.hash` as it was originally intended, to link an anchor point within your HTML document.
### Thanks

@@ -150,0 +41,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc