mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-05-17 13:56:38 +02:00
Refactored helpers module
This commit is contained in:
parent
f3fb49bd3d
commit
64f197866a
66
dist/tablefilter/tablefilter.js
vendored
66
dist/tablefilter/tablefilter.js
vendored
|
@ -134,8 +134,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
|
||||
var _helpers = __webpack_require__(7);
|
||||
|
||||
var _helpers2 = _interopRequireDefault(_helpers);
|
||||
|
||||
var _root = __webpack_require__(2);
|
||||
|
||||
var _emitter = __webpack_require__(8);
|
||||
|
@ -1394,8 +1392,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
function hasArg(sA, cellData, j) {
|
||||
sA = _string2.default.matchCase(sA, this.caseSensitive);
|
||||
|
||||
var occurence = void 0,
|
||||
removeNbFormat = _helpers2.default.removeNbFormat;
|
||||
var occurence = void 0;
|
||||
var dtType = this.hasColDateType ? this.colDateType[j] : this.defaultDateType;
|
||||
|
||||
//Search arg operator tests
|
||||
|
@ -1478,14 +1475,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
} else {
|
||||
//first numbers need to be formated
|
||||
if (this.hasColNbFormat && this.colNbFormat[j]) {
|
||||
numCellData = removeNbFormat(cellData, this.colNbFormat[j]);
|
||||
numCellData = (0, _helpers.removeNbFormat)(cellData, this.colNbFormat[j]);
|
||||
nbFormat = this.colNbFormat[j];
|
||||
} else {
|
||||
if (this.thousandsSeparator === ',' && this.decimalSeparator === '.') {
|
||||
numCellData = removeNbFormat(cellData, 'us');
|
||||
numCellData = (0, _helpers.removeNbFormat)(cellData, 'us');
|
||||
nbFormat = 'us';
|
||||
} else {
|
||||
numCellData = removeNbFormat(cellData, 'eu');
|
||||
numCellData = (0, _helpers.removeNbFormat)(cellData, 'eu');
|
||||
nbFormat = 'eu';
|
||||
}
|
||||
}
|
||||
|
@ -1494,19 +1491,19 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
// rgx:)
|
||||
// lower equal
|
||||
if (hasLE) {
|
||||
occurence = numCellData <= removeNbFormat(sA.replace(re_le, ''), nbFormat);
|
||||
occurence = numCellData <= (0, _helpers.removeNbFormat)(sA.replace(re_le, ''), nbFormat);
|
||||
}
|
||||
//greater equal
|
||||
else if (hasGE) {
|
||||
occurence = numCellData >= removeNbFormat(sA.replace(re_ge, ''), nbFormat);
|
||||
occurence = numCellData >= (0, _helpers.removeNbFormat)(sA.replace(re_ge, ''), nbFormat);
|
||||
}
|
||||
//lower
|
||||
else if (hasLO) {
|
||||
occurence = numCellData < removeNbFormat(sA.replace(re_l, ''), nbFormat);
|
||||
occurence = numCellData < (0, _helpers.removeNbFormat)(sA.replace(re_l, ''), nbFormat);
|
||||
}
|
||||
//greater
|
||||
else if (hasGR) {
|
||||
occurence = numCellData > removeNbFormat(sA.replace(re_g, ''), nbFormat);
|
||||
occurence = numCellData > (0, _helpers.removeNbFormat)(sA.replace(re_g, ''), nbFormat);
|
||||
}
|
||||
//different
|
||||
else if (hasDF) {
|
||||
|
@ -1552,7 +1549,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
// If numeric type data, perform a strict equality test and
|
||||
// fallback to unformatted number string comparison
|
||||
if (numCellData && this.hasColNbFormat && this.colNbFormat[j] && !this.singleSearchFlt) {
|
||||
sA = removeNbFormat(sA, nbFormat);
|
||||
sA = (0, _helpers.removeNbFormat)(sA, nbFormat);
|
||||
occurence = numCellData === sA || _string2.default.contains(sA.toString(), numCellData.toString(), this.isExactMatch(j), this.caseSensitive);
|
||||
} else {
|
||||
// Finally test search term is contained in cell data
|
||||
|
@ -1713,7 +1710,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
}
|
||||
var cellData = this.getCellData(cell[j]),
|
||||
nbFormat = this.colNbFormat ? this.colNbFormat[colIndex] : null,
|
||||
data = num ? _helpers2.default.removeNbFormat(cellData, nbFormat) : cellData;
|
||||
data = num ? (0, _helpers.removeNbFormat)(cellData, nbFormat) : cellData;
|
||||
colValues.push(data);
|
||||
}
|
||||
}
|
||||
|
@ -3180,39 +3177,32 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
|
||||
/***/ },
|
||||
/* 7 */
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
/***/ function(module, exports) {
|
||||
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
/**
|
||||
* Misc helpers
|
||||
*/
|
||||
|
||||
var _string = __webpack_require__(5);
|
||||
|
||||
var _string2 = _interopRequireDefault(_string);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
exports.default = {
|
||||
removeNbFormat: function removeNbFormat(data, format) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (!format) {
|
||||
format = 'us';
|
||||
}
|
||||
var n = data;
|
||||
if (_string2.default.lower(format) === 'us') {
|
||||
n = +n.replace(/[^\d\.-]/g, '');
|
||||
} else {
|
||||
n = +n.replace(/[^\d\,-]/g, '').replace(',', '.');
|
||||
}
|
||||
return n;
|
||||
var removeNbFormat = exports.removeNbFormat = function removeNbFormat(data, format) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
}; /**
|
||||
* Misc helpers
|
||||
*/
|
||||
if (!format) {
|
||||
format = 'us';
|
||||
}
|
||||
var n = data;
|
||||
if (format.toLowerCase() === 'us') {
|
||||
n = +n.replace(/[^\d\.-]/g, '');
|
||||
} else {
|
||||
n = +n.replace(/[^\d\,-]/g, '').replace(',', '.');
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
||||
/***/ },
|
||||
/* 8 */
|
||||
|
|
6
dist/tablefilter/tf-1.js
vendored
6
dist/tablefilter/tf-1.js
vendored
|
@ -1857,8 +1857,6 @@ webpackJsonp([1],{
|
|||
|
||||
var _helpers = __webpack_require__(7);
|
||||
|
||||
var _helpers2 = _interopRequireDefault(_helpers);
|
||||
|
||||
var _const = __webpack_require__(11);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
@ -2260,10 +2258,10 @@ webpackJsonp([1],{
|
|||
|
||||
exports.default = AdapterSortableTable;
|
||||
function usNumberConverter(s) {
|
||||
return _helpers2.default.removeNbFormat(s, 'us');
|
||||
return (0, _helpers.removeNbFormat)(s, 'us');
|
||||
}
|
||||
function euNumberConverter(s) {
|
||||
return _helpers2.default.removeNbFormat(s, 'eu');
|
||||
return (0, _helpers.removeNbFormat)(s, 'eu');
|
||||
}
|
||||
function dateConverter(s, format) {
|
||||
return _date2.default.format(s, format);
|
||||
|
|
|
@ -3,7 +3,7 @@ import {isArray, isFn, isUndef} from '../../types';
|
|||
import Dom from '../../dom';
|
||||
import Event from '../../event';
|
||||
import DateHelper from '../../date';
|
||||
import Helpers from '../../helpers';
|
||||
import {removeNbFormat} from '../../helpers';
|
||||
import {NONE, CELL_TAG, HEADER_TAG} from '../../const';
|
||||
|
||||
export default class AdapterSortableTable extends Feature {
|
||||
|
@ -382,10 +382,10 @@ export default class AdapterSortableTable extends Feature {
|
|||
|
||||
//Converters
|
||||
function usNumberConverter(s) {
|
||||
return Helpers.removeNbFormat(s, 'us');
|
||||
return removeNbFormat(s, 'us');
|
||||
}
|
||||
function euNumberConverter(s) {
|
||||
return Helpers.removeNbFormat(s, 'eu');
|
||||
return removeNbFormat(s, 'eu');
|
||||
}
|
||||
function dateConverter(s, format) {
|
||||
return DateHelper.format(s, format);
|
||||
|
|
|
@ -2,22 +2,18 @@
|
|||
* Misc helpers
|
||||
*/
|
||||
|
||||
import Str from './string';
|
||||
|
||||
export default {
|
||||
removeNbFormat(data, format) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
if (!format) {
|
||||
format = 'us';
|
||||
}
|
||||
let n = data;
|
||||
if (Str.lower(format) === 'us') {
|
||||
n = + n.replace(/[^\d\.-]/g, '');
|
||||
} else {
|
||||
n = + n.replace(/[^\d\,-]/g, '').replace(',', '.');
|
||||
}
|
||||
return n;
|
||||
export const removeNbFormat = (data, format) => {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
if (!format) {
|
||||
format = 'us';
|
||||
}
|
||||
let n = data;
|
||||
if (format.toLowerCase() === 'us') {
|
||||
n = + n.replace(/[^\d\.-]/g, '');
|
||||
} else {
|
||||
n = + n.replace(/[^\d\,-]/g, '').replace(',', '.');
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import Str from './string';
|
|||
import {isArray, isEmpty, isFn, isNumber, isObj, isString, isUndef}
|
||||
from './types';
|
||||
import DateHelper from './date';
|
||||
import Helpers from './helpers';
|
||||
import {removeNbFormat} from './helpers';
|
||||
|
||||
import {root} from './root';
|
||||
import {Emitter} from './emitter';
|
||||
|
@ -1184,8 +1184,7 @@ export class TableFilter {
|
|||
function hasArg(sA, cellData, j) {
|
||||
sA = Str.matchCase(sA, this.caseSensitive);
|
||||
|
||||
let occurence,
|
||||
removeNbFormat = Helpers.removeNbFormat;
|
||||
let occurence;
|
||||
let dtType = this.hasColDateType ?
|
||||
this.colDateType[j] : this.defaultDateType;
|
||||
|
||||
|
@ -1525,8 +1524,7 @@ export class TableFilter {
|
|||
let cellData = this.getCellData(cell[j]),
|
||||
nbFormat = this.colNbFormat ?
|
||||
this.colNbFormat[colIndex] : null,
|
||||
data = num ?
|
||||
Helpers.removeNbFormat(cellData, nbFormat) :
|
||||
data = num ? removeNbFormat(cellData, nbFormat) :
|
||||
cellData;
|
||||
colValues.push(data);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue