New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redux-logger

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-logger - npm Package Compare versions

Comparing version 3.0.1 to 3.0.6

dist/redux-logger.js

67

package.json
{
"name": "redux-logger",
"version": "3.0.1",
"version": "3.0.6",
"description": "Logger for Redux",
"main": "lib/index.js",
"main": "dist/redux-logger.js",
"scripts": {
"lint": "$(npm bin)/eslint src",
"test": "NODE_ENV=development npm run lint && npm run spec",
"test:production": "NODE_ENV=production npm run lint && npm run spec",
"spec": "NODE_PATH=src nyc --all --silent --require babel-core/register mocha --plugins transform-inline-environment-variables --recursive spec/*.spec.js",
"spec:watch": "NODE_ENV=development npm run spec -- --watch",
"lint": "eslint src",
"test": "npm run lint && npm run spec",
"spec": "nyc --all --silent --require babel-core/register mocha --plugins transform-inline-environment-variables --recursive spec/*.spec.js",
"spec:watch": "npm run spec -- --watch",
"coverage": "nyc report",
"coverage:html": "nyc report --reporter=html && (http-server -p 8077 ./coverage & open-url http://localhost:8077/)",
"coverage:html": "nyc report --reporter=html && http-server -p 8077 ./coverage -o",
"coverage:production": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"clean": "$(npm bin)/rimraf dist lib",
"build:lib": "$(npm bin)/babel src --out-dir lib",
"build:umd": "LIBRARY_NAME=reduxLogger NODE_ENV=development $(npm bin)/webpack src/index.js dist/index.js --config webpack.build.js",
"build:umd:min": "LIBRARY_NAME=reduxLogger NODE_ENV=production $(npm bin)/webpack -p src/index.js dist/index.min.js --config webpack.build.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
"precommit": "npm run test",
"prepublish": "npm run clean && npm run test:production && npm run build"
"clean": "rimraf dist",
"build": "rollup -c",
"precommit": "npm test",
"prepublish": "npm run clean && npm test && npm run build"
},
"eslintConfig": {
"extends": "airbnb",
"rules": {
"no-console": "off"
},
"env": {
"browser": true,
"mocha": true
}
},
"nyc": {

@@ -30,3 +36,4 @@ "exclude": [

"dist",
"webpack.*.js"
"coverage",
"rollup.config.js"
]

@@ -36,3 +43,2 @@ },

"dist",
"lib",
"src"

@@ -57,17 +63,13 @@ ],

"devDependencies": {
"@dtrussia/eslint-config-dtrussia": "2.2.1",
"babel-cli": "^6.24.0",
"babel-core": "^6.24.0",
"babel-eslint": "7.1.1",
"babel-loader": "^6.4.1",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-transform-es2015-modules-umd": "6.24.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-inline-environment-variables": "6.8.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.22.0",
"chai": "3.5.0",
"codecov": "1.0.1",
"eslint": "3.10.2",
"eslint-plugin-react": "6.7.1",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"http-server": "0.9.0",

@@ -77,11 +79,14 @@ "husky": "^0.13.2",

"nyc": "9.0.1",
"open-url": "2.0.2",
"redux": "^3.6.0",
"rimraf": "^2.6.1",
"sinon": "^1.17.7",
"webpack": "1.13.3"
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^1.0.2",
"sinon": "^1.17.7"
},
"dependencies": {
"deep-diff": "0.3.4"
"deep-diff": "^0.3.5"
}
}

@@ -243,3 +243,3 @@ # Logger for Redux

