langsmith 0.5.16 → 0.5.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anonymizer/index.cjs +46 -20
- package/dist/anonymizer/index.js +46 -17
- package/dist/client.cjs +112 -143
- package/dist/client.d.ts +19 -40
- package/dist/client.js +112 -143
- package/dist/experimental/anthropic/index.cjs +4 -1
- package/dist/experimental/anthropic/index.js +4 -1
- package/dist/experimental/vercel/index.cjs +1 -0
- package/dist/experimental/vercel/index.js +1 -0
- package/dist/experimental/vercel/middleware.cjs +2 -0
- package/dist/experimental/vercel/middleware.js +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/schemas.d.ts +1 -3
- package/dist/utils/chalk/source/index.cjs +187 -0
- package/dist/utils/chalk/source/index.d.ts +19 -0
- package/dist/utils/chalk/source/index.js +173 -0
- package/dist/utils/chalk/source/utilities.cjs +35 -0
- package/dist/utils/chalk/source/utilities.d.ts +2 -0
- package/dist/utils/chalk/source/utilities.js +31 -0
- package/dist/utils/chalk/source/vendor/ansi-styles/index.cjs +193 -0
- package/dist/utils/chalk/source/vendor/ansi-styles/index.d.ts +58 -0
- package/dist/utils/chalk/source/vendor/ansi-styles/index.js +190 -0
- package/dist/utils/chalk/source/vendor/supports-color/browser.cjs +31 -0
- package/dist/utils/chalk/source/vendor/supports-color/browser.d.ts +15 -0
- package/dist/utils/chalk/source/vendor/supports-color/browser.js +29 -0
- package/dist/utils/chalk/source/vendor/supports-color/index.cjs +155 -0
- package/dist/utils/chalk/source/vendor/supports-color/index.d.ts +21 -0
- package/dist/utils/chalk/source/vendor/supports-color/index.js +149 -0
- package/dist/utils/console-table-printer/index.cjs +11 -0
- package/dist/utils/console-table-printer/index.d.ts +4 -0
- package/dist/utils/console-table-printer/index.js +3 -0
- package/dist/utils/console-table-printer/src/console-table-printer.cjs +42 -0
- package/dist/utils/console-table-printer/src/console-table-printer.d.ts +14 -0
- package/dist/utils/console-table-printer/src/console-table-printer.js +36 -0
- package/dist/utils/console-table-printer/src/internalTable/input-converter.cjs +25 -0
- package/dist/utils/console-table-printer/src/internalTable/input-converter.d.ts +6 -0
- package/dist/utils/console-table-printer/src/internalTable/input-converter.js +20 -0
- package/dist/utils/console-table-printer/src/internalTable/internal-table-printer.cjs +142 -0
- package/dist/utils/console-table-printer/src/internalTable/internal-table-printer.d.ts +6 -0
- package/dist/utils/console-table-printer/src/internalTable/internal-table-printer.js +133 -0
- package/dist/utils/console-table-printer/src/internalTable/internal-table.cjs +186 -0
- package/dist/utils/console-table-printer/src/internalTable/internal-table.d.ts +31 -0
- package/dist/utils/console-table-printer/src/internalTable/internal-table.js +184 -0
- package/dist/utils/console-table-printer/src/internalTable/table-pre-processors.cjs +53 -0
- package/dist/utils/console-table-printer/src/internalTable/table-pre-processors.d.ts +3 -0
- package/dist/utils/console-table-printer/src/internalTable/table-pre-processors.js +48 -0
- package/dist/utils/console-table-printer/src/models/common.cjs +2 -0
- package/dist/utils/console-table-printer/src/models/common.d.ts +14 -0
- package/dist/utils/console-table-printer/src/models/common.js +1 -0
- package/dist/utils/console-table-printer/src/models/external-table.cjs +2 -0
- package/dist/utils/console-table-printer/src/models/external-table.d.ts +99 -0
- package/dist/utils/console-table-printer/src/models/external-table.js +1 -0
- package/dist/utils/console-table-printer/src/models/internal-table.cjs +2 -0
- package/dist/utils/console-table-printer/src/models/internal-table.d.ts +24 -0
- package/dist/utils/console-table-printer/src/models/internal-table.js +1 -0
- package/dist/utils/console-table-printer/src/utils/colored-console-line.cjs +43 -0
- package/dist/utils/console-table-printer/src/utils/colored-console-line.d.ts +12 -0
- package/dist/utils/console-table-printer/src/utils/colored-console-line.js +39 -0
- package/dist/utils/console-table-printer/src/utils/console-utils.cjs +23 -0
- package/dist/utils/console-table-printer/src/utils/console-utils.d.ts +3 -0
- package/dist/utils/console-table-printer/src/utils/console-utils.js +18 -0
- package/dist/utils/console-table-printer/src/utils/string-utils.cjs +68 -0
- package/dist/utils/console-table-printer/src/utils/string-utils.d.ts +4 -0
- package/dist/utils/console-table-printer/src/utils/string-utils.js +62 -0
- package/dist/utils/console-table-printer/src/utils/table-constants.cjs +55 -0
- package/dist/utils/console-table-printer/src/utils/table-constants.d.ts +11 -0
- package/dist/utils/console-table-printer/src/utils/table-constants.js +52 -0
- package/dist/utils/console-table-printer/src/utils/table-helpers.cjs +101 -0
- package/dist/utils/console-table-printer/src/utils/table-helpers.d.ts +29 -0
- package/dist/utils/console-table-printer/src/utils/table-helpers.js +88 -0
- package/dist/utils/jestlike/reporter.cjs +23 -23
- package/dist/utils/jestlike/reporter.js +2 -2
- package/dist/utils/prompts.cjs +0 -10
- package/dist/utils/prompts.d.ts +0 -1
- package/dist/utils/prompts.js +0 -9
- package/dist/utils/simple-wcswidth/index.cjs +10 -0
- package/dist/utils/simple-wcswidth/index.d.ts +3 -0
- package/dist/utils/simple-wcswidth/index.js +3 -0
- package/dist/utils/simple-wcswidth/src/binary-search.cjs +24 -0
- package/dist/utils/simple-wcswidth/src/binary-search.d.ts +3 -0
- package/dist/utils/simple-wcswidth/src/binary-search.js +22 -0
- package/dist/utils/simple-wcswidth/src/models.cjs +2 -0
- package/dist/utils/simple-wcswidth/src/models.d.ts +4 -0
- package/dist/utils/simple-wcswidth/src/models.js +1 -0
- package/dist/utils/simple-wcswidth/src/non-spacing-chars.cjs +149 -0
- package/dist/utils/simple-wcswidth/src/non-spacing-chars.d.ts +3 -0
- package/dist/utils/simple-wcswidth/src/non-spacing-chars.js +147 -0
- package/dist/utils/simple-wcswidth/src/wcswidth.cjs +20 -0
- package/dist/utils/simple-wcswidth/src/wcswidth.d.ts +2 -0
- package/dist/utils/simple-wcswidth/src/wcswidth.js +15 -0
- package/dist/utils/simple-wcswidth/src/wcwidth.cjs +67 -0
- package/dist/utils/simple-wcswidth/src/wcwidth.d.ts +2 -0
- package/dist/utils/simple-wcswidth/src/wcwidth.js +62 -0
- package/package.json +5 -7
- package/dist/utils/lodash/assignValue.cjs +0 -29
- package/dist/utils/lodash/assignValue.d.ts +0 -10
- package/dist/utils/lodash/assignValue.js +0 -24
- package/dist/utils/lodash/baseAssignValue.cjs +0 -25
- package/dist/utils/lodash/baseAssignValue.d.ts +0 -11
- package/dist/utils/lodash/baseAssignValue.js +0 -23
- package/dist/utils/lodash/baseSet.cjs +0 -50
- package/dist/utils/lodash/baseSet.d.ts +0 -12
- package/dist/utils/lodash/baseSet.js +0 -45
- package/dist/utils/lodash/castPath.cjs +0 -22
- package/dist/utils/lodash/castPath.d.ts +0 -10
- package/dist/utils/lodash/castPath.js +0 -17
- package/dist/utils/lodash/eq.cjs +0 -36
- package/dist/utils/lodash/eq.d.ts +0 -32
- package/dist/utils/lodash/eq.js +0 -34
- package/dist/utils/lodash/getTag.cjs +0 -18
- package/dist/utils/lodash/getTag.d.ts +0 -9
- package/dist/utils/lodash/getTag.js +0 -16
- package/dist/utils/lodash/isIndex.cjs +0 -25
- package/dist/utils/lodash/isIndex.d.ts +0 -10
- package/dist/utils/lodash/isIndex.js +0 -23
- package/dist/utils/lodash/isKey.cjs +0 -34
- package/dist/utils/lodash/isKey.d.ts +0 -10
- package/dist/utils/lodash/isKey.js +0 -29
- package/dist/utils/lodash/isObject.cjs +0 -31
- package/dist/utils/lodash/isObject.d.ts +0 -25
- package/dist/utils/lodash/isObject.js +0 -29
- package/dist/utils/lodash/isSymbol.cjs +0 -28
- package/dist/utils/lodash/isSymbol.d.ts +0 -17
- package/dist/utils/lodash/isSymbol.js +0 -23
- package/dist/utils/lodash/memoizeCapped.cjs +0 -65
- package/dist/utils/lodash/memoizeCapped.d.ts +0 -50
- package/dist/utils/lodash/memoizeCapped.js +0 -63
- package/dist/utils/lodash/set.cjs +0 -41
- package/dist/utils/lodash/set.d.ts +0 -32
- package/dist/utils/lodash/set.js +0 -36
- package/dist/utils/lodash/stringToPath.cjs +0 -49
- package/dist/utils/lodash/stringToPath.d.ts +0 -12
- package/dist/utils/lodash/stringToPath.js +0 -44
- package/dist/utils/lodash/toKey.cjs +0 -24
- package/dist/utils/lodash/toKey.d.ts +0 -9
- package/dist/utils/lodash/toKey.js +0 -19
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_COLOR_MAP = void 0;
|
|
4
|
+
exports.DEFAULT_COLOR_MAP = {
|
|
5
|
+
red: '\x1b[31m',
|
|
6
|
+
green: '\x1b[32m',
|
|
7
|
+
yellow: '\x1b[33m',
|
|
8
|
+
blue: '\x1b[34m',
|
|
9
|
+
magenta: '\x1b[35m',
|
|
10
|
+
cyan: '\x1b[36m',
|
|
11
|
+
white: '\x1b[37m',
|
|
12
|
+
white_bold: '\x1b[01m',
|
|
13
|
+
reset: '\x1b[0m',
|
|
14
|
+
};
|
|
15
|
+
class ColoredConsoleLine {
|
|
16
|
+
constructor(colorMap = exports.DEFAULT_COLOR_MAP) {
|
|
17
|
+
Object.defineProperty(this, "text", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "colorMap", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
this.text = '';
|
|
30
|
+
this.colorMap = colorMap;
|
|
31
|
+
}
|
|
32
|
+
addCharsWithColor(color, text) {
|
|
33
|
+
const colorAnsi = this.colorMap[color];
|
|
34
|
+
this.text +=
|
|
35
|
+
colorAnsi !== undefined
|
|
36
|
+
? `${colorAnsi}${text}${this.colorMap.reset}`
|
|
37
|
+
: text;
|
|
38
|
+
}
|
|
39
|
+
renderConsole() {
|
|
40
|
+
return this.text;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.default = ColoredConsoleLine;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { COLOR } from '../models/common.js';
|
|
2
|
+
export type ColorMap = {
|
|
3
|
+
[key in COLOR]?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const DEFAULT_COLOR_MAP: ColorMap;
|
|
6
|
+
export default class ColoredConsoleLine {
|
|
7
|
+
text: string;
|
|
8
|
+
colorMap: ColorMap;
|
|
9
|
+
constructor(colorMap?: ColorMap);
|
|
10
|
+
addCharsWithColor(color: COLOR, text: string): void;
|
|
11
|
+
renderConsole(): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const DEFAULT_COLOR_MAP = {
|
|
2
|
+
red: '\x1b[31m',
|
|
3
|
+
green: '\x1b[32m',
|
|
4
|
+
yellow: '\x1b[33m',
|
|
5
|
+
blue: '\x1b[34m',
|
|
6
|
+
magenta: '\x1b[35m',
|
|
7
|
+
cyan: '\x1b[36m',
|
|
8
|
+
white: '\x1b[37m',
|
|
9
|
+
white_bold: '\x1b[01m',
|
|
10
|
+
reset: '\x1b[0m',
|
|
11
|
+
};
|
|
12
|
+
export default class ColoredConsoleLine {
|
|
13
|
+
constructor(colorMap = DEFAULT_COLOR_MAP) {
|
|
14
|
+
Object.defineProperty(this, "text", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "colorMap", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
this.text = '';
|
|
27
|
+
this.colorMap = colorMap;
|
|
28
|
+
}
|
|
29
|
+
addCharsWithColor(color, text) {
|
|
30
|
+
const colorAnsi = this.colorMap[color];
|
|
31
|
+
this.text +=
|
|
32
|
+
colorAnsi !== undefined
|
|
33
|
+
? `${colorAnsi}${text}${this.colorMap.reset}`
|
|
34
|
+
: text;
|
|
35
|
+
}
|
|
36
|
+
renderConsole() {
|
|
37
|
+
return this.text;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findWidthInConsole = exports.stripAnsi = void 0;
|
|
4
|
+
const index_js_1 = require("../../../simple-wcswidth/index.cjs");
|
|
5
|
+
/* eslint-disable no-control-regex */
|
|
6
|
+
const colorRegex = /\x1b\[\d{1,3}(;\d{1,3})*m/g; // \x1b[30m \x1b[305m \x1b[38;5m
|
|
7
|
+
const stripAnsi = (str) => str.replace(colorRegex, '');
|
|
8
|
+
exports.stripAnsi = stripAnsi;
|
|
9
|
+
const findWidthInConsole = (str, charLength) => {
|
|
10
|
+
let strLen = 0;
|
|
11
|
+
str = (0, exports.stripAnsi)(str);
|
|
12
|
+
if (charLength) {
|
|
13
|
+
Object.entries(charLength).forEach(([key, value]) => {
|
|
14
|
+
// count appearance of the key in the string and remove from original string
|
|
15
|
+
const regex = new RegExp(key, 'g');
|
|
16
|
+
strLen += (str.match(regex) || []).length * value;
|
|
17
|
+
str = str.replace(key, '');
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
strLen += (0, index_js_1.wcswidth)(str);
|
|
21
|
+
return strLen;
|
|
22
|
+
};
|
|
23
|
+
exports.findWidthInConsole = findWidthInConsole;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { wcswidth } from '../../../simple-wcswidth/index.js';
|
|
2
|
+
/* eslint-disable no-control-regex */
|
|
3
|
+
const colorRegex = /\x1b\[\d{1,3}(;\d{1,3})*m/g; // \x1b[30m \x1b[305m \x1b[38;5m
|
|
4
|
+
export const stripAnsi = (str) => str.replace(colorRegex, '');
|
|
5
|
+
export const findWidthInConsole = (str, charLength) => {
|
|
6
|
+
let strLen = 0;
|
|
7
|
+
str = stripAnsi(str);
|
|
8
|
+
if (charLength) {
|
|
9
|
+
Object.entries(charLength).forEach(([key, value]) => {
|
|
10
|
+
// count appearance of the key in the string and remove from original string
|
|
11
|
+
const regex = new RegExp(key, 'g');
|
|
12
|
+
strLen += (str.match(regex) || []).length * value;
|
|
13
|
+
str = str.replace(key, '');
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
strLen += wcswidth(str);
|
|
17
|
+
return strLen;
|
|
18
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.biggestWordInSentence = exports.textWithPadding = exports.splitTextIntoTextsOfMinLen = void 0;
|
|
4
|
+
const console_utils_js_1 = require("./console-utils.cjs");
|
|
5
|
+
// ("How are you?",10) => ["How are ", "you?"]
|
|
6
|
+
const splitTextIntoTextsOfMinLen = (inpStr, width, charLength) => {
|
|
7
|
+
const ret = [];
|
|
8
|
+
const lines = inpStr.split(/[\n\r]/);
|
|
9
|
+
lines.forEach((line) => {
|
|
10
|
+
const spaceSeparatedStrings = line.split(' ');
|
|
11
|
+
let now = [];
|
|
12
|
+
let cnt = 0;
|
|
13
|
+
spaceSeparatedStrings.forEach((strWithoutSpace) => {
|
|
14
|
+
const consoleWidth = (0, console_utils_js_1.findWidthInConsole)(strWithoutSpace, charLength);
|
|
15
|
+
if (cnt + consoleWidth <= width) {
|
|
16
|
+
cnt += consoleWidth + 1; // 1 for the space
|
|
17
|
+
now.push(strWithoutSpace);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
if (now.length > 0)
|
|
21
|
+
ret.push(now.join(' '));
|
|
22
|
+
now = [strWithoutSpace];
|
|
23
|
+
cnt = consoleWidth + 1;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
ret.push(now.join(' '));
|
|
27
|
+
});
|
|
28
|
+
return ret;
|
|
29
|
+
};
|
|
30
|
+
exports.splitTextIntoTextsOfMinLen = splitTextIntoTextsOfMinLen;
|
|
31
|
+
// ("How are you?",center, 20) => " How are you? "
|
|
32
|
+
// ("How are you?",right, 20) => " How are you?"
|
|
33
|
+
// ("How are you?",center, 4) => "How\nare\nyou?"
|
|
34
|
+
const textWithPadding = (text, alignment, columnLen, charLength) => {
|
|
35
|
+
const curTextSize = (0, console_utils_js_1.findWidthInConsole)(text, charLength);
|
|
36
|
+
// alignments for center padding case
|
|
37
|
+
const leftPadding = Math.floor((columnLen - curTextSize) / 2);
|
|
38
|
+
const rightPadding = columnLen - leftPadding - curTextSize;
|
|
39
|
+
// handle edge cases where the text size is larger than the column length
|
|
40
|
+
if (columnLen < curTextSize) {
|
|
41
|
+
const splittedLines = (0, exports.splitTextIntoTextsOfMinLen)(text, columnLen);
|
|
42
|
+
if (splittedLines.length === 1) {
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
45
|
+
return splittedLines
|
|
46
|
+
.map((singleLine) => (0, exports.textWithPadding)(singleLine, alignment, columnLen, charLength))
|
|
47
|
+
.join('\n');
|
|
48
|
+
}
|
|
49
|
+
// console.log(text, columnLen, curTextSize);
|
|
50
|
+
switch (alignment) {
|
|
51
|
+
case 'left':
|
|
52
|
+
return text.concat(' '.repeat(columnLen - curTextSize));
|
|
53
|
+
case 'center':
|
|
54
|
+
return ' '
|
|
55
|
+
.repeat(leftPadding)
|
|
56
|
+
.concat(text)
|
|
57
|
+
.concat(' '.repeat(rightPadding));
|
|
58
|
+
case 'right':
|
|
59
|
+
default:
|
|
60
|
+
return ' '.repeat(columnLen - curTextSize).concat(text);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.textWithPadding = textWithPadding;
|
|
64
|
+
// ("How are you?",10) => ["How are ", "you?"]
|
|
65
|
+
const biggestWordInSentence = (inpStr, charLength) => inpStr
|
|
66
|
+
.split(' ')
|
|
67
|
+
.reduce((a, b) => Math.max(a, (0, console_utils_js_1.findWidthInConsole)(b, charLength)), 0);
|
|
68
|
+
exports.biggestWordInSentence = biggestWordInSentence;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ALIGNMENT, CharLengthDict } from '../models/common.js';
|
|
2
|
+
export declare const splitTextIntoTextsOfMinLen: (inpStr: string, width: number, charLength?: CharLengthDict) => string[];
|
|
3
|
+
export declare const textWithPadding: (text: string, alignment: ALIGNMENT, columnLen: number, charLength?: CharLengthDict) => string;
|
|
4
|
+
export declare const biggestWordInSentence: (inpStr: string, charLength?: CharLengthDict) => number;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { findWidthInConsole } from './console-utils.js';
|
|
2
|
+
// ("How are you?",10) => ["How are ", "you?"]
|
|
3
|
+
export const splitTextIntoTextsOfMinLen = (inpStr, width, charLength) => {
|
|
4
|
+
const ret = [];
|
|
5
|
+
const lines = inpStr.split(/[\n\r]/);
|
|
6
|
+
lines.forEach((line) => {
|
|
7
|
+
const spaceSeparatedStrings = line.split(' ');
|
|
8
|
+
let now = [];
|
|
9
|
+
let cnt = 0;
|
|
10
|
+
spaceSeparatedStrings.forEach((strWithoutSpace) => {
|
|
11
|
+
const consoleWidth = findWidthInConsole(strWithoutSpace, charLength);
|
|
12
|
+
if (cnt + consoleWidth <= width) {
|
|
13
|
+
cnt += consoleWidth + 1; // 1 for the space
|
|
14
|
+
now.push(strWithoutSpace);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
if (now.length > 0)
|
|
18
|
+
ret.push(now.join(' '));
|
|
19
|
+
now = [strWithoutSpace];
|
|
20
|
+
cnt = consoleWidth + 1;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
ret.push(now.join(' '));
|
|
24
|
+
});
|
|
25
|
+
return ret;
|
|
26
|
+
};
|
|
27
|
+
// ("How are you?",center, 20) => " How are you? "
|
|
28
|
+
// ("How are you?",right, 20) => " How are you?"
|
|
29
|
+
// ("How are you?",center, 4) => "How\nare\nyou?"
|
|
30
|
+
export const textWithPadding = (text, alignment, columnLen, charLength) => {
|
|
31
|
+
const curTextSize = findWidthInConsole(text, charLength);
|
|
32
|
+
// alignments for center padding case
|
|
33
|
+
const leftPadding = Math.floor((columnLen - curTextSize) / 2);
|
|
34
|
+
const rightPadding = columnLen - leftPadding - curTextSize;
|
|
35
|
+
// handle edge cases where the text size is larger than the column length
|
|
36
|
+
if (columnLen < curTextSize) {
|
|
37
|
+
const splittedLines = splitTextIntoTextsOfMinLen(text, columnLen);
|
|
38
|
+
if (splittedLines.length === 1) {
|
|
39
|
+
return text;
|
|
40
|
+
}
|
|
41
|
+
return splittedLines
|
|
42
|
+
.map((singleLine) => textWithPadding(singleLine, alignment, columnLen, charLength))
|
|
43
|
+
.join('\n');
|
|
44
|
+
}
|
|
45
|
+
// console.log(text, columnLen, curTextSize);
|
|
46
|
+
switch (alignment) {
|
|
47
|
+
case 'left':
|
|
48
|
+
return text.concat(' '.repeat(columnLen - curTextSize));
|
|
49
|
+
case 'center':
|
|
50
|
+
return ' '
|
|
51
|
+
.repeat(leftPadding)
|
|
52
|
+
.concat(text)
|
|
53
|
+
.concat(' '.repeat(rightPadding));
|
|
54
|
+
case 'right':
|
|
55
|
+
default:
|
|
56
|
+
return ' '.repeat(columnLen - curTextSize).concat(text);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
// ("How are you?",10) => ["How are ", "you?"]
|
|
60
|
+
export const biggestWordInSentence = (inpStr, charLength) => inpStr
|
|
61
|
+
.split(' ')
|
|
62
|
+
.reduce((a, b) => Math.max(a, findWidthInConsole(b, charLength)), 0);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_HEADER_ALIGNMENT = exports.DEFAULT_ROW_ALIGNMENT = exports.DEFAULT_HEADER_FONT_COLOR = exports.DEFAULT_ROW_FONT_COLOR = exports.COLORS = exports.ALIGNMENTS = exports.DEFAULT_TABLE_STYLE = exports.DEFAULT_ROW_SEPARATOR = exports.DEFAULT_COLUMN_LEN = void 0;
|
|
4
|
+
exports.DEFAULT_COLUMN_LEN = 20;
|
|
5
|
+
exports.DEFAULT_ROW_SEPARATOR = false;
|
|
6
|
+
exports.DEFAULT_TABLE_STYLE = {
|
|
7
|
+
/*
|
|
8
|
+
Default Style
|
|
9
|
+
┌────────────┬─────┬──────┐
|
|
10
|
+
│ foo │ bar │ baz │
|
|
11
|
+
│ frobnicate │ bar │ quuz │
|
|
12
|
+
└────────────┴─────┴──────┘
|
|
13
|
+
*/
|
|
14
|
+
headerTop: {
|
|
15
|
+
left: '┌',
|
|
16
|
+
mid: '┬',
|
|
17
|
+
right: '┐',
|
|
18
|
+
other: '─',
|
|
19
|
+
},
|
|
20
|
+
headerBottom: {
|
|
21
|
+
left: '├',
|
|
22
|
+
mid: '┼',
|
|
23
|
+
right: '┤',
|
|
24
|
+
other: '─',
|
|
25
|
+
},
|
|
26
|
+
tableBottom: {
|
|
27
|
+
left: '└',
|
|
28
|
+
mid: '┴',
|
|
29
|
+
right: '┘',
|
|
30
|
+
other: '─',
|
|
31
|
+
},
|
|
32
|
+
vertical: '│',
|
|
33
|
+
rowSeparator: {
|
|
34
|
+
left: '├',
|
|
35
|
+
mid: '┼',
|
|
36
|
+
right: '┤',
|
|
37
|
+
other: '─',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
exports.ALIGNMENTS = ['right', 'left', 'center'];
|
|
41
|
+
exports.COLORS = [
|
|
42
|
+
'red',
|
|
43
|
+
'green',
|
|
44
|
+
'yellow',
|
|
45
|
+
'white',
|
|
46
|
+
'blue',
|
|
47
|
+
'magenta',
|
|
48
|
+
'cyan',
|
|
49
|
+
'white_bold',
|
|
50
|
+
'reset',
|
|
51
|
+
];
|
|
52
|
+
exports.DEFAULT_ROW_FONT_COLOR = 'white';
|
|
53
|
+
exports.DEFAULT_HEADER_FONT_COLOR = 'white_bold';
|
|
54
|
+
exports.DEFAULT_ROW_ALIGNMENT = 'right';
|
|
55
|
+
exports.DEFAULT_HEADER_ALIGNMENT = 'center';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ALIGNMENT, COLOR } from '../models/common.js';
|
|
2
|
+
import { TableStyleDetails } from '../models/internal-table.js';
|
|
3
|
+
export declare const DEFAULT_COLUMN_LEN = 20;
|
|
4
|
+
export declare const DEFAULT_ROW_SEPARATOR = false;
|
|
5
|
+
export declare const DEFAULT_TABLE_STYLE: TableStyleDetails;
|
|
6
|
+
export declare const ALIGNMENTS: string[];
|
|
7
|
+
export declare const COLORS: string[];
|
|
8
|
+
export declare const DEFAULT_ROW_FONT_COLOR: COLOR;
|
|
9
|
+
export declare const DEFAULT_HEADER_FONT_COLOR: COLOR;
|
|
10
|
+
export declare const DEFAULT_ROW_ALIGNMENT: ALIGNMENT;
|
|
11
|
+
export declare const DEFAULT_HEADER_ALIGNMENT: ALIGNMENT;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const DEFAULT_COLUMN_LEN = 20;
|
|
2
|
+
export const DEFAULT_ROW_SEPARATOR = false;
|
|
3
|
+
export const DEFAULT_TABLE_STYLE = {
|
|
4
|
+
/*
|
|
5
|
+
Default Style
|
|
6
|
+
┌────────────┬─────┬──────┐
|
|
7
|
+
│ foo │ bar │ baz │
|
|
8
|
+
│ frobnicate │ bar │ quuz │
|
|
9
|
+
└────────────┴─────┴──────┘
|
|
10
|
+
*/
|
|
11
|
+
headerTop: {
|
|
12
|
+
left: '┌',
|
|
13
|
+
mid: '┬',
|
|
14
|
+
right: '┐',
|
|
15
|
+
other: '─',
|
|
16
|
+
},
|
|
17
|
+
headerBottom: {
|
|
18
|
+
left: '├',
|
|
19
|
+
mid: '┼',
|
|
20
|
+
right: '┤',
|
|
21
|
+
other: '─',
|
|
22
|
+
},
|
|
23
|
+
tableBottom: {
|
|
24
|
+
left: '└',
|
|
25
|
+
mid: '┴',
|
|
26
|
+
right: '┘',
|
|
27
|
+
other: '─',
|
|
28
|
+
},
|
|
29
|
+
vertical: '│',
|
|
30
|
+
rowSeparator: {
|
|
31
|
+
left: '├',
|
|
32
|
+
mid: '┼',
|
|
33
|
+
right: '┤',
|
|
34
|
+
other: '─',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
export const ALIGNMENTS = ['right', 'left', 'center'];
|
|
38
|
+
export const COLORS = [
|
|
39
|
+
'red',
|
|
40
|
+
'green',
|
|
41
|
+
'yellow',
|
|
42
|
+
'white',
|
|
43
|
+
'blue',
|
|
44
|
+
'magenta',
|
|
45
|
+
'cyan',
|
|
46
|
+
'white_bold',
|
|
47
|
+
'reset',
|
|
48
|
+
];
|
|
49
|
+
export const DEFAULT_ROW_FONT_COLOR = 'white';
|
|
50
|
+
export const DEFAULT_HEADER_FONT_COLOR = 'white_bold';
|
|
51
|
+
export const DEFAULT_ROW_ALIGNMENT = 'right';
|
|
52
|
+
export const DEFAULT_HEADER_ALIGNMENT = 'center';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWidthLimitedColumnsArray = exports.createHeaderAsRow = exports.renderTableHorizontalBorders = exports.findLenOfColumn = exports.createRow = exports.createColumFromOnlyName = exports.createTableHorizontalBorders = exports.convertRawRowOptionsToStandard = exports.evaluateCellText = exports.cellText = void 0;
|
|
4
|
+
const console_utils_js_1 = require("./console-utils.cjs");
|
|
5
|
+
const string_utils_js_1 = require("./string-utils.cjs");
|
|
6
|
+
const table_constants_js_1 = require("./table-constants.cjs");
|
|
7
|
+
const max = (a, b) => Math.max(a, b);
|
|
8
|
+
// takes any input that is given by user and converts to string
|
|
9
|
+
const cellText = (text) => text === undefined || text === null ? '' : `${text}`;
|
|
10
|
+
exports.cellText = cellText;
|
|
11
|
+
// evaluate cell text with defined transform
|
|
12
|
+
const evaluateCellText = (text, transform) => (transform ? `${transform(text)}` : (0, exports.cellText)(text));
|
|
13
|
+
exports.evaluateCellText = evaluateCellText;
|
|
14
|
+
const convertRawRowOptionsToStandard = (options) => {
|
|
15
|
+
if (options) {
|
|
16
|
+
return {
|
|
17
|
+
color: options.color,
|
|
18
|
+
separator: options.separator || table_constants_js_1.DEFAULT_ROW_SEPARATOR,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
|
23
|
+
exports.convertRawRowOptionsToStandard = convertRawRowOptionsToStandard;
|
|
24
|
+
// ({ left: "╚", mid: "╩", right: "╝", other: "═" }, [5, 10, 7]) => "╚═══════╩════════════╩═════════╝"
|
|
25
|
+
const createTableHorizontalBorders = ({ left, mid, right, other }, column_lengths) => {
|
|
26
|
+
// ╚
|
|
27
|
+
let ret = left;
|
|
28
|
+
// ╚═══════╩═══════════════════════════════════════╩════════╩
|
|
29
|
+
column_lengths.forEach((len) => {
|
|
30
|
+
ret += other.repeat(len + 2);
|
|
31
|
+
ret += mid;
|
|
32
|
+
});
|
|
33
|
+
// ╚═══════╩═══════════════════════════════════════╩════════
|
|
34
|
+
ret = ret.slice(0, -mid.length);
|
|
35
|
+
// ╚═══════╩═══════════════════════════════════════╩════════╝
|
|
36
|
+
ret += right;
|
|
37
|
+
return ret;
|
|
38
|
+
};
|
|
39
|
+
exports.createTableHorizontalBorders = createTableHorizontalBorders;
|
|
40
|
+
// ("id") => { name: "id", title: "id" }
|
|
41
|
+
const createColumFromOnlyName = (name) => ({
|
|
42
|
+
name,
|
|
43
|
+
title: name,
|
|
44
|
+
});
|
|
45
|
+
exports.createColumFromOnlyName = createColumFromOnlyName;
|
|
46
|
+
// ("green", { id: 1, name: "John" }, true) => { color: "green", separator: true, text: { id: 1, name: "John" } }
|
|
47
|
+
const createRow = (color, text, separator) => ({
|
|
48
|
+
color,
|
|
49
|
+
separator,
|
|
50
|
+
text,
|
|
51
|
+
});
|
|
52
|
+
exports.createRow = createRow;
|
|
53
|
+
// ({ name: "id", title: "ID", minLen: 2 }, [{ text: { id: 1 } }, { text: { id: 100 } }]) => 3
|
|
54
|
+
// Calculates optimal column width based on content and constraints
|
|
55
|
+
const findLenOfColumn = (column, rows, charLength) => {
|
|
56
|
+
const columnId = column.name;
|
|
57
|
+
const columnTitle = column.title;
|
|
58
|
+
const datatransform = column.transform;
|
|
59
|
+
let length = max(0, column?.minLen || 0);
|
|
60
|
+
if (column.maxLen) {
|
|
61
|
+
// if customer input is mentioned a max width, lets see if all other can fit here
|
|
62
|
+
// if others cant fit find the max word length so that at least the table can be printed
|
|
63
|
+
length = max(length, max(column.maxLen, (0, string_utils_js_1.biggestWordInSentence)(columnTitle, charLength)));
|
|
64
|
+
length = rows.reduce((acc, row) => max(acc, (0, string_utils_js_1.biggestWordInSentence)((0, exports.evaluateCellText)(row.text[columnId], datatransform), charLength)), length);
|
|
65
|
+
return length;
|
|
66
|
+
}
|
|
67
|
+
length = max(length, (0, console_utils_js_1.findWidthInConsole)(columnTitle, charLength));
|
|
68
|
+
rows.forEach((row) => {
|
|
69
|
+
length = max(length, (0, console_utils_js_1.findWidthInConsole)((0, exports.evaluateCellText)(row.text[columnId], datatransform), charLength));
|
|
70
|
+
});
|
|
71
|
+
return length;
|
|
72
|
+
};
|
|
73
|
+
exports.findLenOfColumn = findLenOfColumn;
|
|
74
|
+
// ({ left: "╚", mid: "╩", right: "╝", other: "═" }, [5, 10, 7]) => "╚═══════╩════════════╩═════════╝"
|
|
75
|
+
// (undefined, [5, 10, 7]) => ""
|
|
76
|
+
const renderTableHorizontalBorders = (style, column_lengths) => {
|
|
77
|
+
const str = (0, exports.createTableHorizontalBorders)(style, column_lengths);
|
|
78
|
+
return str;
|
|
79
|
+
};
|
|
80
|
+
exports.renderTableHorizontalBorders = renderTableHorizontalBorders;
|
|
81
|
+
// (createRow, [{ name: "id", title: "ID" }, { name: "name", title: "Name" }]) =>
|
|
82
|
+
// { color: "white_bold", separator: false, text: { id: "ID", name: "Name" } }
|
|
83
|
+
const createHeaderAsRow = (createRowFn, columns) => {
|
|
84
|
+
const headerColor = table_constants_js_1.DEFAULT_HEADER_FONT_COLOR;
|
|
85
|
+
const row = createRowFn(headerColor, {}, false);
|
|
86
|
+
columns.forEach((column) => {
|
|
87
|
+
row.text[column.name] = column.title;
|
|
88
|
+
});
|
|
89
|
+
return row;
|
|
90
|
+
};
|
|
91
|
+
exports.createHeaderAsRow = createHeaderAsRow;
|
|
92
|
+
// ([{ name: "desc", length: 10 }], { text: { desc: "This is a long description" } })
|
|
93
|
+
// => { desc: ["This is a", "long", "description"] }
|
|
94
|
+
const getWidthLimitedColumnsArray = (columns, row, charLength) => {
|
|
95
|
+
const ret = {};
|
|
96
|
+
columns.forEach((column) => {
|
|
97
|
+
ret[column.name] = (0, string_utils_js_1.splitTextIntoTextsOfMinLen)((0, exports.cellText)(row.text[column.name]), column.length || table_constants_js_1.DEFAULT_COLUMN_LEN, charLength);
|
|
98
|
+
});
|
|
99
|
+
return ret;
|
|
100
|
+
};
|
|
101
|
+
exports.getWidthLimitedColumnsArray = getWidthLimitedColumnsArray;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CharLengthDict, COLOR, Dictionary, Row } from '../models/common.js';
|
|
2
|
+
import { CellValue, Valuetransform } from '../models/external-table.js';
|
|
3
|
+
import { Column, TableLineDetails } from '../models/internal-table.js';
|
|
4
|
+
export declare const cellText: (text: CellValue) => string;
|
|
5
|
+
export declare const evaluateCellText: (text: CellValue, transform?: Valuetransform) => string;
|
|
6
|
+
export interface RowOptionsRaw {
|
|
7
|
+
color?: string;
|
|
8
|
+
separator?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface RowOptions {
|
|
11
|
+
color: COLOR;
|
|
12
|
+
separator: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface CreateRowFunction {
|
|
15
|
+
(color: COLOR, text: Dictionary, separator: boolean): Row;
|
|
16
|
+
}
|
|
17
|
+
export declare const convertRawRowOptionsToStandard: (options?: RowOptionsRaw) => RowOptions | undefined;
|
|
18
|
+
export declare const createTableHorizontalBorders: ({ left, mid, right, other }: TableLineDetails, column_lengths: number[]) => string;
|
|
19
|
+
export declare const createColumFromOnlyName: (name: string) => {
|
|
20
|
+
name: string;
|
|
21
|
+
title: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const createRow: CreateRowFunction;
|
|
24
|
+
export declare const findLenOfColumn: (column: Column, rows: Row[], charLength?: CharLengthDict) => number;
|
|
25
|
+
export declare const renderTableHorizontalBorders: (style: TableLineDetails, column_lengths: number[]) => string;
|
|
26
|
+
export declare const createHeaderAsRow: (createRowFn: CreateRowFunction, columns: Column[]) => Row;
|
|
27
|
+
export declare const getWidthLimitedColumnsArray: (columns: Column[], row: Row, charLength?: CharLengthDict) => {
|
|
28
|
+
[key: string]: string[];
|
|
29
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { findWidthInConsole } from './console-utils.js';
|
|
2
|
+
import { biggestWordInSentence, splitTextIntoTextsOfMinLen, } from './string-utils.js';
|
|
3
|
+
import { DEFAULT_COLUMN_LEN, DEFAULT_HEADER_FONT_COLOR, DEFAULT_ROW_SEPARATOR, } from './table-constants.js';
|
|
4
|
+
const max = (a, b) => Math.max(a, b);
|
|
5
|
+
// takes any input that is given by user and converts to string
|
|
6
|
+
export const cellText = (text) => text === undefined || text === null ? '' : `${text}`;
|
|
7
|
+
// evaluate cell text with defined transform
|
|
8
|
+
export const evaluateCellText = (text, transform) => (transform ? `${transform(text)}` : cellText(text));
|
|
9
|
+
export const convertRawRowOptionsToStandard = (options) => {
|
|
10
|
+
if (options) {
|
|
11
|
+
return {
|
|
12
|
+
color: options.color,
|
|
13
|
+
separator: options.separator || DEFAULT_ROW_SEPARATOR,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
18
|
+
// ({ left: "╚", mid: "╩", right: "╝", other: "═" }, [5, 10, 7]) => "╚═══════╩════════════╩═════════╝"
|
|
19
|
+
export const createTableHorizontalBorders = ({ left, mid, right, other }, column_lengths) => {
|
|
20
|
+
// ╚
|
|
21
|
+
let ret = left;
|
|
22
|
+
// ╚═══════╩═══════════════════════════════════════╩════════╩
|
|
23
|
+
column_lengths.forEach((len) => {
|
|
24
|
+
ret += other.repeat(len + 2);
|
|
25
|
+
ret += mid;
|
|
26
|
+
});
|
|
27
|
+
// ╚═══════╩═══════════════════════════════════════╩════════
|
|
28
|
+
ret = ret.slice(0, -mid.length);
|
|
29
|
+
// ╚═══════╩═══════════════════════════════════════╩════════╝
|
|
30
|
+
ret += right;
|
|
31
|
+
return ret;
|
|
32
|
+
};
|
|
33
|
+
// ("id") => { name: "id", title: "id" }
|
|
34
|
+
export const createColumFromOnlyName = (name) => ({
|
|
35
|
+
name,
|
|
36
|
+
title: name,
|
|
37
|
+
});
|
|
38
|
+
// ("green", { id: 1, name: "John" }, true) => { color: "green", separator: true, text: { id: 1, name: "John" } }
|
|
39
|
+
export const createRow = (color, text, separator) => ({
|
|
40
|
+
color,
|
|
41
|
+
separator,
|
|
42
|
+
text,
|
|
43
|
+
});
|
|
44
|
+
// ({ name: "id", title: "ID", minLen: 2 }, [{ text: { id: 1 } }, { text: { id: 100 } }]) => 3
|
|
45
|
+
// Calculates optimal column width based on content and constraints
|
|
46
|
+
export const findLenOfColumn = (column, rows, charLength) => {
|
|
47
|
+
const columnId = column.name;
|
|
48
|
+
const columnTitle = column.title;
|
|
49
|
+
const datatransform = column.transform;
|
|
50
|
+
let length = max(0, column?.minLen || 0);
|
|
51
|
+
if (column.maxLen) {
|
|
52
|
+
// if customer input is mentioned a max width, lets see if all other can fit here
|
|
53
|
+
// if others cant fit find the max word length so that at least the table can be printed
|
|
54
|
+
length = max(length, max(column.maxLen, biggestWordInSentence(columnTitle, charLength)));
|
|
55
|
+
length = rows.reduce((acc, row) => max(acc, biggestWordInSentence(evaluateCellText(row.text[columnId], datatransform), charLength)), length);
|
|
56
|
+
return length;
|
|
57
|
+
}
|
|
58
|
+
length = max(length, findWidthInConsole(columnTitle, charLength));
|
|
59
|
+
rows.forEach((row) => {
|
|
60
|
+
length = max(length, findWidthInConsole(evaluateCellText(row.text[columnId], datatransform), charLength));
|
|
61
|
+
});
|
|
62
|
+
return length;
|
|
63
|
+
};
|
|
64
|
+
// ({ left: "╚", mid: "╩", right: "╝", other: "═" }, [5, 10, 7]) => "╚═══════╩════════════╩═════════╝"
|
|
65
|
+
// (undefined, [5, 10, 7]) => ""
|
|
66
|
+
export const renderTableHorizontalBorders = (style, column_lengths) => {
|
|
67
|
+
const str = createTableHorizontalBorders(style, column_lengths);
|
|
68
|
+
return str;
|
|
69
|
+
};
|
|
70
|
+
// (createRow, [{ name: "id", title: "ID" }, { name: "name", title: "Name" }]) =>
|
|
71
|
+
// { color: "white_bold", separator: false, text: { id: "ID", name: "Name" } }
|
|
72
|
+
export const createHeaderAsRow = (createRowFn, columns) => {
|
|
73
|
+
const headerColor = DEFAULT_HEADER_FONT_COLOR;
|
|
74
|
+
const row = createRowFn(headerColor, {}, false);
|
|
75
|
+
columns.forEach((column) => {
|
|
76
|
+
row.text[column.name] = column.title;
|
|
77
|
+
});
|
|
78
|
+
return row;
|
|
79
|
+
};
|
|
80
|
+
// ([{ name: "desc", length: 10 }], { text: { desc: "This is a long description" } })
|
|
81
|
+
// => { desc: ["This is a", "long", "description"] }
|
|
82
|
+
export const getWidthLimitedColumnsArray = (columns, row, charLength) => {
|
|
83
|
+
const ret = {};
|
|
84
|
+
columns.forEach((column) => {
|
|
85
|
+
ret[column.name] = splitTextIntoTextsOfMinLen(cellText(row.text[column.name]), column.length || DEFAULT_COLUMN_LEN, charLength);
|
|
86
|
+
});
|
|
87
|
+
return ret;
|
|
88
|
+
};
|