@fincity/kirun-js 1.0.0
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/.prettierrc +9 -0
- package/__tests__/engine/function/system/array/AddFirstTest.ts +235 -0
- package/__tests__/engine/function/system/array/AddTest.ts +126 -0
- package/__tests__/engine/function/system/array/BinarySearchTest.ts +135 -0
- package/__tests__/engine/function/system/array/CompareTest.ts +48 -0
- package/__tests__/engine/function/system/array/CopyTest.ts +86 -0
- package/__tests__/engine/function/system/array/DeleteFirstTest.ts +103 -0
- package/__tests__/engine/function/system/array/DeleteFromTest.ts +232 -0
- package/__tests__/engine/function/system/array/DeleteLastTest.ts +103 -0
- package/__tests__/engine/function/system/array/DeleteTest.ts +110 -0
- package/__tests__/engine/function/system/array/DisjointTest.ts +184 -0
- package/__tests__/engine/function/system/array/Equals.ts +67 -0
- package/__tests__/engine/function/system/array/FillTest.ts +36 -0
- package/__tests__/engine/function/system/array/FrequencyTest.ts +97 -0
- package/__tests__/engine/function/system/array/IndexOfArrayTest.ts +347 -0
- package/__tests__/engine/function/system/array/IndexOfTest.ts +267 -0
- package/__tests__/engine/function/system/array/InsertTest.ts +229 -0
- package/__tests__/engine/function/system/array/LastIndexOfArrayTest.ts +213 -0
- package/__tests__/engine/function/system/array/LastIndexOfTest.ts +253 -0
- package/__tests__/engine/function/system/array/MaxTest.ts +98 -0
- package/__tests__/engine/function/system/array/MinTest.ts +99 -0
- package/__tests__/engine/function/system/array/MisMatchTest.ts +215 -0
- package/__tests__/engine/function/system/array/ReverseTest.ts +235 -0
- package/__tests__/engine/function/system/array/RotateTest.ts +137 -0
- package/__tests__/engine/function/system/array/ShuffleTest.ts +154 -0
- package/__tests__/engine/function/system/array/SortTest.ts +130 -0
- package/__tests__/engine/function/system/array/SubArrayTest.ts +236 -0
- package/__tests__/engine/function/system/math/AddTest.ts +12 -0
- package/__tests__/engine/function/system/string/ConcatenateTest.ts +46 -0
- package/__tests__/engine/function/system/string/DeleteForGivenLengthTest.ts +38 -0
- package/__tests__/engine/function/system/string/InsertAtGivenPositionTest.ts +53 -0
- package/__tests__/engine/function/system/string/PostPadTest.ts +54 -0
- package/__tests__/engine/function/system/string/PrePadTest.ts +54 -0
- package/__tests__/engine/function/system/string/RegionMatchesTest.ts +78 -0
- package/__tests__/engine/function/system/string/ReverseTest.ts +36 -0
- package/__tests__/engine/function/system/string/SplitTest.ts +61 -0
- package/__tests__/engine/function/system/string/StringFunctionRepoTest2.ts +126 -0
- package/__tests__/engine/function/system/string/StringFunctionRepoTest3.ts +54 -0
- package/__tests__/engine/function/system/string/StringFunctionRepositoryTest.ts +146 -0
- package/__tests__/engine/function/system/string/ToStringTest.ts +43 -0
- package/__tests__/engine/function/system/string/TrimToTest.ts +28 -0
- package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +26 -0
- package/__tests__/engine/runtime/KIRuntimeTest.ts +351 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +128 -0
- package/__tests__/engine/runtime/expression/ExpressionTest.ts +33 -0
- package/__tests__/engine/runtime/expression/tokenextractor/OutputMapTokenValueExtractorTest.ts +44 -0
- package/__tests__/engine/runtime/expression/tokenextractor/TokenValueExtractorTest.ts +72 -0
- package/__tests__/engine/util/LinkedListTest.ts +29 -0
- package/__tests__/engine/util/string/StringFormatterTest.ts +17 -0
- package/__tests__/indexTest.ts +33 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +430 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +54 -0
- package/src/engine/HybridRepository.ts +18 -0
- package/src/engine/Repository.ts +3 -0
- package/src/engine/constant/KIRunConstants.ts +7 -0
- package/src/engine/exception/ExecutionException.ts +12 -0
- package/src/engine/exception/KIRuntimeException.ts +12 -0
- package/src/engine/function/AbstractFunction.ts +76 -0
- package/src/engine/function/Function.ts +13 -0
- package/src/engine/function/system/GenerateEvent.ts +76 -0
- package/src/engine/function/system/If.ts +40 -0
- package/src/engine/function/system/array/AbstractArrayFunction.ts +158 -0
- package/src/engine/function/system/array/Add.ts +31 -0
- package/src/engine/function/system/array/AddFirst.ts +44 -0
- package/src/engine/function/system/array/BinarySearch.ts +66 -0
- package/src/engine/function/system/array/Compare.ts +150 -0
- package/src/engine/function/system/array/Copy.ts +56 -0
- package/src/engine/function/system/array/Delete.ts +63 -0
- package/src/engine/function/system/array/DeleteFirst.ts +22 -0
- package/src/engine/function/system/array/DeleteFrom.ts +51 -0
- package/src/engine/function/system/array/DeleteLast.ts +23 -0
- package/src/engine/function/system/array/Disjoint.ts +85 -0
- package/src/engine/function/system/array/Equals.ts +36 -0
- package/src/engine/function/system/array/Fill.ts +51 -0
- package/src/engine/function/system/array/Frequency.ts +68 -0
- package/src/engine/function/system/array/IndexOf.ts +56 -0
- package/src/engine/function/system/array/IndexOfArray.ts +67 -0
- package/src/engine/function/system/array/Insert.ts +48 -0
- package/src/engine/function/system/array/LastIndexOf.ts +62 -0
- package/src/engine/function/system/array/LastIndexOfArray.ts +70 -0
- package/src/engine/function/system/array/Max.ts +31 -0
- package/src/engine/function/system/array/Min.ts +32 -0
- package/src/engine/function/system/array/MisMatch.ts +66 -0
- package/src/engine/function/system/array/Reverse.ts +50 -0
- package/src/engine/function/system/array/Rotate.ts +43 -0
- package/src/engine/function/system/array/Shuffle.ts +31 -0
- package/src/engine/function/system/array/Sort.ts +70 -0
- package/src/engine/function/system/array/SubArray.ts +48 -0
- package/src/engine/function/system/context/Create.ts +73 -0
- package/src/engine/function/system/context/Get.ts +55 -0
- package/src/engine/function/system/context/SetFunction.ts +244 -0
- package/src/engine/function/system/loop/CountLoop.ts +55 -0
- package/src/engine/function/system/loop/RangeLoop.ts +120 -0
- package/src/engine/function/system/math/Add.ts +34 -0
- package/src/engine/function/system/math/GenericMathFunction.ts +80 -0
- package/src/engine/function/system/math/Hypotenuse.ts +57 -0
- package/src/engine/function/system/math/MathFunctionRepository.ts +63 -0
- package/src/engine/function/system/math/Maximum.ts +38 -0
- package/src/engine/function/system/math/Minimum.ts +38 -0
- package/src/engine/function/system/math/Random.ts +27 -0
- package/src/engine/function/system/string/AbstractStringFunction.ts +409 -0
- package/src/engine/function/system/string/Concatenate.ts +57 -0
- package/src/engine/function/system/string/DeleteForGivenLength.ts +82 -0
- package/src/engine/function/system/string/InsertAtGivenPosition.ts +72 -0
- package/src/engine/function/system/string/PostPad.ts +83 -0
- package/src/engine/function/system/string/PrePad.ts +73 -0
- package/src/engine/function/system/string/RegionMatches.ts +119 -0
- package/src/engine/function/system/string/ReplaceAtGivenPosition.ts +101 -0
- package/src/engine/function/system/string/Reverse.ts +62 -0
- package/src/engine/function/system/string/Split.ts +53 -0
- package/src/engine/function/system/string/StringFunctionRepository.ts +60 -0
- package/src/engine/function/system/string/ToString.ts +45 -0
- package/src/engine/function/system/string/TrimTo.ts +55 -0
- package/src/engine/json/JsonExpression.ts +11 -0
- package/src/engine/json/schema/Schema.ts +670 -0
- package/src/engine/json/schema/SchemaUtil.ts +145 -0
- package/src/engine/json/schema/array/ArraySchemaType.ts +44 -0
- package/src/engine/json/schema/object/AdditionalPropertiesType.ts +32 -0
- package/src/engine/json/schema/string/StringFormat.ts +7 -0
- package/src/engine/json/schema/type/MultipleType.ts +28 -0
- package/src/engine/json/schema/type/SchemaType.ts +11 -0
- package/src/engine/json/schema/type/SingleType.ts +23 -0
- package/src/engine/json/schema/type/Type.ts +6 -0
- package/src/engine/json/schema/type/TypeUtil.ts +25 -0
- package/src/engine/json/schema/validator/AnyOfAllOfOneOfValidator.ts +108 -0
- package/src/engine/json/schema/validator/ArrayValidator.ts +145 -0
- package/src/engine/json/schema/validator/BooleanValidator.ts +24 -0
- package/src/engine/json/schema/validator/NullValidator.ts +17 -0
- package/src/engine/json/schema/validator/NumberValidator.ts +115 -0
- package/src/engine/json/schema/validator/ObjectValidator.ts +184 -0
- package/src/engine/json/schema/validator/SchemaValidator.ts +141 -0
- package/src/engine/json/schema/validator/StringValidator.ts +97 -0
- package/src/engine/json/schema/validator/TypeValidator.ts +49 -0
- package/src/engine/json/schema/validator/exception/SchemaReferenceException.ts +19 -0
- package/src/engine/json/schema/validator/exception/SchemaValidationException.ts +22 -0
- package/src/engine/model/AbstractStatement.ts +29 -0
- package/src/engine/model/Argument.ts +36 -0
- package/src/engine/model/Event.ts +62 -0
- package/src/engine/model/EventResult.ts +34 -0
- package/src/engine/model/FunctionDefinition.ts +69 -0
- package/src/engine/model/FunctionOutput.ts +37 -0
- package/src/engine/model/FunctionOutputGenerator.ts +5 -0
- package/src/engine/model/FunctionSignature.ts +67 -0
- package/src/engine/model/Parameter.ts +97 -0
- package/src/engine/model/ParameterReference.ts +57 -0
- package/src/engine/model/ParameterReferenceType.ts +4 -0
- package/src/engine/model/ParameterType.ts +4 -0
- package/src/engine/model/Position.ts +40 -0
- package/src/engine/model/Statement.ts +101 -0
- package/src/engine/model/StatementGroup.ts +37 -0
- package/src/engine/namespaces/Namespaces.ts +11 -0
- package/src/engine/repository/KIRunFunctionRepository.ts +37 -0
- package/src/engine/repository/KIRunSchemaRepository.ts +24 -0
- package/src/engine/runtime/ContextElement.ts +28 -0
- package/src/engine/runtime/FunctionExecutionParameters.ts +74 -0
- package/src/engine/runtime/KIRuntime.ts +653 -0
- package/src/engine/runtime/StatementExecution.ts +61 -0
- package/src/engine/runtime/StatementMessage.ts +30 -0
- package/src/engine/runtime/StatementMessageType.ts +5 -0
- package/src/engine/runtime/expression/Expression.ts +330 -0
- package/src/engine/runtime/expression/ExpressionEvaluator.ts +305 -0
- package/src/engine/runtime/expression/ExpressionToken.ts +15 -0
- package/src/engine/runtime/expression/ExpressionTokenValue.ts +23 -0
- package/src/engine/runtime/expression/Operation.ts +190 -0
- package/src/engine/runtime/expression/exception/ExpressionEvaluationException.ts +15 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticAdditionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticDivisionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticInetgerDivisionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticModulusOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticMultiplicationOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArithmeticSubtractionOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/ArrayOperator.ts +31 -0
- package/src/engine/runtime/expression/operators/binary/BinaryOperator.ts +15 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseAndOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseLeftShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseOrOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseRightShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseUnsignedRightShiftOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/BitwiseXorOperator.ts +9 -0
- package/src/engine/runtime/expression/operators/binary/LogicalAndOperator.ts +25 -0
- package/src/engine/runtime/expression/operators/binary/LogicalEqualOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanEqualOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalGreaterThanOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalLessThanEqualOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalLessThanOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/binary/LogicalNotEqualOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/binary/LogicalOrOperator.ts +25 -0
- package/src/engine/runtime/expression/operators/binary/ObjectOperator.ts +24 -0
- package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryMinusOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/unary/ArithmeticUnaryPlusOperator.ts +13 -0
- package/src/engine/runtime/expression/operators/unary/BitwiseComplementOperator.ts +22 -0
- package/src/engine/runtime/expression/operators/unary/LogicalNotOperator.ts +22 -0
- package/src/engine/runtime/expression/operators/unary/UnaryOperator.ts +15 -0
- package/src/engine/runtime/expression/tokenextractor/LiteralTokenValueExtractor.ts +64 -0
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +136 -0
- package/src/engine/runtime/graph/ExecutionGraph.ts +81 -0
- package/src/engine/runtime/graph/GraphVertex.ts +118 -0
- package/src/engine/runtime/graph/GraphVertexType.ts +4 -0
- package/src/engine/runtime/tokenextractor/ArgumentsTokenValueExtractor.ts +22 -0
- package/src/engine/runtime/tokenextractor/ContextTokenValueExtractor.ts +37 -0
- package/src/engine/runtime/tokenextractor/OutputMapTokenValueExtractor.ts +32 -0
- package/src/engine/util/ArrayUtil.ts +23 -0
- package/src/engine/util/LinkedList.ts +229 -0
- package/src/engine/util/MapUtil.ts +86 -0
- package/src/engine/util/NullCheck.ts +3 -0
- package/src/engine/util/Tuples.ts +43 -0
- package/src/engine/util/primitive/PrimitiveUtil.ts +143 -0
- package/src/engine/util/string/StringBuilder.ts +59 -0
- package/src/engine/util/string/StringFormatter.ts +25 -0
- package/src/engine/util/string/StringUtil.ts +48 -0
- package/src/index.ts +13 -0
- package/tsconfig.json +6 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { ExecutionException } from '../../exception/ExecutionException';
|
|
2
|
+
import { KIRuntimeException } from '../../exception/KIRuntimeException';
|
|
3
|
+
import { JsonExpression } from '../../json/JsonExpression';
|
|
4
|
+
import { SchemaType } from '../../json/schema/type/SchemaType';
|
|
5
|
+
import { isNullValue } from '../NullCheck';
|
|
6
|
+
import { StringFormatter } from '../string/StringFormatter';
|
|
7
|
+
import { Tuple2 } from '../Tuples';
|
|
8
|
+
|
|
9
|
+
export class PrimitiveUtil {
|
|
10
|
+
public static findPrimitiveNullAsBoolean(element: any): Tuple2<SchemaType, any> {
|
|
11
|
+
if (!element) return new Tuple2(SchemaType.BOOLEAN, false);
|
|
12
|
+
|
|
13
|
+
let typof: string = typeof element;
|
|
14
|
+
if (typof === 'object')
|
|
15
|
+
throw new ExecutionException(
|
|
16
|
+
StringFormatter.format('$ is not a primitive type', element),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
let value: any = element;
|
|
20
|
+
|
|
21
|
+
if (typof === 'boolean') return new Tuple2(SchemaType.BOOLEAN, value);
|
|
22
|
+
|
|
23
|
+
if (typof === 'string') return new Tuple2(SchemaType.STRING, value);
|
|
24
|
+
|
|
25
|
+
return PrimitiveUtil.findPrimitiveNumberType(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static findPrimitive(element: any): Tuple2<SchemaType, any> {
|
|
29
|
+
if (isNullValue(element)) return new Tuple2(SchemaType.NULL, undefined);
|
|
30
|
+
|
|
31
|
+
let typof: string = typeof element;
|
|
32
|
+
|
|
33
|
+
if (typof === 'object')
|
|
34
|
+
throw new ExecutionException(
|
|
35
|
+
StringFormatter.format('$ is not a primitive type', element),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
let value: any = element;
|
|
39
|
+
|
|
40
|
+
if (typof === 'boolean') return new Tuple2(SchemaType.BOOLEAN, value);
|
|
41
|
+
|
|
42
|
+
if (typof === 'string') return new Tuple2(SchemaType.STRING, value);
|
|
43
|
+
|
|
44
|
+
return PrimitiveUtil.findPrimitiveNumberType(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static findPrimitiveNumberType(element: any): Tuple2<SchemaType, any> {
|
|
48
|
+
if (isNullValue(element) || Array.isArray(element) || typeof element == 'object')
|
|
49
|
+
throw new ExecutionException(
|
|
50
|
+
StringFormatter.format('Unable to convert $ to a number.', element),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
let value: any = element;
|
|
54
|
+
|
|
55
|
+
// I think we should not forcibly convert a string to number, it was needed in java as we were using GSON.
|
|
56
|
+
// if (typeof value === "string") {
|
|
57
|
+
// if (!/^[\d]{0,}[.]{0,1}[\d]{1,}$/.test(value)) //Don't do this, I need to enhance to accommadate the exponent form.
|
|
58
|
+
// throw new ExecutionException(StringFormatter.format("Unable to convert $ to a number.", value));
|
|
59
|
+
// let fv = parseFloat(value);
|
|
60
|
+
// let iv = parseInt(value);
|
|
61
|
+
|
|
62
|
+
// if (iv === fv)
|
|
63
|
+
// return new Tuple2(SchemaType.LONG, iv);
|
|
64
|
+
// else
|
|
65
|
+
// return new Tuple2(SchemaType.DOUBLE, fv);
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
let num: number = value as number;
|
|
70
|
+
if (Number.isInteger(num)) return new Tuple2(SchemaType.LONG, num);
|
|
71
|
+
else return new Tuple2(SchemaType.DOUBLE, num);
|
|
72
|
+
} catch (err: any) {
|
|
73
|
+
throw new ExecutionException(
|
|
74
|
+
StringFormatter.format('Unable to convert $ to a number.', value),
|
|
75
|
+
err,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public static compare(a: any, b: any): number {
|
|
81
|
+
if (a == b) return 0;
|
|
82
|
+
|
|
83
|
+
if (isNullValue(a) || isNullValue(b)) return isNullValue(a) ? -1 : 1;
|
|
84
|
+
|
|
85
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
86
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
87
|
+
if (a.length != b.length) return a.length - b.length;
|
|
88
|
+
for (let i = 0; i < a.length; i++) {
|
|
89
|
+
let cmp: number = this.compare(a[i], b[i]);
|
|
90
|
+
if (cmp != 0) return cmp;
|
|
91
|
+
}
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
return Array.isArray(a) ? -1 : 1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const typofa = typeof a;
|
|
98
|
+
const typofb = typeof b;
|
|
99
|
+
|
|
100
|
+
if (typofa === 'object' || typofb === 'object') {
|
|
101
|
+
if (typofa === 'object' && typofb === 'object') {
|
|
102
|
+
Object.keys(a).forEach((key) => {
|
|
103
|
+
let cmp = this.compare(a[key], b[key]);
|
|
104
|
+
if (cmp != 0) return cmp;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return this.comparePrimitive(a, b);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public static comparePrimitive(oa: any, ob: any): number {
|
|
113
|
+
if (isNullValue(oa) || isNullValue(ob)) {
|
|
114
|
+
if (isNullValue(oa) && isNullValue(ob)) return 0;
|
|
115
|
+
return isNullValue(oa) ? -1 : 1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (oa == ob) return 0;
|
|
119
|
+
|
|
120
|
+
if (typeof oa == 'boolean' || typeof ob == 'boolean') return oa ? -1 : 1;
|
|
121
|
+
|
|
122
|
+
if (typeof oa == 'string' || typeof ob == 'string') {
|
|
123
|
+
return oa + '' < ob + '' ? -1 : 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (typeof oa == 'number' || typeof ob == 'number') {
|
|
127
|
+
return oa - ob;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private static baseNumberType(num: number): SchemaType {
|
|
134
|
+
if (Number.isInteger(num)) return SchemaType.LONG;
|
|
135
|
+
else return SchemaType.DOUBLE;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public static toPrimitiveType(e: any): number {
|
|
139
|
+
return e as number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private constructor() {}
|
|
143
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { KIRunConstants } from '../../constant/KIRunConstants';
|
|
2
|
+
import { KIRuntimeException } from '../../exception/KIRuntimeException';
|
|
3
|
+
|
|
4
|
+
export class StringBuilder {
|
|
5
|
+
private str: string;
|
|
6
|
+
|
|
7
|
+
public constructor(str?: string) {
|
|
8
|
+
this.str = str ?? '';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public append(x: any): StringBuilder {
|
|
12
|
+
this.str += x;
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public toString(): string {
|
|
17
|
+
return '' + this.str;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public trim(): StringBuilder {
|
|
21
|
+
this.str = this.str.trim();
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public setLength(num: number): StringBuilder {
|
|
26
|
+
this.str = this.str.substring(0, num);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public length(): number {
|
|
31
|
+
return this.str.length;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public charAt(index: number): string {
|
|
35
|
+
return this.str.charAt(index);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public deleteCharAt(index: number): StringBuilder {
|
|
39
|
+
this.checkIndex(index);
|
|
40
|
+
this.str = this.str.substring(0, index) + this.str.substring(index + 1);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public insert(index: number, str: string): StringBuilder {
|
|
45
|
+
this.str = this.str.substring(0, index) + str + this.str.substring(index);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private checkIndex(index: number): void {
|
|
50
|
+
if (index >= this.str.length)
|
|
51
|
+
throw new KIRuntimeException(
|
|
52
|
+
`Index ${index} is greater than or equal to ${this.str.length}`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public substring(start: number, end: number): string {
|
|
57
|
+
return this.str.substring(start, end);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class StringFormatter {
|
|
2
|
+
public static format(formatString: string, ...params: any[]): string {
|
|
3
|
+
if (!params || params.length == 0) return formatString;
|
|
4
|
+
|
|
5
|
+
let sb: string = '';
|
|
6
|
+
let ind: number = 0;
|
|
7
|
+
let chr: string = '';
|
|
8
|
+
let prevchar: string = chr;
|
|
9
|
+
let length: number = formatString.length;
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < length; i++) {
|
|
12
|
+
chr = formatString.charAt(i);
|
|
13
|
+
|
|
14
|
+
if (chr == '$' && prevchar == '\\') sb = sb.substring(0, i - 1) + chr;
|
|
15
|
+
else if (chr == '$' && ind < params.length) sb += params[ind++];
|
|
16
|
+
else sb += chr;
|
|
17
|
+
|
|
18
|
+
prevchar = chr;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return sb.toString();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private constructor() {}
|
|
25
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { KIRuntimeException } from '../../exception/KIRuntimeException';
|
|
2
|
+
import { StringFormatter } from './StringFormatter';
|
|
3
|
+
|
|
4
|
+
export class StringUtil {
|
|
5
|
+
private constructor() {}
|
|
6
|
+
|
|
7
|
+
public static nthIndex(str: string, c: string, from: number = 0, occurance: number): number {
|
|
8
|
+
if (!str) throw new KIRuntimeException('String cannot be null');
|
|
9
|
+
|
|
10
|
+
if (from < 0 || from >= str.length)
|
|
11
|
+
throw new KIRuntimeException(
|
|
12
|
+
StringFormatter.format('Cannot search from index : $', from),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
if (occurance <= 0 || occurance > str.length)
|
|
16
|
+
throw new KIRuntimeException(
|
|
17
|
+
StringFormatter.format('Cannot search for occurance : $', occurance),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
while (from < str.length) {
|
|
21
|
+
if (str.charAt(from) == c) {
|
|
22
|
+
--occurance;
|
|
23
|
+
if (occurance == 0) return from;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
++from;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return -1;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static splitAtFirstOccurance(
|
|
33
|
+
str: string,
|
|
34
|
+
c: string,
|
|
35
|
+
): [string | undefined, string | undefined] {
|
|
36
|
+
if (!str) return [undefined, undefined];
|
|
37
|
+
|
|
38
|
+
let index: number = str.indexOf(c);
|
|
39
|
+
|
|
40
|
+
if (index == -1) return [str, undefined];
|
|
41
|
+
|
|
42
|
+
return [str.substring(0, index), str.substring(index + 1)];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public static isNullOrBlank(str: string | undefined): boolean {
|
|
46
|
+
return !str || str.trim() == '';
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './engine/util/Tuples';
|
|
2
|
+
export * from './engine/Repository';
|
|
3
|
+
export * from './engine/HybridRepository';
|
|
4
|
+
export * from './engine/json/schema/Schema';
|
|
5
|
+
export * from './engine/json/schema/type/SchemaType';
|
|
6
|
+
export * from './engine/json/schema/validator/SchemaValidator';
|
|
7
|
+
export * from './engine/constant/KIRunConstants';
|
|
8
|
+
export * from './engine/exception/ExecutionException';
|
|
9
|
+
export * from './engine/exception/KIRuntimeException';
|
|
10
|
+
export * from './engine/function/Function';
|
|
11
|
+
export * from './engine/function/AbstractFunction';
|
|
12
|
+
export * from './engine/namespaces/Namespaces';
|
|
13
|
+
export * from './engine/runtime/KIRuntime';
|