umt 2.2.0 → 2.3.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.
Files changed (44) hide show
  1. package/module/Function/curry.d.ts +141 -0
  2. package/module/Function/curry.js +11 -0
  3. package/module/Function/curry.js.map +1 -0
  4. package/module/Function/index.d.ts +1 -0
  5. package/module/Function/index.js +2 -0
  6. package/module/Function/index.js.map +1 -0
  7. package/module/Tool/index.d.ts +1 -0
  8. package/module/Tool/index.js +1 -0
  9. package/module/Tool/index.js.map +1 -1
  10. package/module/Tool/pipe.d.ts +66 -0
  11. package/module/Tool/pipe.js +98 -0
  12. package/module/Tool/pipe.js.map +1 -0
  13. package/module/Validate/index.d.ts +1 -0
  14. package/module/Validate/index.js +1 -0
  15. package/module/Validate/index.js.map +1 -1
  16. package/module/Validate/isBun.js +0 -1
  17. package/module/Validate/isBun.js.map +1 -1
  18. package/module/Validate/isString.d.ts +9 -0
  19. package/module/Validate/isString.js +12 -0
  20. package/module/Validate/isString.js.map +1 -0
  21. package/module/es5/Function/curry.d.ts +141 -0
  22. package/module/es5/Function/curry.js +38 -0
  23. package/module/es5/Function/index.d.ts +1 -0
  24. package/module/es5/Function/index.js +16 -0
  25. package/module/es5/Tool/index.d.ts +1 -0
  26. package/module/es5/Tool/index.js +11 -0
  27. package/module/es5/Tool/pipe.d.ts +66 -0
  28. package/module/es5/Tool/pipe.js +129 -0
  29. package/module/es5/Validate/index.d.ts +1 -0
  30. package/module/es5/Validate/index.js +11 -0
  31. package/module/es5/Validate/isBun.js +0 -1
  32. package/module/es5/Validate/isString.d.ts +9 -0
  33. package/module/es5/Validate/isString.js +16 -0
  34. package/module/es5/index.d.ts +1 -0
  35. package/module/es5/index.js +11 -0
  36. package/module/es5/tests/unit/Function/curry.test.d.ts +1 -0
  37. package/module/es5/tests/unit/Function/curry.test.js +138 -0
  38. package/module/es5/tests/unit/Tool/pipe.test.d.ts +1 -0
  39. package/module/es5/tests/unit/Tool/pipe.test.js +445 -0
  40. package/module/es5/tsconfig.tsbuildinfo +1 -1
  41. package/module/index.d.ts +1 -0
  42. package/module/index.js +1 -0
  43. package/module/index.js.map +1 -1
  44. package/package.json +19 -18
