@mutates/core 1.0.1 → 1.2.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/README.md CHANGED
@@ -1,3 +1,73 @@
1
1
  # @mutates/core
2
2
 
3
- [WIP]
3
+ 🔧 **@mutates/core** is the essential package of the Mutates toolset, providing the core
4
+ functionality to manipulate the Abstract Syntax Tree (AST) of TypeScript files. It serves as the
5
+ backbone for other specialized packages within the Mutates ecosystem.
6
+
7
+ ## Features
8
+
9
+ - **AST Manipulation:** Modify the AST of any TypeScript file with ease.
10
+ - **TypeScript Focused:** Specifically designed for TypeScript, ensuring optimal integration and
11
+ performance.
12
+ - **Extensible:** Can be extended with framework-specific packages for additional functionality.
13
+
14
+ ## Installation
15
+
16
+ To install the core package, use the following command:
17
+
18
+ ```sh
19
+ npm install @mutates/core
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Basic Example
25
+
26
+ Here is a simple example demonstrating how to use `@mutates/core` to modify a TypeScript file:
27
+
28
+ ```typescript
29
+ import { addFunctions, creataProject, createSourceFile, saveProject } from '@mutates/core';
30
+
31
+ // Initialize a new project
32
+ createProject();
33
+
34
+ // Add a TypeScript file to the project
35
+ createSourceFile(
36
+ 'example.ts',
37
+ `
38
+ const greet = (name: string) => {
39
+ return 'Hello, ' + name;
40
+ };
41
+ `,
42
+ );
43
+
44
+ // Perform some transformations
45
+ addFunctions('example.ts', {
46
+ name: 'farewell',
47
+ isExported: true,
48
+ statements: "return 'buy!'",
49
+ });
50
+
51
+ // Save the modified file
52
+ saveProject();
53
+ ```
54
+
55
+ ## API Reference
56
+
57
+ For a comprehensive guide on the available APIs and their usage, please refer to the
58
+ [official documentation](https://mutates.katsuba.dev/packages/core)
59
+
60
+ ## Contributing
61
+
62
+ 🤝 Contributions are welcome! If you have any improvements or suggestions, feel free to open an
63
+ issue or submit a pull request.
64
+
65
+ ## License
66
+
67
+ 📄 `@mutates/core` is licensed under the Apache-2.0 License. See the
68
+ [LICENSE](https://github.com/ikatsuba/mutates/blob/main/LICENSE) file for more information.
69
+
70
+ ---
71
+
72
+ For further assistance or to report issues, please visit our
73
+ [GitHub repository](https://github.com/ikatsuba/mutates).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mutates/core",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "keywords": [
5
5
  "typescript",
6
6
  "ast",
package/src/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './lib/accessors';
2
+ export * from './lib/arrays';
2
3
  export * from './lib/classes';
3
4
  export * from './lib/constructors';
4
5
  export * from './lib/decorators';
@@ -6,6 +7,7 @@ export * from './lib/enums';
6
7
  export * from './lib/exports';
7
8
  export * from './lib/fs/file-system';
8
9
  export * from './lib/functions';
10
+ export * from './lib/helpers';
9
11
  export * from './lib/imports';
10
12
  export * from './lib/interfaces';
11
13
  export * from './lib/methods';
package/src/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./lib/accessors"), exports);
5
+ tslib_1.__exportStar(require("./lib/arrays"), exports);
5
6
  tslib_1.__exportStar(require("./lib/classes"), exports);
6
7
  tslib_1.__exportStar(require("./lib/constructors"), exports);
7
8
  tslib_1.__exportStar(require("./lib/decorators"), exports);
@@ -9,6 +10,7 @@ tslib_1.__exportStar(require("./lib/enums"), exports);
9
10
  tslib_1.__exportStar(require("./lib/exports"), exports);
10
11
  tslib_1.__exportStar(require("./lib/fs/file-system"), exports);
11
12
  tslib_1.__exportStar(require("./lib/functions"), exports);
13
+ tslib_1.__exportStar(require("./lib/helpers"), exports);
12
14
  tslib_1.__exportStar(require("./lib/imports"), exports);
13
15
  tslib_1.__exportStar(require("./lib/interfaces"), exports);
14
16
  tslib_1.__exportStar(require("./lib/methods"), exports);
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,wDAA8B;AAC9B,6DAAmC;AACnC,2DAAiC;AACjC,sDAA4B;AAC5B,wDAA8B;AAC9B,+DAAqC;AACrC,0DAAgC;AAChC,wDAA8B;AAC9B,2DAAiC;AACjC,wDAA8B;AAC9B,uDAA6B;AAC7B,wDAA8B;AAC9B,2DAAiC;AACjC,4DAAkC;AAClC,sDAA4B;AAC5B,0DAAgC;AAChC,mDAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,uDAA6B;AAC7B,wDAA8B;AAC9B,6DAAmC;AACnC,2DAAiC;AACjC,sDAA4B;AAC5B,wDAA8B;AAC9B,+DAAqC;AACrC,0DAAgC;AAChC,wDAA8B;AAC9B,wDAA8B;AAC9B,2DAAiC;AACjC,wDAA8B;AAC9B,uDAA6B;AAC7B,wDAA8B;AAC9B,2DAAiC;AACjC,4DAAkC;AAClC,sDAA4B;AAC5B,0DAAgC;AAChC,mDAAyB"}
@@ -0,0 +1,5 @@
1
+ import { ArrayLiteralExpression } from 'ts-morph';
2
+ export declare function pushToArray(array: ArrayLiteralExpression, ...items: string[]): void;
3
+ export declare function pushToArrayIfNotExists(array: ArrayLiteralExpression, ...items: string[]): void;
4
+ export declare function arrayIncludes(array: ArrayLiteralExpression, item: string): boolean;
5
+ export declare function removeFromArray(array: ArrayLiteralExpression, ...items: string[]): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeFromArray = exports.arrayIncludes = exports.pushToArrayIfNotExists = exports.pushToArray = void 0;
4
+ function pushToArray(array, ...items) {
5
+ array.addElements(items);
6
+ }
7
+ exports.pushToArray = pushToArray;
8
+ function pushToArrayIfNotExists(array, ...items) {
9
+ array.addElements(items.filter((item) => !arrayIncludes(array, item)));
10
+ }
11
+ exports.pushToArrayIfNotExists = pushToArrayIfNotExists;
12
+ function arrayIncludes(array, item) {
13
+ return !!array.getElements().find((exp) => exp.getText() === item);
14
+ }
15
+ exports.arrayIncludes = arrayIncludes;
16
+ function removeFromArray(array, ...items) {
17
+ for (const item of items) {
18
+ const index = array.getElements().findIndex((exp) => exp.getText() === item);
19
+ if (index !== -1) {
20
+ array.removeElement(index);
21
+ }
22
+ }
23
+ }
24
+ exports.removeFromArray = removeFromArray;
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/arrays/index.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAC,KAA6B,EAAE,GAAG,KAAe;IAC3E,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAFD,kCAEC;AAED,SAAgB,sBAAsB,CAAC,KAA6B,EAAE,GAAG,KAAe;IACtF,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC;AAFD,wDAEC;AAED,SAAgB,aAAa,CAAC,KAA6B,EAAE,IAAY;IACvE,OAAO,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC,CAAC;AACrE,CAAC;AAFD,sCAEC;AAED,SAAgB,eAAe,CAAC,KAA6B,EAAE,GAAG,KAAe;IAC/E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC,CAAC;QAE7E,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC;AARD,0CAQC"}
@@ -0,0 +1 @@
1
+ export * from './match';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./match"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/helpers/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB"}
@@ -0,0 +1,2 @@
1
+ import { MinimatchOptions } from 'minimatch';
2
+ export declare function match(list: string | readonly string[], patterns: string | readonly string[], options?: MinimatchOptions): string[];
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*
3
+ * This file includes code from the library multimatch.
4
+ * License for the original code:
5
+ *
6
+ * MIT License
7
+ *
8
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ *
16
+ * The code was sourced from: https://github.com/sindresorhus/multimatch/blob/main/index.js
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.match = void 0;
20
+ const minimatch_1 = require("minimatch");
21
+ function match(list, patterns, options) {
22
+ list = [list].flat();
23
+ patterns = [patterns].flat();
24
+ if (list.length === 0 || patterns.length === 0) {
25
+ return [];
26
+ }
27
+ let result = [];
28
+ for (const item of list) {
29
+ for (let pattern of patterns) {
30
+ let process = (res, matches) => res.concat(matches);
31
+ if (pattern[0] === '!') {
32
+ pattern = pattern.slice(1);
33
+ process = (res, matches) => res.filter((x) => !matches.includes(x));
34
+ }
35
+ result = process(result, minimatch_1.minimatch.match([item], pattern, options));
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ exports.match = match;
41
+ //# sourceMappingURL=match.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/helpers/match.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,yCAAwD;AAExD,SAAgB,KAAK,CACnB,IAAgC,EAChC,QAAoC,EACpC,OAA0B;IAE1B,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IACrB,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;IAE7B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,MAAM,GAAa,EAAE,CAAC;IAC1B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,KAAK,IAAI,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,OAAO,GAAG,CAAC,GAAa,EAAE,OAAiB,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAExE,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACvB,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC3B,OAAO,GAAG,CAAC,GAAa,EAAE,OAAiB,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1F,CAAC;YAED,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,qBAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AA3BD,sBA2BC"}