Socket
Socket
Sign inDemoInstall

melody-runtime

Package Overview
Dependencies
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

melody-runtime - npm Package Compare versions

Comparing version 1.2.0-commit.39a4cc79 to 1.2.0-commit.39e381df

src/async.js

148

lib/index.esm.js

@@ -13,2 +13,3 @@ import _isString from 'lodash/isString';

import _isNumber from 'lodash/isNumber';
import { enqueueComponent, link } from 'melody-idom';

@@ -67,3 +68,3 @@ /**

var value = attrMap[attr];
attrArray.push(attr, value === false || value === null || value === 0 || value === '' ? undefined : value);
attrArray.push(attr, value === false || value === null || value === 0 || value === '' && attr !== 'alt' ? undefined : value);
}

@@ -764,2 +765,33 @@ return attrArray;

function trim(str, charList) {
var side = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'both';
if (charList === undefined && side === 'both') {
// Use String.prototype.trim() for efficiency
return String(str).trim();
}
if (side !== 'both' && side !== 'left' && side !== 'right') {
throw new Error('Filter "trim". Invalid value ' + side + ' for parameter "side". Valid values are "both", "left", "right".');
}
var strLen = str.length;
var trimStart = 0;
if (side === 'both' || side === 'left') {
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) {
trimStart++;
}
}
var trimEnd = strLen;
if (side === 'both' || side === 'right') {
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) {
trimEnd--;
}
}
return str.substr(trimStart, trimEnd - trimStart);
}
var MAX_SAFE_INTEGER = 'MAX_SAFE_INTEGER' in Number ? Number.MAX_SAFE_INTEGER : 9007199254740991;

@@ -865,2 +897,114 @@

var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
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 AsyncComponent = function () {
function AsyncComponent() {
classCallCheck(this, AsyncComponent);
this.promisedComponent = null;
this._el = null;
this.refs = Object.create(null);
this.props = null;
this.resolvedComponent = null;
this.alreadyUnmounted = false;
this.isLoading = false;
this.loadingError = null;
}
AsyncComponent.prototype.apply = function apply(props) {
var _this = this;
this.props = props;
var promisedComponent = props.promisedComponent;
// if we already have resolved the component, just pass the data forward
if (this.resolvedComponent) {
this.resolvedComponent.apply(this.props.data);
}
// otherwise
if (!this.isLoading) {
this.isLoading = true;
promisedComponent().then(function (_ref) {
var Component = _ref.default;
if (_this.alreadyUnmounted) {
return;
}
_this.resolvedComponent = new Component();
link(_this, _this.resolvedComponent);
_this.resolvedComponent.el = _this._el;
_this.resolvedComponent.apply(_this.props.data);
}, function (err) {
// fail early
_this.loadingError = err;
enqueueComponent(_this);
}).catch(function (err) {
// just in case something went wrong while initialising the component
_this.loadingError = err;
enqueueComponent(_this);
});
if (this.props.delayLoadingAnimation) {
setTimeout(function () {
return enqueueComponent(_this);
}, this.props.delayLoadingAnimation);
} else {
enqueueComponent(this);
}
}
};
AsyncComponent.prototype.notify = function notify() {};
AsyncComponent.prototype.componentWillUnmount = function componentWillUnmount() {
this.alreadyUnmounted = true;
};
AsyncComponent.prototype.render = function render() {
if (!this.resolvedComponent) {
if (this.loadingError && this.props.onError) {
this.props.onError(this.loadingError);
} else {
this.props.whileLoading();
}
}
};
createClass(AsyncComponent, [{
key: 'el',
set: function set$$1(el) {
if (this.resolvedComponent) {
this.resolvedComponent.el = el;
}
this._el = el;
return el;
},
get: function get$$1() {
return this.resolvedComponent ? this.resolvedComponent.el : this._el;
}
}]);
return AsyncComponent;
}();
/**

@@ -882,2 +1026,2 @@ * Copyright 2017 trivago N.V.

export { createSubContext, batch, attrs, styles, classes, merge, replace, reverse, round, striptags, number_format, format, title, url_encode, strtotime, random, min, max, cycle, attribute, isEmpty, inheritBlocks };
export { AsyncComponent, createSubContext, batch, attrs, styles, classes, merge, replace, reverse, round, striptags, number_format, format, title, url_encode, strtotime, trim, random, min, max, cycle, attribute, isEmpty, inheritBlocks };

@@ -19,2 +19,3 @@ 'use strict';

var _isNumber = _interopDefault(require('lodash/isNumber'));
var melodyIdom = require('melody-idom');

@@ -73,3 +74,3 @@ /**

var value = attrMap[attr];
attrArray.push(attr, value === false || value === null || value === 0 || value === '' ? undefined : value);
attrArray.push(attr, value === false || value === null || value === 0 || value === '' && attr !== 'alt' ? undefined : value);
}

@@ -770,2 +771,33 @@ return attrArray;

function trim(str, charList) {
var side = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'both';
if (charList === undefined && side === 'both') {
// Use String.prototype.trim() for efficiency
return String(str).trim();
}
if (side !== 'both' && side !== 'left' && side !== 'right') {
throw new Error('Filter "trim". Invalid value ' + side + ' for parameter "side". Valid values are "both", "left", "right".');
}
var strLen = str.length;
var trimStart = 0;
if (side === 'both' || side === 'left') {
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) {
trimStart++;
}
}
var trimEnd = strLen;
if (side === 'both' || side === 'right') {
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) {
trimEnd--;
}
}
return str.substr(trimStart, trimEnd - trimStart);
}
var MAX_SAFE_INTEGER = 'MAX_SAFE_INTEGER' in Number ? Number.MAX_SAFE_INTEGER : 9007199254740991;

@@ -871,2 +903,114 @@

var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
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 AsyncComponent = function () {
function AsyncComponent() {
classCallCheck(this, AsyncComponent);
this.promisedComponent = null;
this._el = null;
this.refs = Object.create(null);
this.props = null;
this.resolvedComponent = null;
this.alreadyUnmounted = false;
this.isLoading = false;
this.loadingError = null;
}
AsyncComponent.prototype.apply = function apply(props) {
var _this = this;
this.props = props;
var promisedComponent = props.promisedComponent;
// if we already have resolved the component, just pass the data forward
if (this.resolvedComponent) {
this.resolvedComponent.apply(this.props.data);
}
// otherwise
if (!this.isLoading) {
this.isLoading = true;
promisedComponent().then(function (_ref) {
var Component = _ref.default;
if (_this.alreadyUnmounted) {
return;
}
_this.resolvedComponent = new Component();
melodyIdom.link(_this, _this.resolvedComponent);
_this.resolvedComponent.el = _this._el;
_this.resolvedComponent.apply(_this.props.data);
}, function (err) {
// fail early
_this.loadingError = err;
melodyIdom.enqueueComponent(_this);
}).catch(function (err) {
// just in case something went wrong while initialising the component
_this.loadingError = err;
melodyIdom.enqueueComponent(_this);
});
if (this.props.delayLoadingAnimation) {
setTimeout(function () {
return melodyIdom.enqueueComponent(_this);
}, this.props.delayLoadingAnimation);
} else {
melodyIdom.enqueueComponent(this);
}
}
};
AsyncComponent.prototype.notify = function notify() {};
AsyncComponent.prototype.componentWillUnmount = function componentWillUnmount() {
this.alreadyUnmounted = true;
};
AsyncComponent.prototype.render = function render() {
if (!this.resolvedComponent) {
if (this.loadingError && this.props.onError) {
this.props.onError(this.loadingError);
} else {
this.props.whileLoading();
}
}
};
createClass(AsyncComponent, [{
key: 'el',
set: function set$$1(el) {
if (this.resolvedComponent) {
this.resolvedComponent.el = el;
}
this._el = el;
return el;
},
get: function get$$1() {
return this.resolvedComponent ? this.resolvedComponent.el : this._el;
}
}]);
return AsyncComponent;
}();
/**

@@ -888,2 +1032,3 @@ * Copyright 2017 trivago N.V.

exports.AsyncComponent = AsyncComponent;
exports.createSubContext = createSubContext;

@@ -904,2 +1049,3 @@ exports.batch = batch;

exports.strtotime = strtotime;
exports.trim = trim;
exports.random = random;

@@ -906,0 +1052,0 @@ exports.min = min;

5

package.json
{
"name": "melody-runtime",
"version": "1.2.0-commit.39a4cc79",
"version": "1.2.0-commit.39e381df",
"description": "",

@@ -15,2 +15,5 @@ "main": "./lib/index.js",

},
"peerDependencies": {
"melody-idom": "^1.2.0"
},
"devDependencies": {

@@ -17,0 +20,0 @@ "rollup-plugin-babel": "^2.6.1"

@@ -41,3 +41,6 @@ /**

attr,
value === false || value === null || value === 0 || value === ''
value === false ||
value === null ||
value === 0 ||
(value === '' && attr !== 'alt')
? undefined

@@ -489,3 +492,3 @@ : value

// Plain Math.round doesn't just truncate
number = Math.round(number - number % 1);
number = Math.round(number - (number % 1));
prefix = number < 0 ? '-' : positivePrefix;

@@ -966,1 +969,34 @@ value =

}
export function trim(str, charList, side = 'both') {
if (charList === undefined && side === 'both') {
// Use String.prototype.trim() for efficiency
return String(str).trim();
}
if (side !== 'both' && side !== 'left' && side !== 'right') {
throw new Error(
'Filter "trim". Invalid value ' +
side +
' for parameter "side". Valid values are "both", "left", "right".'
);
}
const strLen = str.length;
let trimStart = 0;
if (side === 'both' || side === 'left') {
while (trimStart < strLen && charList.indexOf(str[trimStart]) !== -1) {
trimStart++;
}
}
let trimEnd = strLen;
if (side === 'both' || side === 'right') {
while (trimEnd > 0 && charList.indexOf(str[trimEnd - 1]) !== -1) {
trimEnd--;
}
}
return str.substr(trimStart, trimEnd - trimStart);
}

@@ -32,4 +32,8 @@ /**

strtotime,
trim,
} from './filters';
export { random, min, max, cycle, attribute } from './functions';
export { isEmpty, inheritBlocks } from './helpers';
import AsyncComponent from './async';
export { AsyncComponent };
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