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

react-bsonschema-form

Package Overview
Dependencies
Maintainers
3
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-bsonschema-form - npm Package Compare versions

Comparing version 0.42.33 to 0.43.0

lib/components/fields/BsonNumberFieldHOC.js

60

lib/components/fields/DoubleField.js

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

"use strict";
'use strict';

@@ -7,61 +7,23 @@ Object.defineProperty(exports, "__esModule", {

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 _react = require('react');
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _StringField = require("./StringField");
var _bson = require('bson');
var _StringField2 = _interopRequireDefault(_StringField);
var _BsonNumberFieldHOC = require('./BsonNumberFieldHOC');
var _bson = require("bson");
var _BsonNumberFieldHOC2 = _interopRequireDefault(_BsonNumberFieldHOC);
var _bson2 = _interopRequireDefault(_bson);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Double = _bson2.default.Double;
function convert(value) {
var notNumber = value === '' || isNaN(value);
if (notNumber) {
function stringToBsonNumber(string) {
var float = parseFloat(string);
if (isNaN(float)) {
return undefined;
} else {
return new _bson.Double(parseFloat(float.toFixed(2)));
}
// NOTE: we may need to validate range for double
return new Double(value);
}
function round(value) {
return parseFloat(value).toFixed(2);
}
function DoubleField(props) {
return _react2.default.createElement(_StringField2.default, _extends({}, props, {
onChange: function onChange(value) {
return props.onChange(convert(value));
},
onBlur: function onBlur(event) {
return props.onChange(convert(round(event.target.value)));
} }));
}
if (process.env.NODE_ENV !== "production") {
DoubleField.propTypes = {
schema: _react.PropTypes.object.isRequired,
uiSchema: _react.PropTypes.object,
idSchema: _react.PropTypes.object,
onChange: _react.PropTypes.func.isRequired,
onBlur: _react.PropTypes.func,
formData: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string, _react.PropTypes.object]),
required: _react.PropTypes.bool,
formContext: _react.PropTypes.object.isRequired
};
}
DoubleField.defaultProps = {
uiSchema: {}
};
exports.default = DoubleField;
exports.default = (0, _BsonNumberFieldHOC2.default)(stringToBsonNumber);

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

"use strict";
'use strict';

@@ -7,62 +7,23 @@ Object.defineProperty(exports, "__esModule", {

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 _react = require('react');
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _bson = require("bson");
var _bson = require('bson');
var _bson2 = _interopRequireDefault(_bson);
var _BsonNumberFieldHOC = require('./BsonNumberFieldHOC');
var _utils = require("../../utils");
var _BsonNumberFieldHOC2 = _interopRequireDefault(_BsonNumberFieldHOC);
var _StringField = require("./StringField");
var _StringField2 = _interopRequireDefault(_StringField);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Int32 = _bson2.default.Int32,
BSON_INT32_MAX = _bson2.default.BSON_INT32_MAX,
BSON_INT32_MIN = _bson2.default.BSON_INT32_MIN;
function convert(value) {
if (!(0, _utils.isInteger)(value)) {
function stringToBsonNumber(string) {
var int = parseInt(string);
if (isNaN(int)) {
return undefined;
} else {
return new _bson.Int32(int);
}
var number = Number(value);
var isOutOfRange = number < BSON_INT32_MIN || number > BSON_INT32_MAX;
if (isOutOfRange) {
return value;
}
return new Int32(number);
}
function IntField(props) {
return _react2.default.createElement(_StringField2.default, _extends({}, props, {
onChange: function onChange(value) {
return props.onChange(convert(value));
} }));
}
if (process.env.NODE_ENV !== "production") {
IntField.propTypes = {
schema: _react.PropTypes.object.isRequired,
uiSchema: _react.PropTypes.object,
idSchema: _react.PropTypes.object,
onChange: _react.PropTypes.func.isRequired,
formData: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string, _react.PropTypes.object]),
required: _react.PropTypes.bool,
formContext: _react.PropTypes.object.isRequired
};
}
IntField.defaultProps = {
uiSchema: {}
};
exports.default = IntField;
exports.default = (0, _BsonNumberFieldHOC2.default)(stringToBsonNumber);

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

"use strict";
'use strict';

@@ -7,62 +7,23 @@ Object.defineProperty(exports, "__esModule", {

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 _react = require('react');
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _bson = require("bson");
var _bson = require('bson');
var _bson2 = _interopRequireDefault(_bson);
var _BsonNumberFieldHOC = require('./BsonNumberFieldHOC');
var _utils = require("../../utils");
var _BsonNumberFieldHOC2 = _interopRequireDefault(_BsonNumberFieldHOC);
var _StringField = require("./StringField");
var _StringField2 = _interopRequireDefault(_StringField);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Long = _bson2.default.Long,
BSON_INT64_MAX = _bson2.default.BSON_INT64_MAX,
BSON_INT64_MIN = _bson2.default.BSON_INT64_MIN;
function convert(value) {
if (!(0, _utils.isInteger)(value)) {
function stringToBsonNumber(string) {
var long = parseInt(string);
if (isNaN(long)) {
return undefined;
} else {
return _bson.Long.fromString(long.toString());
}
var number = Number(value);
var isOutOfRange = number < BSON_INT64_MIN || number > BSON_INT64_MAX;
if (isOutOfRange) {
return value;
}
return Long.fromString(number.toString());
}
function LongField(props) {
return _react2.default.createElement(_StringField2.default, _extends({}, props, {
onChange: function onChange(value) {
return props.onChange(convert(value));
} }));
}
if (process.env.NODE_ENV !== "production") {
LongField.propTypes = {
schema: _react.PropTypes.object.isRequired,
uiSchema: _react.PropTypes.object,
idSchema: _react.PropTypes.object,
onChange: _react.PropTypes.func.isRequired,
formData: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string, _react.PropTypes.object]),
required: _react.PropTypes.bool,
formContext: _react.PropTypes.object.isRequired
};
}
LongField.defaultProps = {
uiSchema: {}
};
exports.default = LongField;
exports.default = (0, _BsonNumberFieldHOC2.default)(stringToBsonNumber);

@@ -31,4 +31,3 @@ "use strict";

registry = props.registry,
_onChange = props.onChange,
onBlur = props.onBlur;
_onChange = props.onChange;
var title = schema.title,

@@ -51,5 +50,2 @@ format = schema.format;

var inputProps = {};
if (onBlur) {
inputProps.onBlur = onBlur;
}

@@ -81,3 +77,2 @@ return _react2.default.createElement(Widget, _extends({}, inputProps, {

onChange: _react.PropTypes.func.isRequired,
onBlur: _react.PropTypes.func,
formData: _react.PropTypes.oneOfType([_react2.default.PropTypes.string, _react2.default.PropTypes.number, _react2.default.PropTypes.object]),

@@ -84,0 +79,0 @@ registry: _react.PropTypes.shape({

@@ -66,2 +66,6 @@ 'use strict';

// NOTE
// Here we use onBlur to trigger onChange.
// This is for performance purposes.
// Previously we are using debounce and it creates strange behavior.

@@ -68,0 +72,0 @@ return _react2.default.createElement('input', _extends({}, inputProps, {

{
"name": "react-bsonschema-form",
"version": "0.42.33",
"version": "0.43.0",
"description": "A simple React component capable of building HTML forms out of a JSON schema.",

@@ -5,0 +5,0 @@ "scripts": {

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