Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

message-box

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

message-box - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

4

CHANGELOG.md
# MessageBox Changelog
## 0.2.3
Removed `lodash` dependency in favor of `deep-extend` and `lodash.template`.
## 0.2.2

@@ -4,0 +8,0 @@

235

dist/MessageBox.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -8,40 +8,35 @@ Object.defineProperty(exports, "__esModule", {

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _lodash = require("lodash.template");
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 _lodash2 = _interopRequireDefault(_lodash);
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 _deepExtend = require("deep-extend");
var _merge = require('lodash/merge');
var _deepExtend2 = _interopRequireDefault(_deepExtend);
var _merge2 = _interopRequireDefault(_merge);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _template = require('lodash/template');
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
var _template2 = _interopRequireDefault(_template);
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Default lodash templates regexs
// https://regex101.com/r/ce27tA/5
var DEFAULT_INTERPOLATE = exports.DEFAULT_INTERPOLATE = /{{{([^\{\}#][\s\S]+?)}}}/g;
// https://regex101.com/r/8sRC8b/8
var DEFAULT_ESCAPE = exports.DEFAULT_ESCAPE = /{{([^\{\}#][\s\S]+?)}}/g;
// https://regex101.com/r/ndDqxg/4
var SUGGESTED_EVALUATE = exports.SUGGESTED_EVALUATE = /{{#([^\{\}].*?)}}/g;
const DEFAULT_INTERPOLATE = exports.DEFAULT_INTERPOLATE = /{{{([^{}#][\s\S]+?)}}}/g; // https://regex101.com/r/8sRC8b/8
var MessageBox = function () {
function MessageBox() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
escape = _ref.escape,
evaluate = _ref.evaluate,
initialLanguage = _ref.initialLanguage,
interpolate = _ref.interpolate,
messages = _ref.messages,
tracker = _ref.tracker;
const DEFAULT_ESCAPE = exports.DEFAULT_ESCAPE = /{{([^{}#][\s\S]+?)}}/g; // https://regex101.com/r/ndDqxg/4
_classCallCheck(this, MessageBox);
const SUGGESTED_EVALUATE = exports.SUGGESTED_EVALUATE = /{{#([^{}].*?)}}/g;
class MessageBox {
constructor({
escape,
evaluate,
initialLanguage,
interpolate,
messages,
tracker
} = {}) {
this.language = initialLanguage || MessageBox.language || 'en';

@@ -53,5 +48,5 @@ this.messageList = messages || {};

this.trackerDep = new tracker.Dependency();
}
} // Template options
// Template options
this.interpolate = interpolate || MessageBox.interpolate || DEFAULT_INTERPOLATE;

@@ -62,120 +57,104 @@ this.evaluate = evaluate || MessageBox.evaluate;

_createClass(MessageBox, [{
key: 'clone',
value: function clone() {
var copy = new MessageBox({
escape: this.escape,
evaluate: this.evaluate,
initialLanguage: this.language,
interpolate: this.interpolate,
tracker: this.tracker
});
copy.messages(this.messageList);
return copy;
clone() {
const copy = new MessageBox({
escape: this.escape,
evaluate: this.evaluate,
initialLanguage: this.language,
interpolate: this.interpolate,
tracker: this.tracker
});
copy.messages(this.messageList);
return copy;
}
getMessages(language) {
if (!language) {
language = this.language;
if (this.trackerDep) this.trackerDep.depend();
}
}, {
key: 'getMessages',
value: function getMessages(language) {
if (!language) {
language = this.language;
if (this.trackerDep) this.trackerDep.depend();
}
var globalMessages = MessageBox.messages[language];
const globalMessages = MessageBox.messages[language];
let messages = this.messageList[language];
var messages = this.messageList[language];
if (messages) {
if (globalMessages) messages = (0, _merge2.default)({}, globalMessages, messages);
} else {
messages = globalMessages;
}
if (messages) {
if (globalMessages) messages = (0, _deepExtend2.default)({}, globalMessages, messages);
} else {
messages = globalMessages;
}
if (!messages) throw new Error('No messages found for language "' + language + '"');
if (!messages) throw new Error(`No messages found for language "${language}"`);
return {
messages,
language
};
}
return {
messages: messages,
language: language
};
}
}, {
key: 'message',
value: function message(errorInfo) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
context = _ref2.context,
language = _ref2.language;
message(errorInfo, {
context,
language
} = {}) {
// Error objects can optionally include a preformatted message,
// in which case we use that.
if (errorInfo.message) return errorInfo.message;
const fieldName = errorInfo.name;
const genericName = MessageBox.makeNameGeneric(fieldName);
const {
messages
} = this.getMessages(language);
let message = messages[errorInfo.type];
// Error objects can optionally include a preformatted message,
// in which case we use that.
if (errorInfo.message) return errorInfo.message;
const fullContext = _objectSpread({
genericName
}, context, {}, errorInfo);
var fieldName = errorInfo.name;
var genericName = MessageBox.makeNameGeneric(fieldName);
if (message && typeof message === 'object') message = message[genericName] || message._default; // eslint-disable-line no-underscore-dangle
var _getMessages = this.getMessages(language),
messages = _getMessages.messages;
if (typeof message === 'string') {
message = (0, _lodash2.default)(message, {
interpolate: this.interpolate,
evaluate: this.evaluate,
escape: this.escape
});
}
var message = messages[errorInfo.type];
if (typeof message !== 'function') return `${fieldName} is invalid`;
return message(fullContext);
}
var fullContext = _extends({
genericName: genericName
}, context, errorInfo);
messages(messages) {
(0, _deepExtend2.default)(this.messageList, messages);
}
if (message && (typeof message === 'undefined' ? 'undefined' : _typeof(message)) === 'object') message = message[genericName] || message._default; // eslint-disable-line no-underscore-dangle
setLanguage(language) {
this.language = language;
if (this.trackerDep) this.trackerDep.changed();
}
if (typeof message === 'string') {
message = (0, _template2.default)(message, {
interpolate: this.interpolate,
evaluate: this.evaluate,
escape: this.escape
});
}
static makeNameGeneric(name) {
if (typeof name !== 'string') return null;
return name.replace(/\.[0-9]+(?=\.|$)/g, '.$');
}
if (typeof message !== 'function') return fieldName + ' is invalid';
static defaults({
escape,
evaluate,
initialLanguage,
interpolate,
messages
} = {}) {
if (typeof initialLanguage === 'string') MessageBox.language = initialLanguage;
if (interpolate instanceof RegExp) MessageBox.interpolate = interpolate;
if (evaluate instanceof RegExp) MessageBox.evaluate = evaluate;
if (escape instanceof RegExp) MessageBox.escape = escape;
return message(fullContext);
if (messages) {
if (!MessageBox.messages) MessageBox.messages = {};
(0, _deepExtend2.default)(MessageBox.messages, messages);
}
}, {
key: 'messages',
value: function messages(_messages) {
(0, _merge2.default)(this.messageList, _messages);
}
}, {
key: 'setLanguage',
value: function setLanguage(language) {
this.language = language;
if (this.trackerDep) this.trackerDep.changed();
}
}], [{
key: 'makeNameGeneric',
value: function makeNameGeneric(name) {
if (typeof name !== 'string') return null;
return name.replace(/\.[0-9]+(?=\.|$)/g, '.$');
}
}, {
key: 'defaults',
value: function defaults() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
escape = _ref3.escape,
evaluate = _ref3.evaluate,
initialLanguage = _ref3.initialLanguage,
interpolate = _ref3.interpolate,
messages = _ref3.messages;
}
if (typeof initialLanguage === 'string') MessageBox.language = initialLanguage;
}
if (interpolate instanceof RegExp) MessageBox.interpolate = interpolate;
if (evaluate instanceof RegExp) MessageBox.evaluate = evaluate;
if (escape instanceof RegExp) MessageBox.escape = escape;
_defineProperty(MessageBox, "messages", {});
if (messages) {
if (!MessageBox.messages) MessageBox.messages = {};
(0, _merge2.default)(MessageBox.messages, messages);
}
}
}]);
return MessageBox;
}();
MessageBox.messages = {};
exports.default = MessageBox;
{
"name": "message-box",
"version": "0.2.2",
"version": "0.2.3",
"description": "A package for defining and getting validation error messages, with support for Meteor Tracker reactivity",

@@ -16,30 +16,34 @@ "author": "Eric Dobbertin <aldeed@gmail.com>",

"files": [
"dist"
"dist",
"LICENSE",
"README.md"
],
"main": "./dist/MessageBox.js",
"scripts": {
"build": "rm -rf dist/** && babel lib --out-dir dist --ignore *.tests.js",
"build": "rm -rf dist/** && babel lib --out-dir dist --ignore 'lib/**/*.tests.js'",
"lint": "eslint .",
"lint:fix": "eslint . --fix || true",
"prepare": "npm run build",
"test": "mocha --require babel-core/register --recursive 'lib/**/*.tests.js'",
"prepublishOnly": "npm run build",
"test": "mocha --require @babel/register --recursive 'lib/**/*.tests.js'",
"test:watch": "npm test -- --watch"
},
"dependencies": {
"lodash": "^4.17.14"
"deep-extend": "^0.6.0",
"lodash.template": "^4.5.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^6.0.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"eslint": "^2.11.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.8.1",
"eslint-plugin-jsx-a11y": "^1.3.0",
"eslint-plugin-react": "^5.1.1",
"expect": "^1.20.1",
"mocha": "^6.0.2"
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@babel/register": "^7.9.0",
"babel-eslint": "^10.1.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-import-meta": "^1.0.1",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.2",
"expect": "^1.20.2",
"mocha": "^7.1.1"
}
}

Sorry, the diff of this file is not supported yet

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