@@ -0,0 +1,66 @@
1
+ import { type Result } from "@/Error/safeExecute";
2
+ /**
3
+ * A class to handle pipeline processing
4
+ * Allows chaining transformations in a fluent interface
5
+ * @template T Type of the current value
6
+ */
7
+ export declare class Pipe<T> {
8
+ private readonly value;
9
+ /**
10
+ * @param value Current value in the pipe
11
+ */
12
+ constructor(value: T);
13
+ /**
14
+ * Applies a transformation function and returns a new Pipe instance
15
+ * @param fn Transformation function to apply
16
+ * @returns New Pipe instance with transformed value
17
+ */
18
+ map<U>(function_: (input: T) => U): Pipe<U>;
19
+ /**
20
+ * Applies a transformation function only if the condition is met
21
+ * @param predicate Condition function
22
+ * @param fn Transformation function to apply if condition is met
23
+ * @returns New Pipe instance with conditionally transformed value
24
+ */
25
+ when<U>(predicate: (input: T) => boolean, function_: (input: T) => U): Pipe<U | T>;
26
+ /**
27
+ * Executes a side effect without changing the value
28
+ * @param fn Function to execute as a side effect
29
+ * @returns Same Pipe instance
30
+ */
31
+ tap(function_: (input: T) => void): Pipe<T>;
32
+ /**
33
+ * Strictly filters the value based on a predicate function
34
+ * Throws an error if the predicate returns false
35
+ * @param predicate Condition function that determines if value should be filtered
36
+ * @returns New Pipe instance with filtered value and narrowed type
37
+ * @throws Error if the predicate returns false
38
+ */
39
+ filterStrict<U extends T>(predicate: (input: T) => input is U): Pipe<U>;
40
+ /**
41
+ * Filters the value based on a predicate function
42
+ * Returns a default value if the predicate returns false
43
+ * @param predicate Condition function that determines if value should be filtered
44
+ * @param defaultValue Default value to use if predicate returns false
45
+ * @returns New Pipe instance with filtered value or default value
46
+ */
47
+ filterWithDefault<U extends T>(predicate: (input: T) => input is U, defaultValue: U): Pipe<U>;
48
+ /**
49
+ * Filters the value based on a predicate function
50
+ * Returns a Result type containing either the filtered value or an error
51
+ * @param predicate Condition function that determines if value should be filtered
52
+ * @returns New Pipe instance with Result containing filtered value or error
53
+ */
54
+ filterResult<U extends T>(predicate: (input: T) => input is U): Pipe<Result<U, Error>>;
55
+ /**
56
+ * Terminates the pipeline and returns the final value
57
+ * @returns Final result of the pipeline processing
58
+ */
59
+ end(): T;
60
+ }
61
+ /**
62
+ * Creates a new Pipe instance with an initial value
63
+ * @param initialValue Initial value for the pipeline
64
+ * @returns New Pipe instance
65
+ */
66
+ export declare function pipe<T>(initialValue: T): Pipe<T>;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Pipe = void 0;
7
+ exports.pipe = pipe;
8
+ var _safeExecute = require("@/Error/safeExecute");
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
12
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ /**
16
+ * A class to handle pipeline processing
17
+ * Allows chaining transformations in a fluent interface
18
+ * @template T Type of the current value
19
+ */
20
+ var Pipe = exports.Pipe = /*#__PURE__*/function () {
21
+ /**
22
+ * @param value Current value in the pipe
23
+ */
24
+ function Pipe(value) {
25
+ _classCallCheck(this, Pipe);
26
+ this.value = value;
27
+ }
28
+
29
+ /**
30
+ * Applies a transformation function and returns a new Pipe instance
31
+ * @param fn Transformation function to apply
32
+ * @returns New Pipe instance with transformed value
33
+ */
34
+ return _createClass(Pipe, [{
35
+ key: "map",
36
+ value: function map(function_) {
37
+ return new Pipe(function_(this.value));
38
+ }
39
+
40
+ /**
41
+ * Applies a transformation function only if the condition is met
42
+ * @param predicate Condition function
43
+ * @param fn Transformation function to apply if condition is met
44
+ * @returns New Pipe instance with conditionally transformed value
45
+ */
46
+ }, {
47
+ key: "when",
48
+ value: function when(predicate, function_) {
49
+ return predicate(this.value) ? new Pipe(function_(this.value)) : new Pipe(this.value);
50
+ }
51
+
52
+ /**
53
+ * Executes a side effect without changing the value
54
+ * @param fn Function to execute as a side effect
55
+ * @returns Same Pipe instance
56
+ */
57
+ }, {
58
+ key: "tap",
59
+ value: function tap(function_) {
60
+ function_(this.value);
61
+ return this;
62
+ }
63
+
64
+ /**
65
+ * Strictly filters the value based on a predicate function
66
+ * Throws an error if the predicate returns false
67
+ * @param predicate Condition function that determines if value should be filtered
68
+ * @returns New Pipe instance with filtered value and narrowed type
69
+ * @throws Error if the predicate returns false
70
+ */
71
+ }, {
72
+ key: "filterStrict",
73
+ value: function filterStrict(predicate) {
74
+ if (predicate(this.value)) {
75
+ return new Pipe(this.value);
76
+ }
77
+ throw new Error("Value did not match filter predicate");
78
+ }
79
+
80
+ /**
81
+ * Filters the value based on a predicate function
82
+ * Returns a default value if the predicate returns false
83
+ * @param predicate Condition function that determines if value should be filtered
84
+ * @param defaultValue Default value to use if predicate returns false
85
+ * @returns New Pipe instance with filtered value or default value
86
+ */
87
+ }, {
88
+ key: "filterWithDefault",
89
+ value: function filterWithDefault(predicate, defaultValue) {
90
+ return predicate(this.value) ? new Pipe(this.value) : new Pipe(defaultValue);
91
+ }
92
+
93
+ /**
94
+ * Filters the value based on a predicate function
95
+ * Returns a Result type containing either the filtered value or an error
96
+ * @param predicate Condition function that determines if value should be filtered
97
+ * @returns New Pipe instance with Result containing filtered value or error
98
+ */
99
+ }, {
100
+ key: "filterResult",
101
+ value: function filterResult(predicate) {
102
+ var _this = this;
103
+ return new Pipe((0, _safeExecute.safeExecute)(function () {
104
+ if (predicate(_this.value)) {
105
+ return _this.value;
106
+ }
107
+ throw new Error("Value did not match filter predicate");
108
+ }));
109
+ }
110
+
111
+ /**
112
+ * Terminates the pipeline and returns the final value
113
+ * @returns Final result of the pipeline processing
114
+ */
115
+ }, {
116
+ key: "end",
117
+ value: function end() {
118
+ return this.value;
119
+ }
120
+ }]);
121
+ }();
122
+ /**
123
+ * Creates a new Pipe instance with an initial value
124
+ * @param initialValue Initial value for the pipeline
125
+ * @returns New Pipe instance
126
+ */
127
+ function pipe(initialValue) {
128
+ return new Pipe(initialValue);
129
+ }
@@ -15,4 +15,5 @@ export * from "./isNotEmpty";
15
15
  export * from "./isNumber";
