mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 22:36:01 +00:00
Shorten identifiers
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"blueimp-md5": "^2.19.0",
|
||||
"dbgate-query-splitter": "^4.11.7",
|
||||
"dbgate-sqltree": "^6.0.0-alpha.1",
|
||||
"debug": "^4.3.4",
|
||||
|
||||
@@ -9,6 +9,7 @@ import _isEmpty from 'lodash/isEmpty';
|
||||
import _omitBy from 'lodash/omitBy';
|
||||
import { DataEditorTypesBehaviour } from 'dbgate-types';
|
||||
import isPlainObject from 'lodash/isPlainObject';
|
||||
import md5 from 'blueimp-md5';
|
||||
|
||||
export const MAX_GRID_TEXT_LENGTH = 1000; // maximum length of text in grid cell, longer text is truncated
|
||||
|
||||
@@ -737,3 +738,12 @@ export function setSqlFrontMatter(text: string, data: { [key: string]: any }, ya
|
||||
const frontMatterContent = `-- >>>\n${yamlContentMapped}\n-- <<<\n`;
|
||||
return frontMatterContent + (textClean || '');
|
||||
}
|
||||
|
||||
export function shortenIdentifier(s: string, maxLength?: number) {
|
||||
if (!maxLength || maxLength < 10) return s;
|
||||
if (s.length <= maxLength) return s;
|
||||
const hash = md5(s).substring(0, 8);
|
||||
const partLength = Math.floor((maxLength - 9) / 2);
|
||||
const restLength = maxLength - 10 - partLength;
|
||||
return s.substring(0, partLength) + '_' + hash + '_' + s.substring(s.length - restLength);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user