react-cookie
Advanced tools
Comparing version 2.2.0 to 3.0.0
@@ -1,53 +0,1 @@ | ||
import * as React from 'react'; | ||
export type Cookie = string; | ||
export class Cookies { | ||
constructor( | ||
cookieHeader?: string | object | null, | ||
hooks?: { | ||
onSet: (name: string, value: string, options?: ReactCookieSetOptions) => void; | ||
onRemove: (name: string, options?: ReactCookieRemoveOptions) => void; | ||
}, | ||
); | ||
get: (key: string, options?: ReactCookieGetOptions) => Cookie | undefined; | ||
getAll: (options?: ReactCookieGetAllOptions) => Cookie[]; | ||
set(name: string, value: string, options?: ReactCookieSetOptions): void; | ||
remove(name: string, options?: ReactCookieRemoveOptions): void; | ||
} | ||
export class CookiesProvider extends React.Component<ReactCookieProps, any> {} | ||
type Diff<T, U> = T extends U ? never : T; | ||
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>; | ||
export declare function withCookies<T extends ReactCookieProps>(Component: React.ComponentType<T>): React.ComponentType<Omit<T, keyof ReactCookieProps>>; | ||
export interface ReactCookieGetOptions { | ||
doNotParse?: boolean; | ||
} | ||
export interface ReactCookieGetAllOptions { | ||
doNotParse?: boolean; | ||
} | ||
export interface ReactCookieSetOptions { | ||
path?: string; | ||
expires?: Date; | ||
maxAge?: number; | ||
domain?: string; | ||
secure?: boolean; | ||
httpOnly?: boolean; | ||
} | ||
export interface ReactCookieRemoveOptions { | ||
path?: string; | ||
expires?: Date; | ||
maxAge?: number; | ||
domain?: string; | ||
secure?: boolean; | ||
httpOnly?: boolean; | ||
} | ||
export type ReactCookieProps = { | ||
cookies?: Cookies | ||
}; | ||
export * from './lib'; |
@@ -1,14 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _universalCookie = require('universal-cookie'); | ||
var _universalCookie2 = _interopRequireDefault(_universalCookie); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = _universalCookie2.default; | ||
module.exports = exports['default']; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var universal_cookie_1 = require("universal-cookie"); | ||
exports.default = universal_cookie_1.default; |
@@ -1,66 +0,36 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _react = require('react'); | ||
var _propTypes = require('prop-types'); | ||
var _universalCookie = require('universal-cookie'); | ||
var _universalCookie2 = _interopRequireDefault(_universalCookie); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var CookiesProvider = function (_Component) { | ||
_inherits(CookiesProvider, _Component); | ||
function CookiesProvider(props) { | ||
_classCallCheck(this, CookiesProvider); | ||
var _this = _possibleConstructorReturn(this, (CookiesProvider.__proto__ || Object.getPrototypeOf(CookiesProvider)).call(this, props)); | ||
if (props.cookies) { | ||
_this.cookies = props.cookies; | ||
} else { | ||
_this.cookies = new _universalCookie2.default(); | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return _this; | ||
} | ||
_createClass(CookiesProvider, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
return { | ||
cookies: this.cookies | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var React = require("react"); | ||
var universal_cookie_1 = require("universal-cookie"); | ||
var CookiesContext_1 = require("./CookiesContext"); | ||
var CookiesProvider = /** @class */ (function (_super) { | ||
__extends(CookiesProvider, _super); | ||
function CookiesProvider(props) { | ||
var _this = _super.call(this, props) || this; | ||
if (props.cookies) { | ||
_this.cookies = props.cookies; | ||
} | ||
else { | ||
_this.cookies = new universal_cookie_1.default(); | ||
} | ||
return _this; | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return this.props.children; | ||
} | ||
}]); | ||
return CookiesProvider; | ||
}(_react.Component); | ||
CookiesProvider.propTypes = { | ||
children: _propTypes.node, | ||
cookies: (0, _propTypes.instanceOf)(_universalCookie2.default) | ||
}; | ||
CookiesProvider.childContextTypes = { | ||
cookies: (0, _propTypes.instanceOf)(_universalCookie2.default).isRequired | ||
}; | ||
CookiesProvider.prototype.render = function () { | ||
return (React.createElement(CookiesContext_1.Provider, { value: this.cookies }, this.props.children)); | ||
}; | ||
return CookiesProvider; | ||
}(React.Component)); | ||
exports.default = CookiesProvider; | ||
module.exports = exports['default']; |
@@ -1,34 +0,8 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _Cookies = require('./Cookies'); | ||
Object.defineProperty(exports, 'Cookies', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_Cookies).default; | ||
} | ||
}); | ||
var _CookiesProvider = require('./CookiesProvider'); | ||
Object.defineProperty(exports, 'CookiesProvider', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_CookiesProvider).default; | ||
} | ||
}); | ||
var _withCookies = require('./withCookies'); | ||
Object.defineProperty(exports, 'withCookies', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_withCookies).default; | ||
} | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Cookies_1 = require("./Cookies"); | ||
exports.Cookies = Cookies_1.default; | ||
var CookiesProvider_1 = require("./CookiesProvider"); | ||
exports.CookiesProvider = CookiesProvider_1.default; | ||
var withCookies_1 = require("./withCookies"); | ||
exports.withCookies = withCookies_1.default; |
@@ -1,91 +0,86 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: 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; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
exports.default = withCookies; | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _propTypes = require('prop-types'); | ||
var _universalCookie = require('universal-cookie'); | ||
var _universalCookie2 = _interopRequireDefault(_universalCookie); | ||
var _hoistNonReactStatics = require('hoist-non-react-statics'); | ||
var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var React = require("react"); | ||
// @ts-ignore | ||
var hoistStatics = require("hoist-non-react-statics"); | ||
var CookiesContext_1 = require("./CookiesContext"); | ||
function withCookies(WrapperComponent) { | ||
var Wrapper = function (_Component) { | ||
_inherits(Wrapper, _Component); | ||
function Wrapper(props, context) { | ||
_classCallCheck(this, Wrapper); | ||
var _this = _possibleConstructorReturn(this, (Wrapper.__proto__ || Object.getPrototypeOf(Wrapper)).call(this, props)); | ||
_this.onChange = function () { | ||
_this.forceUpdate(); | ||
}; | ||
context.cookies.addChangeListener(_this.onChange); | ||
return _this; | ||
} | ||
_createClass(Wrapper, [{ | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this.context.cookies.removeChangeListener(this.onChange); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _props = this.props, | ||
wrappedComponentRef = _props.wrappedComponentRef, | ||
remainingProps = _objectWithoutProperties(_props, ['wrappedComponentRef']); | ||
var allCookies = this.context.cookies.getAll(); | ||
return _react2.default.createElement(WrapperComponent, _extends({}, remainingProps, { | ||
cookies: this.context.cookies, | ||
allCookies: allCookies, | ||
ref: wrappedComponentRef | ||
})); | ||
} | ||
}]); | ||
return Wrapper; | ||
}(_react.Component); | ||
Wrapper.displayName = 'withCookies(' + (_react.Component.displayName || _react.Component.name) + ')'; | ||
Wrapper.WrapperComponent = WrapperComponent; | ||
Wrapper.propTypes = { | ||
wrappedComponentRef: _propTypes.func | ||
}; | ||
Wrapper.contextTypes = { | ||
cookies: (0, _propTypes.instanceOf)(_universalCookie2.default).isRequired | ||
}; | ||
return (0, _hoistNonReactStatics2.default)(Wrapper, WrapperComponent, { WrappedComponent: true }); | ||
// @ts-ignore | ||
var name = WrapperComponent.displayName || WrapperComponent.name; | ||
var CookieWrapper = /** @class */ (function (_super) { | ||
__extends(CookieWrapper, _super); | ||
function CookieWrapper() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.onChange = function () { | ||
// Make sure to update children with new values | ||
_this.forceUpdate(); | ||
}; | ||
return _this; | ||
} | ||
CookieWrapper.prototype.listen = function (cookies) { | ||
if (cookies !== this.cookies) { | ||
this.unlisten(); | ||
this.cookies = cookies; | ||
this.cookies.addChangeListener(this.onChange); | ||
} | ||
}; | ||
CookieWrapper.prototype.unlisten = function () { | ||
if (this.cookies) { | ||
this.cookies.removeChangeListener(this.onChange); | ||
} | ||
}; | ||
CookieWrapper.prototype.componentWillUnmount = function () { | ||
this.unlisten(); | ||
}; | ||
CookieWrapper.prototype.render = function () { | ||
var _this = this; | ||
return (React.createElement(CookiesContext_1.Consumer, null, function (cookies) { | ||
_this.listen(cookies); | ||
var _a = _this.props, forwardedRef = _a.forwardedRef, restProps = __rest(_a, ["forwardedRef"]); | ||
var allCookies = cookies.getAll(); | ||
return (React.createElement(WrapperComponent, __assign({}, restProps, { ref: forwardedRef, cookies: cookies, allCookies: allCookies }))); | ||
})); | ||
}; | ||
CookieWrapper.displayName = "withCookies(" + name + ")"; | ||
CookieWrapper.WrapperComponent = WrapperComponent; | ||
return CookieWrapper; | ||
}(React.Component)); | ||
var CookieWrapperWithRef = React.forwardRef(function (props, ref) { | ||
return React.createElement(CookieWrapper, __assign({}, props, { forwardedRef: ref })); | ||
}); | ||
return hoistStatics(CookieWrapperWithRef, WrapperComponent, { WrappedComponent: true }); | ||
} | ||
module.exports = exports['default']; | ||
exports.default = withCookies; |
{ | ||
"name": "react-cookie", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Universal cookies for React", | ||
"main": "lib/index.js", | ||
"typings": "index.d.ts", | ||
"files": [ | ||
@@ -26,18 +25,19 @@ "lib", | ||
"scripts": { | ||
"build": "rimraf lib && babel src -d lib --ignore __tests__" | ||
"build": "rimraf lib && tsc --jsx react" | ||
}, | ||
"dependencies": { | ||
"hoist-non-react-statics": "^2.3.1", | ||
"prop-types": "^15.0.0", | ||
"universal-cookie": "^2.2.0" | ||
"@types/hoist-non-react-statics": "^3.0.1", | ||
"hoist-non-react-statics": "^3.0.0", | ||
"prop-types": "^15.6.2", | ||
"universal-cookie": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"react": "^15.0.0", | ||
"react-dom": "^15.0.0", | ||
"rimraf": "^2.6.1" | ||
"react": "^16.3.0", | ||
"react-dom": "^16.3.0", | ||
"rimraf": "^2.6.1", | ||
"typescript": "^3.0.1" | ||
}, | ||
"peerDependencies": { | ||
"react": ">= 15" | ||
"react": ">= 16.3.0" | ||
} | ||
} |
@@ -215,3 +215,3 @@ <h3 align="center"> | ||
// server.js | ||
require('babel-register'); | ||
require('@babel/register'); | ||
@@ -218,0 +218,0 @@ const express = require('express'); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
15
14558
5
173
1
+ Added@types/cookie@0.3.3(transitive)
+ Added@types/hoist-non-react-statics@3.3.5(transitive)
+ Added@types/object-assign@4.0.33(transitive)
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@18.3.12(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addedhoist-non-react-statics@3.3.2(transitive)
+ Addeduniversal-cookie@3.1.0(transitive)
- Removedhoist-non-react-statics@2.5.5(transitive)
- Removeduniversal-cookie@2.2.0(transitive)
Updatedprop-types@^15.6.2
Updateduniversal-cookie@^3.0.0