```javascript
import createLogger from 'redux-logger';
import { createLogger } from 'redux-logger';

@@ -285,4 +285,3 @@ const actionTransformer = action => {

## To Do
- [ ] Update example to [create-react-app](https://github.com/facebookincubator/create-react-app)
- [ ] Update eslint config to [airbnb's](https://www.npmjs.com/package/eslint-config-airbnb)
- [x] Update eslint config to [airbnb's](https://www.npmjs.com/package/eslint-config-airbnb)
- [ ] Clean up code, because it's very messy, to be honest

@@ -289,0 +288,0 @@ - [ ] Write tests

@@ -16,5 +16,5 @@ import { formatTime } from './helpers';

switch (typeof level) {
case `object`:
return typeof level[type] === `function` ? level[type](...payload) : level[type];
case `function`:
case 'object':
return typeof level[type] === 'function' ? level[type](...payload) : level[type];
case 'function':
return level(action);

@@ -27,9 +27,6 @@ default:

function defaultTitleFormatter(options) {
const {
timestamp,
duration,
} = options;
const { timestamp, duration } = options;
return (action, time, took) => {
const parts = [`action`];
const parts = ['action'];

@@ -40,7 +37,7 @@ parts.push(`%c${String(action.type)}`);

return parts.join(` `);
return parts.join(' ');
};
}
export function printBuffer(buffer, options) {
function printBuffer(buffer, options) {
const {

@@ -56,3 +53,3 @@ logger,

const isUsingDefaultFormatter = typeof options.titleFormatter === `undefined`;
const isUsingDefaultFormatter = typeof options.titleFormatter === 'undefined';

@@ -71,10 +68,12 @@ buffer.forEach((logEntry, key) => {

const formattedAction = actionTransformer(action);
const isCollapsed = (typeof collapsed === `function`) ? collapsed(() => nextState, action, logEntry) : collapsed;
const isCollapsed = typeof collapsed === 'function'
? collapsed(() => nextState, action, logEntry)
: collapsed;
const formattedTime = formatTime(startedTime);
const titleCSS = colors.title ? `color: ${colors.title(formattedAction)};` : ``;
const headerCSS = [`color: gray; font-weight: lighter;`];
const titleCSS = colors.title ? `color: ${colors.title(formattedAction)};` : '';
const headerCSS = ['color: gray; font-weight: lighter;'];
headerCSS.push(titleCSS);
if (options.timestamp) headerCSS.push(`color: gray; font-weight: lighter;`);
if (options.duration) headerCSS.push(`color: gray; font-weight: lighter;`);
if (options.timestamp) headerCSS.push('color: gray; font-weight: lighter;');
if (options.duration) headerCSS.push('color: gray; font-weight: lighter;');
const title = titleFormatter(formattedAction, formattedTime, took);

@@ -85,7 +84,9 @@

if (isCollapsed) {
if (colors.title && isUsingDefaultFormatter) logger.groupCollapsed(`%c ${title}`, ...headerCSS);
else logger.groupCollapsed(title);
if (colors.title && isUsingDefaultFormatter) {
logger.groupCollapsed(`%c ${title}`, ...headerCSS);
} else logger.groupCollapsed(title);
} else if (colors.title && isUsingDefaultFormatter) {
logger.group(`%c ${title}`, ...headerCSS);
} else {
if (colors.title && isUsingDefaultFormatter) logger.group(`%c ${title}`, ...headerCSS);
else logger.group(title);
logger.group(title);
}

@@ -96,25 +97,37 @@ } catch (e) {

const prevStateLevel = getLogLevel(level, formattedAction, [prevState], `prevState`);
const actionLevel = getLogLevel(level, formattedAction, [formattedAction], `action`);
const errorLevel = getLogLevel(level, formattedAction, [error, prevState], `error`);
const nextStateLevel = getLogLevel(level, formattedAction, [nextState], `nextState`);
const prevStateLevel = getLogLevel(level, formattedAction, [prevState], 'prevState');
const actionLevel = getLogLevel(level, formattedAction, [formattedAction], 'action');
const errorLevel = getLogLevel(level, formattedAction, [error, prevState], 'error');
const nextStateLevel = getLogLevel(level, formattedAction, [nextState], 'nextState');
if (prevStateLevel) {
if (colors.prevState) logger[prevStateLevel](`%c prev state`, `color: ${colors.prevState(prevState)}; font-weight: bold`, prevState);
else logger[prevStateLevel](`prev state`, prevState);
if (colors.prevState) {
const styles = `color: ${colors.prevState(prevState)}; font-weight: bold`;
logger[prevStateLevel]('%c prev state', styles, prevState);
} else logger[prevStateLevel]('prev state', prevState);
}
if (actionLevel) {
if (colors.action) logger[actionLevel](`%c action `, `color: ${colors.action(formattedAction)}; font-weight: bold`, formattedAction);
else logger[actionLevel](`action `, formattedAction);
if (colors.action) {
const styles = `color: ${colors.action(formattedAction)}; font-weight: bold`;
logger[actionLevel]('%c action ', styles, formattedAction);
} else logger[actionLevel]('action ', formattedAction);
}
if (error && errorLevel) {
if (colors.error) logger[errorLevel](`%c error `, `color: ${colors.error(error, prevState)}; font-weight: bold;`, error);
else logger[errorLevel](`error `, error);
if (colors.error) {
const styles = `color: ${colors.error(error, prevState)}; font-weight: bold;`;
logger[errorLevel]('%c error ', styles, error);
} else logger[errorLevel]('error ', error);
}
if (nextStateLevel) {
if (colors.nextState) logger[nextStateLevel](`%c next state`, `color: ${colors.nextState(nextState)}; font-weight: bold`, nextState);
else logger[nextStateLevel](`next state`, nextState);
if (colors.nextState) {
const styles = `color: ${colors.nextState(nextState)}; font-weight: bold`;
logger[nextStateLevel]('%c next state', styles, nextState);
} else logger[nextStateLevel]('next state', nextState);
}

@@ -129,5 +142,7 @@

} catch (e) {
logger.log(`—— log end ——`);
logger.log('—— log end ——');
}
});
}
export default printBuffer;
export default {
level: `log`,
level: 'log',
logger: console,

@@ -13,7 +13,7 @@ logErrors: true,

colors: {
title: () => `inherit`,
prevState: () => `#9E9E9E`,
action: () => `#03A9F4`,
nextState: () => `#4CAF50`,
error: () => `#F20404`,
title: () => 'inherit',
prevState: () => '#9E9E9E',
action: () => '#03A9F4',
nextState: () => '#4CAF50',
error: () => '#F20404',
},

@@ -20,0 +20,0 @@ diff: false,

@@ -5,36 +5,36 @@ import differ from 'deep-diff';

