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