16
16
  export * from "./isPerfectSquare";
17
17
  export * from "./isPrimeNumber";
18
+ export * from "./isString";
18
19
  export * from "./isValueNaN";
@@ -190,6 +190,17 @@ Object.keys(_isPrimeNumber).forEach(function (key) {
190
190
  }
191
191
  });
192
192
  });
193
+ var _isString = require("./isString");
194
+ Object.keys(_isString).forEach(function (key) {
195
+ if (key === "default" || key === "__esModule") return;
196
+ if (key in exports && exports[key] === _isString[key]) return;
197
+ Object.defineProperty(exports, key, {
198
+ enumerable: true,
199
+ get: function get() {
200
+ return _isString[key];
201
+ }
202
+ });
203
+ });
193
204
  var _isValueNaN = require("./isValueNaN");
194
205
  Object.keys(_isValueNaN).forEach(function (key) {
195
206
  if (key === "default" || key === "__esModule") return;
@@ -9,7 +9,6 @@ exports.isBun = void 0;
9
9
  */
10
10
  var isBun = exports.isBun = function isBun() {
11
11
  try {
12
- // @ts-expect-error: Bun is only defined in Bun runtime
13
12
  return typeof Bun !== "undefined";
14
13
  } catch (_unused) {
15
14
  return false;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Determines if the value is a string
3
+ * @param {unknown} value - Value to check
4
+ * @returns boolean - True if the value is a string, false otherwise
5
+ * @example isString("test"); // true
6
+ * isString(123); // false
7
+ */
8
+ declare const isString: (value: unknown) => value is string;
9
+ export { isString };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isString = void 0;
7
+ /**
8
+ * Determines if the value is a string
9
+ * @param {unknown} value - Value to check
10
+ * @returns boolean - True if the value is a string, false otherwise
11
+ * @example isString("test"); // true
12
+ * isString(123); // false
13
+ */
14
+ var isString = exports.isString = function isString(value) {
15
+ return typeof value === "string";
16
+ };
@@ -4,6 +4,7 @@ export * from "./Color";
4
4
  export * from "./Consts";
5
5
  export * from "./Date";
6
6
  export * from "./Error";
7
+ export * from "./Function";
7
8
  export * from "./IP";
8
9
  export * from "./Math";
9
10
  export * from "./Object";
@@ -69,6 +69,17 @@ Object.keys(_Error).forEach(function (key) {
69
69
  }
70
70
  });
71
71
  });
72
+ var _Function = require("./Function");
73
+ Object.keys(_Function).forEach(function (key) {
74
+ if (key === "default" || key === "__esModule") return;
75
+ if (key in exports && exports[key] === _Function[key]) return;
76
+ Object.defineProperty(exports, key, {
77
+ enumerable: true,
78
+ get: function get() {
79
+ return _Function[key];
80
+ }
81
+ });
82
+ });
72
83
  var _IP = require("./IP");
73
84
  Object.keys(_IP).forEach(function (key) {
74
85
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ var _curry = require("@/Function/curry");
4
+ describe("curry", function () {
5
+ test("should curry a function with 0 arguments", function () {
6
+ var func = function func() {
7
+ return "hello";
8
+ };
9
+ var curriedFunc = (0, _curry.curry)(func);
10
+ expect(curriedFunc()).toBe("hello");
11
+ });
12
+ test("should curry a function with 1 argument", function () {
13
+ var func = function func(a) {
14
+ return a * 2;
15
+ };
16
+ var curriedFunc = (0, _curry.curry)(func);
17
+ expect(curriedFunc(5)).toBe(10);
18
+ });
19
+ test("should curry a function with 2 arguments", function () {
20
+ var func = function func(a, b) {
21
+ return a + b;
22
+ };
23
+ var curriedFunc = (0, _curry.curry)(func);
24
+ expect(curriedFunc(2)(3)).toBe(5);
25
+ expect(curriedFunc(2, 3)).toBe(5);
26
+ });
27
+ test("should curry a function with 3 arguments", function () {
28
+ var func = function func(a, b, c) {
29
+ return a * b + c;
30
+ };
31
+ var curriedFunc = (0, _curry.curry)(func);
32
+ expect(curriedFunc(2)(3)(4)).toBe(10);
33
+ expect(curriedFunc(2, 3)(4)).toBe(10);
34
+ expect(curriedFunc(2)(3, 4)).toBe(10);
35
+ expect(curriedFunc(2, 3, 4)).toBe(10);
36
+ });
37
+ test("should curry a function with 4 arguments", function () {
38
+ var func = function func(a, b, c, d) {
39
+ return a + b + c + d;
40
+ };
41
+ var curriedFunc = (0, _curry.curry)(func);
42
+ expect(curriedFunc(1)(2)(3)(4)).toBe(10);
43
+ expect(curriedFunc(1, 2)(3)(4)).toBe(10);
44
+ expect(curriedFunc(1)(2, 3)(4)).toBe(10);
45
+ expect(curriedFunc(1)(2)(3, 4)).toBe(10);
46
+ expect(curriedFunc(1, 2, 3)(4)).toBe(10);
47
+ expect(curriedFunc(1, 2)(3, 4)).toBe(10);
48
+ expect(curriedFunc(1, 2, 3, 4)).toBe(10);
49
+ });
50
+ test("should curry a function with 5 arguments", function () {
51
+ var func = function func(a, b, c, d, e) {
52
+ return a + b + c + d + e;
53
+ };
54
+ var curriedFunc = (0, _curry.curry)(func);
55
+ expect(curriedFunc(1)(2)(3)(4)(5)).toBe(15);
56
+ expect(curriedFunc(1, 2)(3)(4)(5)).toBe(15);
57
+ expect(curriedFunc(1)(2, 3)(4)(5)).toBe(15);
58
+ expect(curriedFunc(1)(2)(3, 4)(5)).toBe(15);
59
+ expect(curriedFunc(1)(2)(3)(4, 5)).toBe(15);
60
+ expect(curriedFunc(1, 2, 3)(4)(5)).toBe(15);
61
+ expect(curriedFunc(1, 2)(3, 4)(5)).toBe(15);
62
+ expect(curriedFunc(1, 2)(3)(4, 5)).toBe(15);
63
+ expect(curriedFunc(1, 2, 3, 4)(5)).toBe(15);
64
+ expect(curriedFunc(1, 2, 3)(4, 5)).toBe(15);
65
+ expect(curriedFunc(1, 2, 3, 4, 5)).toBe(15);
66
+ });
67
+ test("should curry a function with 6 arguments", function () {
68
+ var func = function func(a, b, c, d, e, f) {
69
+ return a + b + c + d + e + f;
70
+ };
71
+ var curriedFunc = (0, _curry.curry)(func);
72
+ expect(curriedFunc(1)(2)(3)(4)(5)(6)).toBe(21);
73
+ expect(curriedFunc(1, 2)(3)(4)(5)(6)).toBe(21);
74
+ expect(curriedFunc(1)(2, 3)(4)(5)(6)).toBe(21);
75
+ expect(curriedFunc(1)(2)(3, 4)(5)(6)).toBe(21);
76
+ expect(curriedFunc(1)(2)(3)(4, 5)(6)).toBe(21);
77
+ expect(curriedFunc(1)(2)(3)(4)(5, 6)).toBe(21);
78
+ expect(curriedFunc(1, 2, 3)(4)(5)(6)).toBe(21);
79
+ expect(curriedFunc(1, 2)(3, 4)(5)(6)).toBe(21);
80
+ expect(curriedFunc(1, 2)(3)(4, 5)(6)).toBe(21);
81
+ expect(curriedFunc(1, 2)(3)(4)(5, 6)).toBe(21);
82
+ expect(curriedFunc(1, 2, 3, 4)(5)(6)).toBe(21);
83
+ expect(curriedFunc(1, 2, 3)(4, 5)(6)).toBe(21);
84
+ expect(curriedFunc(1, 2, 3)(4)(5, 6)).toBe(21);
85
+ expect(curriedFunc(1, 2, 3, 4, 5)(6)).toBe(21);
86
+ expect(curriedFunc(1, 2, 3, 4)(5, 6)).toBe(21);
87
+ expect(curriedFunc(1, 2, 3, 4, 5, 6)).toBe(21);
88
+ });
89
+ test("should handle different argument types", function () {
90
+ var func = function func(a, b, c) {
91
+ return "".concat(a).concat(b).concat(c);
92
+ };
93
+ var curriedFunc = (0, _curry.curry)(func);
94
+ expect(curriedFunc(1)("hello")(true)).toBe("1hellotrue");
95
+ expect(curriedFunc(1, "hello")(true)).toBe("1hellotrue");
96
+ expect(curriedFunc(1)("hello", true)).toBe("1hellotrue");
97
+ expect(curriedFunc(1, "hello", true)).toBe("1hellotrue");
98
+ });
99
+
100
+ // 追加テスト
101
+
102
+ test("should curry a function with object and array arguments", function () {
103
+ var func = function func(obj, arr) {
104
+ return obj.x + arr.reduce(function (a, b) {
105
+ return a + b;
106
+ }, 0);
107
+ };
108
+ var curriedFunc = (0, _curry.curry)(func);
109
+ expect(curriedFunc({
110
+ x: 5
111
+ })([1, 2, 3])).toBe(11);
112
+ expect(curriedFunc({
113
+ x: 5
114
+ }, [1, 2, 3])).toBe(11);
115
+ });
116
+ test("should curry a function with function arguments", function () {
117
+ var func = function func(f, x) {
118
+ return f(x);
119
+ };
120
+ var curriedFunc = (0, _curry.curry)(func);
121
+ var _double = function _double(x) {
122
+ return x * 2;
123
+ };
124
+ expect(curriedFunc(_double)(5)).toBe(10);
125
+ expect(curriedFunc(_double, 5)).toBe(10);
126
+ });
127
+ test("should preserve the original 'this' context", function () {
128
+ var obj = {
129
+ multiplier: 2,
130
+ multiply: function multiply(a, b) {
131
+ return a * b * this.multiplier;
132
+ }
133
+ };
134
+ var curriedMultiply = (0, _curry.curry)(obj.multiply.bind(obj));
135
+ expect(curriedMultiply(3)(4)).toBe(24);
136
+ expect(curriedMultiply(3, 4)).toBe(24);
137
+ });
138
+ });
@@ -0,0 +1 @@
1
+ export {};