1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-04 15:43:15 +02:00

fix TableFilter table id generation with more robust uuid generator

This commit is contained in:
koalyptus 2019-02-18 22:50:04 +11:00
parent 0a69a99dc5
commit 495b64ecf0
6 changed files with 28 additions and 7 deletions

4
dist/starter.html vendored
View file

@ -1,10 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>tablefilter v0.6.78 - Starter</title> <title>tablefilter v0.6.79 - Starter</title>
</head> </head>
<body> <body>
<h1>tablefilter v0.6.78</h1> <h1>tablefilter v0.6.79</h1>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{ {
"name": "tablefilter", "name": "tablefilter",
"version": "0.6.78", "version": "0.6.79",
"description": "A Javascript library making HTML tables filterable and a bit more", "description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT", "license": "MIT",
"author": { "author": {

View file

@ -89,3 +89,24 @@ export const toCamelCase = (text = '') => {
return p1.toLowerCase(); return p1.toLowerCase();
}); });
}; };
/**
* Generate a string in the format of a UUID (Universally Unique IDentifier).
* NOTE: This format of 8 chars, followed by 3 groups of 4 chars, followed by 12
* chars is known as a UUID and is defined in RFC4122 and is a standard for
* generating unique IDs. This function DOES NOT implement this standard.
* It simply outputs a string that looks similar. The standard is found here:
* https://www.ietf.org/rfc/rfc4122.txt
* source: https://gist.github.com/gordonbrander/2230317
* @return {String}
*/
export const uuid = () => {
const chr4 = () => Math.random().toString(16).slice(-4);
return chr4() + chr4()
+ '-' + chr4()
+ '-' + chr4()
+ '-' + chr4()
+ '-' + chr4()
+ chr4() + chr4();
};

View file

@ -2,7 +2,7 @@ import {addEvt, cancelEvt, stopEvt, targetEvt, isKeyPressed} from './event';
import { import {
addClass, createElm, elm, getText, getFirstTextNode, removeClass, tag addClass, createElm, elm, getText, getFirstTextNode, removeClass, tag
} from './dom'; } from './dom';
import {contains, matchCase, rgxEsc, trim, toCamelCase} from './string'; import {contains, matchCase, rgxEsc, trim, toCamelCase, uuid} from './string';
import { import {
isArray, isEmpty, isFn, isNumber, isObj, isString, isUndef, EMPTY_FN, isArray, isEmpty, isFn, isNumber, isObj, isString, isUndef, EMPTY_FN,
isBoolean isBoolean
@ -142,7 +142,7 @@ export class TableFilter {
args.forEach((arg) => { args.forEach((arg) => {
if (typeof arg === 'object' && arg.nodeName === 'TABLE') { if (typeof arg === 'object' && arg.nodeName === 'TABLE') {
this.tbl = arg; this.tbl = arg;
this.id = arg.id || `tf_${new Date().getTime()}_`; this.id = arg.id || `tf_${uuid()}`;
this.tbl.id = this.id; this.tbl.id = this.id;
} else if (isString(arg)) { } else if (isString(arg)) {
this.id = arg; this.id = arg;