const dictionary = {
'E': {
color: `#2196F3`,
text: `CHANGED:`,
E: {
color: '#2196F3',
text: 'CHANGED:',
},
'N': {
color: `#4CAF50`,
text: `ADDED:`,
N: {
color: '#4CAF50',
text: 'ADDED:',
},
'D': {
color: `#F44336`,
text: `DELETED:`,
D: {
color: '#F44336',
text: 'DELETED:',
},
'A': {
color: `#2196F3`,
text: `ARRAY:`,
A: {
color: '#2196F3',
text: 'ARRAY:',
},
};
function style(kind) {
export function style(kind) {
return `color: ${dictionary[kind].color}; font-weight: bold`;
}
function render(diff) {
export function render(diff) {
const { kind, path, lhs, rhs, index, item } = diff;
switch (kind) {
case `E`:
return [path.join(`.`), lhs, `→`, rhs];
case `N`:
return [path.join(`.`), rhs];
case `D`:
return [path.join(`.`)];
case `A`:
return [`${path.join(`.`)}[${index}]`, item];
case 'E':
return [path.join('.'), lhs, '→', rhs];
case 'N':
return [path.join('.'), rhs];
case 'D':
return [path.join('.')];
case 'A':
return [`${path.join('.')}[${index}]`, item];
default:

@@ -50,8 +50,8 @@ return [];

if (isCollapsed) {
logger.groupCollapsed(`diff`);
logger.groupCollapsed('diff');
} else {
logger.group(`diff`);
logger.group('diff');
}
} catch (e) {
logger.log(`diff`);
logger.log('diff');
}

@@ -67,3 +67,3 @@

} else {
logger.log(`—— no diff ——`);
logger.log('—— no diff ——');
}

@@ -74,4 +74,4 @@

} catch (e) {
logger.log(`—— diff end —— `);
logger.log('—— diff end —— ');
}
}
export const repeat = (str, times) => (new Array(times + 1)).join(str);
export const pad = (num, maxLength) => repeat(`0`, maxLength - num.toString().length) + num;
export const pad = (num, maxLength) => repeat('0', maxLength - num.toString().length) + num;
export const formatTime = (time) => `${pad(time.getHours(), 2)}:${pad(time.getMinutes(), 2)}:${pad(time.getSeconds(), 2)}.${pad(time.getMilliseconds(), 3)}`;
export const formatTime = time => `${pad(time.getHours(), 2)}:${pad(time.getMinutes(), 2)}:${pad(time.getSeconds(), 2)}.${pad(time.getMilliseconds(), 3)}`;
// Use performance API if it's available in order to get better precision
export const timer = (typeof performance !== `undefined` && performance !== null) && typeof performance.now === `function` ? performance : Date;
export const timer =
(typeof performance !== 'undefined' && performance !== null) && typeof performance.now === 'function' ?
performance :
Date;

@@ -1,5 +0,5 @@

import { printBuffer } from './core';
import printBuffer from './core';
import { timer } from './helpers';
import defaults from './defaults';
/* eslint max-len: ["error", 110, { "ignoreComments": true }] */
/**

@@ -25,6 +25,3 @@ * Creates logger with following options

function createLogger(options = {}) {
const loggerOptions = {
...defaults,
...options,
};
const loggerOptions = Object.assign({}, defaults, options);

@@ -41,3 +38,3 @@ const {

// Return if 'console' object is not defined
if (typeof logger === `undefined`) {
if (typeof logger === 'undefined') {
return () => next => action => next(action);

@@ -72,5 +69,5 @@ }

return ({ getState }) => (next) => (action) => {
return ({ getState }) => next => (action) => {
// Exit early if predicate function returns 'false'
if (typeof predicate === `function` && !predicate(getState, action)) {
if (typeof predicate === 'function' && !predicate(getState, action)) {
return next(action);

@@ -102,5 +99,7 @@ }

const diff = loggerOptions.diff && typeof diffPredicate === `function` ? diffPredicate(getState, action) : loggerOptions.diff;
const diff = loggerOptions.diff && typeof diffPredicate === 'function'
? diffPredicate(getState, action)
: loggerOptions.diff;
printBuffer(logBuffer, { ...loggerOptions, diff });
printBuffer(logBuffer, Object.assign({}, loggerOptions, { diff }));
logBuffer.length = 0;

@@ -113,8 +112,9 @@

// eslint-disable-next-line consistent-return
const defaultLogger = ({ dispatch, getState } = {}) => {
if (typeof dispatch === `function` || typeof getState === `function`) {
if (typeof dispatch === 'function' || typeof getState === 'function') {
return createLogger()({ dispatch, getState });
} else {
// eslint-disable-next-line no-console
console.error(`
}
// eslint-disable-next-line no-console
console.error(`
[redux-logger v3] BREAKING CHANGE

@@ -127,11 +127,6 @@ [redux-logger v3] Since 3.0.0 redux-logger exports by default logger with default settings.

`);
}
};
export {
defaults,
createLogger,
defaultLogger as logger,
};
export { defaults, createLogger, defaultLogger as logger };
export default defaultLogger;
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc