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

alaska-field-number

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alaska-field-number - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

114

index.js

@@ -12,3 +12,63 @@ /**

exports.views = {
class NumberField extends alaska.Field {
init() {
let field = this;
this.underscoreMethod('format', function (format) {
if (format) {
return numeral(this.get(field.path)).format(format);
}
return this.get(field.path);
});
}
createFilter(filter) {
let value;
if (typeof filter === 'object') {
value = filter.value;
} else if (typeof filter === 'number' || typeof filter === 'string') {
value = filter;
}
if (value !== undefined) {
value = parseFloat(value);
return isNaN(value) ? undefined : value;
}
//区间
let bt;
if (filter instanceof Array) {
bt = filter;
} else if (filter.$bt && filter.$bt instanceof Array) {
bt = filter.$bt;
}
if (bt && bt.length === 2) {
let start = parseFloat(bt[0]);
let end = parseFloat(bt[1]);
if (isNaN(start) || isNaN(end)) {
return;
}
return { $gte: start, $lte: end };
}
//比较
['$gt', '$gte', '$lt', '$lte'].forEach((key) => {
let val = filter[key];
if (val === undefined) {
return;
}
val = parseFloat(val);
if (isNaN(val)) {
return;
}
if (!value) {
value = {};
}
value[key] = val;
});
if (value) {
return value;
}
}
}
NumberField.views = {
cell: {

@@ -24,50 +84,6 @@ name: 'NumberFieldCell',

exports.plain = Number;
NumberField.plain = Number;
NumberField.options = ['min', 'max'];
NumberField.viewOptions = ['min', 'max', 'format'];
/**
* 初始化Schema
* @param field alaksa.Model中的字段配置
* @param schema
* @param Model
*/
exports.initSchema = function (field, schema, Model) {
let options = {
type: Number
};
[
'get',
'set',
'default',
'index',
'required',
'select',
'min',
'max'
].forEach(function (key) {
if (field[key] !== undefined) {
options[key] = field[key];
}
});
schema.path(field.path, options);
Model.underscoreMethod(field.path, 'format', function (format) {
if (format) {
return numeral(this.get(field.path)).format(format);
}
return this.get(field.path);
});
};
/**
* alaska-admin-view 前端控件初始化参数
* @param field
* @param Model
*/
exports.viewOptions = function (field, Model) {
let options = alaska.Field.viewOptions.apply(this, arguments);
options.min = field.min instanceof Array ? field.min[0] : field.min;
options.max = field.max instanceof Array ? field.max[0] : field.max;
options.format = field.format || '';
return options;
};
module.exports = NumberField;

@@ -133,10 +133,13 @@ 'use strict';

var field = this.props.field;
var unfomarted = undefined;
if (field.format) {
var value = numeral(this.props.value).format(field.format);
this.setState({ value: value, display: value });
var unfomarted = numeral().unformat(value);
if (unfomarted != this.props.value) {
this.props.onChange && this.props.onChange(unfomarted);
}
unfomarted = numeral().unformat(value);
} else {
unfomarted = parseFloat(this.props.value) || '';
}
if (unfomarted !== this.props.value) {
this.props.onChange && this.props.onChange(unfomarted);
}
}

@@ -143,0 +146,0 @@ }, {

{
"name": "alaska-field-number",
"version": "0.2.1",
"version": "0.3.0",
"description": "Alaska number field",

@@ -5,0 +5,0 @@ "main": "index.js",

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