@codedrifters/utils 0.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/LICENSE +19 -0
- package/README.md +298 -0
- package/lib/aws/aws-types.d.ts +44 -0
- package/lib/aws/aws-types.js +40 -0
- package/lib/git/git-utils.d.ts +8 -0
- package/lib/git/git-utils.js +36 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +20 -0
- package/lib/lib/git-utils.d.ts +8 -0
- package/lib/lib/git-utils.js +36 -0
- package/lib/lib/string-utils.d.ts +14 -0
- package/lib/lib/string-utils.js +64 -0
- package/lib/string/string-utils.d.ts +14 -0
- package/lib/string/string-utils.js +64 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 CodeDrifters
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# @codedrifters/utils
|
|
2
|
+
|
|
3
|
+
Common utilities and helper functions for CodeDrifter projects. This package provides reusable utility functions for working with Git, string manipulation, and other common tasks.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Utility Functions](#utility-functions)
|
|
9
|
+
- [Git Utilities](#git-utilities)
|
|
10
|
+
- [String Utilities](#string-utilities)
|
|
11
|
+
- [AWS Types](#aws-types)
|
|
12
|
+
- [API Reference](#api-reference)
|
|
13
|
+
- [Further Documentation](#further-documentation)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
**Important:** Always configure dependencies through Projen/Configulator, not by manually installing packages via command line. This ensures consistent dependency management across your project.
|
|
18
|
+
|
|
19
|
+
### In a Monorepo (Recommended)
|
|
20
|
+
|
|
21
|
+
If you're using `@codedrifters/configulator` in a monorepo, add the package as a dependency in your sub-project configuration:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { TypeScriptProject } from '@codedrifters/configulator';
|
|
25
|
+
import { MonorepoProject } from '@codedrifters/configulator';
|
|
26
|
+
|
|
27
|
+
const myProject = new TypeScriptProject({
|
|
28
|
+
name: 'my-project',
|
|
29
|
+
packageName: '@myorg/my-project',
|
|
30
|
+
outdir: 'packages/my-project',
|
|
31
|
+
parent: root, // Your MonorepoProject instance
|
|
32
|
+
|
|
33
|
+
deps: [
|
|
34
|
+
'@codedrifters/utils',
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### In a Standalone Project
|
|
40
|
+
|
|
41
|
+
If you're using Projen directly, add the package to your `deps` array:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { typescript } from 'projen';
|
|
45
|
+
|
|
46
|
+
const project = new typescript.TypeScriptProject({
|
|
47
|
+
name: 'my-project',
|
|
48
|
+
|
|
49
|
+
deps: [
|
|
50
|
+
'@codedrifters/utils',
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### After Adding to Configuration
|
|
56
|
+
|
|
57
|
+
After updating your projenrc configuration file, run:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx projen
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This will update your `package.json` with the new dependency. Then run:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pnpm install
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
to install the newly configured dependencies.
|
|
70
|
+
|
|
71
|
+
## Utility Functions
|
|
72
|
+
|
|
73
|
+
### Git Utilities
|
|
74
|
+
|
|
75
|
+
Helper functions for working with Git in deployments and build processes.
|
|
76
|
+
|
|
77
|
+
#### `findGitBranch()`
|
|
78
|
+
|
|
79
|
+
Returns the current git branch name.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { findGitBranch } from '@codedrifters/utils/lib/git-utils';
|
|
83
|
+
|
|
84
|
+
const branch = findGitBranch();
|
|
85
|
+
// Returns: "feature/1234" or "main" etc.
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Example Usage:**
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { findGitBranch } from '@codedrifters/utils/lib/git-utils';
|
|
92
|
+
|
|
93
|
+
// Use in CDK deployment
|
|
94
|
+
const branch = findGitBranch();
|
|
95
|
+
const environment = branch === 'main' ? 'production' : 'staging';
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### `findGitRepoName()`
|
|
99
|
+
|
|
100
|
+
Returns the repository name. Works in both local environments and GitHub Actions.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { findGitRepoName } from '@codedrifters/utils/lib/git-utils';
|
|
104
|
+
|
|
105
|
+
const repoName = findGitRepoName();
|
|
106
|
+
// Returns: "codedrifters/packages" or similar
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**How it works:**
|
|
110
|
+
|
|
111
|
+
- In GitHub Actions, this uses the `GITHUB_REPOSITORY` environment variable
|
|
112
|
+
- Locally, it extracts the name from the git remote URL
|
|
113
|
+
|
|
114
|
+
**Example Usage:**
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { findGitRepoName } from '@codedrifters/utils/lib/git-utils';
|
|
118
|
+
|
|
119
|
+
const repoName = findGitRepoName();
|
|
120
|
+
console.log(`Deploying from repository: ${repoName}`);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### String Utilities
|
|
124
|
+
|
|
125
|
+
Helper functions for string manipulation and hashing.
|
|
126
|
+
|
|
127
|
+
#### `hashString(inString: string, trimLength?: number)`
|
|
128
|
+
|
|
129
|
+
Creates a SHA-256 hash of a string, optionally trimmed to a specific length.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { hashString } from '@codedrifters/utils/lib/string-utils';
|
|
133
|
+
|
|
134
|
+
const hash = hashString('my-string');
|
|
135
|
+
// Returns: Full SHA-256 hash
|
|
136
|
+
|
|
137
|
+
const shortHash = hashString('my-string', 8);
|
|
138
|
+
// Returns: First 8 characters of hash
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Parameters:**
|
|
142
|
+
- `inString: string` - The string to hash
|
|
143
|
+
- `trimLength?: number` - Optional length to trim the hash to (defaults to 999)
|
|
144
|
+
|
|
145
|
+
**Example Usage:**
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { hashString } from '@codedrifters/utils/lib/string-utils';
|
|
149
|
+
|
|
150
|
+
// Create a unique identifier from a string
|
|
151
|
+
const id = hashString('user-123', 16);
|
|
152
|
+
// Returns: First 16 characters of SHA-256 hash
|
|
153
|
+
|
|
154
|
+
// Full hash for security purposes
|
|
155
|
+
const secureHash = hashString('sensitive-data');
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### `trimStringLength(inputString: string, maxLength: number)`
|
|
159
|
+
|
|
160
|
+
Truncates a string to a maximum length if it exceeds it.
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { trimStringLength } from '@codedrifters/utils/lib/string-utils';
|
|
164
|
+
|
|
165
|
+
const short = trimStringLength('very long string', 10);
|
|
166
|
+
// Returns: "very long " (truncated to 10 chars)
|
|
167
|
+
|
|
168
|
+
const unchanged = trimStringLength('short', 10);
|
|
169
|
+
// Returns: "short" (no change needed)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Parameters:**
|
|
173
|
+
- `inputString: string` - The string to truncate
|
|
174
|
+
- `maxLength: number` - Maximum length of the string
|
|
175
|
+
|
|
176
|
+
**Example Usage:**
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { trimStringLength } from '@codedrifters/utils/lib/string-utils';
|
|
180
|
+
|
|
181
|
+
// Ensure string fits within AWS resource name limits
|
|
182
|
+
const resourceName = trimStringLength('very-long-resource-name', 63);
|
|
183
|
+
// Useful for AWS resource naming constraints
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### AWS Types
|
|
187
|
+
|
|
188
|
+
Type definitions for AWS deployment stages and environment types, commonly used in CDK deployment configurations.
|
|
189
|
+
|
|
190
|
+
#### `AWS_STAGE_TYPE` and `AwsStageType`
|
|
191
|
+
|
|
192
|
+
Constants and types for deployment stage classification (dev, stage, prod).
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { AWS_STAGE_TYPE, AwsStageType } from '@codedrifters/utils/lib/aws/aws-types';
|
|
196
|
+
|
|
197
|
+
// Use the constant
|
|
198
|
+
const stage = AWS_STAGE_TYPE.DEV; // "dev"
|
|
199
|
+
const prodStage = AWS_STAGE_TYPE.PROD; // "prod"
|
|
200
|
+
|
|
201
|
+
// Use the type
|
|
202
|
+
function configureDeployment(stage: AwsStageType) {
|
|
203
|
+
// stage can be "dev", "stage", or "prod"
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Available Values:**
|
|
208
|
+
- `AWS_STAGE_TYPE.DEV` - Development environment
|
|
209
|
+
- `AWS_STAGE_TYPE.STAGE` - Staging environment
|
|
210
|
+
- `AWS_STAGE_TYPE.PROD` - Production environment
|
|
211
|
+
|
|
212
|
+
#### `AWS_ENVIRONMENT_TYPE` and `AwsEnvironmentType`
|
|
213
|
+
|
|
214
|
+
Constants and types for environment classification (primary, secondary).
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import { AWS_ENVIRONMENT_TYPE, AwsEnvironmentType } from '@codedrifters/utils/lib/aws/aws-types';
|
|
218
|
+
|
|
219
|
+
// Use the constant
|
|
220
|
+
const env = AWS_ENVIRONMENT_TYPE.PRIMARY; // "primary"
|
|
221
|
+
const replicaEnv = AWS_ENVIRONMENT_TYPE.SECONDARY; // "secondary"
|
|
222
|
+
|
|
223
|
+
// Use the type
|
|
224
|
+
function configureRegion(env: AwsEnvironmentType) {
|
|
225
|
+
// env can be "primary" or "secondary"
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Available Values:**
|
|
230
|
+
- `AWS_ENVIRONMENT_TYPE.PRIMARY` - Primary region/environment
|
|
231
|
+
- `AWS_ENVIRONMENT_TYPE.SECONDARY` - Secondary/replica region/environment
|
|
232
|
+
|
|
233
|
+
**Example Usage:**
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { AWS_STAGE_TYPE, AWS_ENVIRONMENT_TYPE } from '@codedrifters/utils/lib/aws/aws-types';
|
|
237
|
+
import { AwsDeploymentTarget } from '@codedrifters/configulator';
|
|
238
|
+
|
|
239
|
+
// Configure a deployment target
|
|
240
|
+
new AwsDeploymentTarget(project, {
|
|
241
|
+
account: '123456789012',
|
|
242
|
+
region: 'us-east-1',
|
|
243
|
+
awsStageType: AWS_STAGE_TYPE.PROD,
|
|
244
|
+
awsEnvironmentType: AWS_ENVIRONMENT_TYPE.PRIMARY,
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## API Reference
|
|
249
|
+
|
|
250
|
+
### Exports
|
|
251
|
+
|
|
252
|
+
The package exports the following utility functions:
|
|
253
|
+
|
|
254
|
+
**Git Utilities:**
|
|
255
|
+
- `findGitBranch()` - Get current git branch name
|
|
256
|
+
- `findGitRepoName()` - Get repository name (works in local and CI environments)
|
|
257
|
+
|
|
258
|
+
**String Utilities:**
|
|
259
|
+
- `hashString(inString: string, trimLength?: number)` - Create SHA-256 hash of a string
|
|
260
|
+
- `trimStringLength(inputString: string, maxLength: number)` - Truncate string to maximum length
|
|
261
|
+
|
|
262
|
+
**AWS Types:**
|
|
263
|
+
- `AWS_STAGE_TYPE` - Constants for deployment stages (DEV, STAGE, PROD)
|
|
264
|
+
- `AwsStageType` - Type for deployment stage values
|
|
265
|
+
- `AWS_ENVIRONMENT_TYPE` - Constants for environment types (PRIMARY, SECONDARY)
|
|
266
|
+
- `AwsEnvironmentType` - Type for environment type values
|
|
267
|
+
|
|
268
|
+
### Import Paths
|
|
269
|
+
|
|
270
|
+
You can import utilities in two ways:
|
|
271
|
+
|
|
272
|
+
**Direct import from lib:**
|
|
273
|
+
```typescript
|
|
274
|
+
import { findGitBranch } from '@codedrifters/utils/lib/git-utils';
|
|
275
|
+
import { hashString } from '@codedrifters/utils/lib/string-utils';
|
|
276
|
+
import { AWS_STAGE_TYPE, AwsStageType } from '@codedrifters/utils/lib/aws/aws-types';
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
**Import from main package (if re-exported):**
|
|
280
|
+
```typescript
|
|
281
|
+
import { findGitBranch, hashString, AWS_STAGE_TYPE, AwsStageType } from '@codedrifters/utils';
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Further Documentation
|
|
285
|
+
|
|
286
|
+
### Package Information
|
|
287
|
+
|
|
288
|
+
- [NPM Package](https://www.npmjs.com/package/@codedrifters/utils) - View on NPM
|
|
289
|
+
- [GitHub Repository](https://github.com/codedrifters/packages) - Source code
|
|
290
|
+
|
|
291
|
+
### Related Packages
|
|
292
|
+
|
|
293
|
+
- [@codedrifters/constructs](../constructs/README.md) - AWS CDK constructs that use these utilities
|
|
294
|
+
- [@codedrifters/configulator](../configulator/README.md) - Projen configuration utilities
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
**Note:** This package is designed to be lightweight and dependency-free where possible. It uses Node.js built-in modules (`node:child_process`, `node:crypto`) for maximum compatibility.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage Types
|
|
3
|
+
*
|
|
4
|
+
* What stage of deployment is this? Dev, staging, or prod?
|
|
5
|
+
*/
|
|
6
|
+
export declare const AWS_STAGE_TYPE: {
|
|
7
|
+
/**
|
|
8
|
+
* Development environment, typically used for testing and development.
|
|
9
|
+
*/
|
|
10
|
+
readonly DEV: "dev";
|
|
11
|
+
/**
|
|
12
|
+
* Staging environment, used for pre-production testing.
|
|
13
|
+
*/
|
|
14
|
+
readonly STAGE: "stage";
|
|
15
|
+
/**
|
|
16
|
+
* Production environment, used for live deployments.
|
|
17
|
+
*/
|
|
18
|
+
readonly PROD: "prod";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Above const as a type.
|
|
22
|
+
*/
|
|
23
|
+
export type AwsStageType = (typeof AWS_STAGE_TYPE)[keyof typeof AWS_STAGE_TYPE];
|
|
24
|
+
/**
|
|
25
|
+
* Environment Types
|
|
26
|
+
*
|
|
27
|
+
* Is this a primary of secondary region / environment?
|
|
28
|
+
*/
|
|
29
|
+
export declare const AWS_ENVIRONMENT_TYPE: {
|
|
30
|
+
/**
|
|
31
|
+
* Account and region that represents the primary region for this service.
|
|
32
|
+
* For example, the base DynamoDB Region for global tables.
|
|
33
|
+
*/
|
|
34
|
+
readonly PRIMARY: "primary";
|
|
35
|
+
/**
|
|
36
|
+
* Account and region that represents a secondary region for this service.
|
|
37
|
+
* For example, a replica region for a global DynamoDB table.
|
|
38
|
+
*/
|
|
39
|
+
readonly SECONDARY: "secondary";
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Above const as a type.
|
|
43
|
+
*/
|
|
44
|
+
export type AwsEnvironmentType = (typeof AWS_ENVIRONMENT_TYPE)[keyof typeof AWS_ENVIRONMENT_TYPE];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AWS_ENVIRONMENT_TYPE = exports.AWS_STAGE_TYPE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Stage Types
|
|
6
|
+
*
|
|
7
|
+
* What stage of deployment is this? Dev, staging, or prod?
|
|
8
|
+
*/
|
|
9
|
+
exports.AWS_STAGE_TYPE = {
|
|
10
|
+
/**
|
|
11
|
+
* Development environment, typically used for testing and development.
|
|
12
|
+
*/
|
|
13
|
+
DEV: "dev",
|
|
14
|
+
/**
|
|
15
|
+
* Staging environment, used for pre-production testing.
|
|
16
|
+
*/
|
|
17
|
+
STAGE: "stage",
|
|
18
|
+
/**
|
|
19
|
+
* Production environment, used for live deployments.
|
|
20
|
+
*/
|
|
21
|
+
PROD: "prod",
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Environment Types
|
|
25
|
+
*
|
|
26
|
+
* Is this a primary of secondary region / environment?
|
|
27
|
+
*/
|
|
28
|
+
exports.AWS_ENVIRONMENT_TYPE = {
|
|
29
|
+
/**
|
|
30
|
+
* Account and region that represents the primary region for this service.
|
|
31
|
+
* For example, the base DynamoDB Region for global tables.
|
|
32
|
+
*/
|
|
33
|
+
PRIMARY: "primary",
|
|
34
|
+
/**
|
|
35
|
+
* Account and region that represents a secondary region for this service.
|
|
36
|
+
* For example, a replica region for a global DynamoDB table.
|
|
37
|
+
*/
|
|
38
|
+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U19FTlZJUk9OTUVOVF9UWVBFXTtcbiJdfQ==
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findGitRepoName = exports.findGitBranch = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the current full git branch name
|
|
7
|
+
*
|
|
8
|
+
* ie: feature/1234 returns feature/1234
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
const findGitBranch = () => {
|
|
12
|
+
return (0, node_child_process_1.execSync)("git rev-parse --abbrev-ref HEAD")
|
|
13
|
+
.toString("utf8")
|
|
14
|
+
.replace(/[\n\r\s]+$/, "");
|
|
15
|
+
};
|
|
16
|
+
exports.findGitBranch = findGitBranch;
|
|
17
|
+
const findGitRepoName = () => {
|
|
18
|
+
/**
|
|
19
|
+
* When running in github actions this will be populated.
|
|
20
|
+
*/
|
|
21
|
+
if (process.env.GITHUB_REPOSITORY) {
|
|
22
|
+
return process.env.GITHUB_REPOSITORY;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* locally, we need to extract the repo name from the git config.
|
|
26
|
+
*/
|
|
27
|
+
const remote = (0, node_child_process_1.execSync)("git config --get remote.origin.url")
|
|
28
|
+
.toString("utf8")
|
|
29
|
+
.replace(/[\n\r\s]+$/, "")
|
|
30
|
+
.trim();
|
|
31
|
+
const match = remote.match(/[:\/]([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
32
|
+
const repoName = match ? match[1] : "error-repo-name";
|
|
33
|
+
return repoName;
|
|
34
|
+
};
|
|
35
|
+
exports.findGitRepoName = findGitRepoName;
|
|
36
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2l0LXV0aWxzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2dpdC9naXQtdXRpbHMudH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mFtZSA9IG1hdGNoID8gbWF0Y2hbMV0gOiBcImVycm9yLXJlcG8tbmFtZVwiO1xuXG4gIHJldHVybiByZXBvTmFtZTtcbn07XG4iXX0=
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./aws/aws-types"), exports);
|
|
18
|
+
__exportStar(require("./git/git-utils"), exports);
|
|
19
|
+
__exportStar(require("./string/string-utils"), exports);
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLGtEQUFnQztBQUNoQyxrREFBZ0M7QUFDaEMsd0RBQXNDIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSBcIi4vYXdzL2F3cy10eXBlc1wiO1xuZXhwb3J0ICogZnJvbSBcIi4vZ2l0L2dpdC11dGlsc1wiO1xuZXhwb3J0ICogZnJvbSBcIi4vc3RyaW5nL3N0cmluZy11dGlsc1wiO1xuIl19
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findGitRepoName = exports.findGitBranch = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the current full git branch name
|
|
7
|
+
*
|
|
8
|
+
* ie: feature/1234 returns feature/1234
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
const findGitBranch = () => {
|
|
12
|
+
return (0, node_child_process_1.execSync)("git rev-parse --abbrev-ref HEAD")
|
|
13
|
+
.toString("utf8")
|
|
14
|
+
.replace(/[\n\r\s]+$/, "");
|
|
15
|
+
};
|
|
16
|
+
exports.findGitBranch = findGitBranch;
|
|
17
|
+
const findGitRepoName = () => {
|
|
18
|
+
/**
|
|
19
|
+
* When running in github actions this will be populated.
|
|
20
|
+
*/
|
|
21
|
+
if (process.env.GITHUB_REPOSITORY) {
|
|
22
|
+
return process.env.GITHUB_REPOSITORY;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* locally, we need to extract the repo name from the git config.
|
|
26
|
+
*/
|
|
27
|
+
const remote = (0, node_child_process_1.execSync)("git config --get remote.origin.url")
|
|
28
|
+
.toString("utf8")
|
|
29
|
+
.replace(/[\n\r\s]+$/, "")
|
|
30
|
+
.trim();
|
|
31
|
+
const match = remote.match(/[:\/]([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
32
|
+
const repoName = match ? match[1] : "error-repo-name";
|
|
33
|
+
return repoName;
|
|
34
|
+
};
|
|
35
|
+
exports.findGitRepoName = findGitRepoName;
|
|
36
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2l0LX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W90ZS5tYXRjaCgvWzpcXC9dKFteL10rXFwvW14vXSs/KSg/OlxcLmdpdCk/JC8pO1xuICBjb25zdCByZXBvTmFtZSA9IG1hdGNoID8gbWF0Y2hbMV0gOiBcImVycm9yLXJlcG8tbmFtZVwiO1xuXG4gIHJldHVybiByZXBvTmFtZTtcbn07XG4iXX0=
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param inString string to hash
|
|
4
|
+
* @param trimLength trim to this length (defaults to 999 chars)
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const hashString: (inString: string, trimLength?: number) => string;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param inputString string to truncate
|
|
11
|
+
* @param maxLength max length of this string
|
|
12
|
+
* @returns trimmed string
|
|
13
|
+
*/
|
|
14
|
+
export declare const trimStringLength: (inputString: string, maxLength: number) => string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.trimStringLength = exports.hashString = void 0;
|
|
37
|
+
const crypto = __importStar(require("node:crypto"));
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param inString string to hash
|
|
41
|
+
* @param trimLength trim to this length (defaults to 999 chars)
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
const hashString = (inString, trimLength = 999) => {
|
|
45
|
+
return crypto
|
|
46
|
+
.createHash("sha256")
|
|
47
|
+
.update(inString)
|
|
48
|
+
.digest("hex")
|
|
49
|
+
.substring(0, trimLength);
|
|
50
|
+
};
|
|
51
|
+
exports.hashString = hashString;
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param inputString string to truncate
|
|
55
|
+
* @param maxLength max length of this string
|
|
56
|
+
* @returns trimmed string
|
|
57
|
+
*/
|
|
58
|
+
const trimStringLength = (inputString, maxLength) => {
|
|
59
|
+
return inputString.length < maxLength
|
|
60
|
+
? inputString
|
|
61
|
+
: inputString.substring(0, maxLength);
|
|
62
|
+
};
|
|
63
|
+
exports.trimStringLength = trimStringLength;
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj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VsdHMgdG8gOTk5IGNoYXJzKVxuICogQHJldHVybnNcbiAqL1xuZXhwb3J0IGNvbnN0IGhhc2hTdHJpbmcgPSAoaW5TdHJpbmc6IHN0cmluZywgdHJpbUxlbmd0aDogbnVtYmVyID0gOTk5KSA9PiB7XG4gIHJldHVybiBjcnlwdG9cbiAgICAuY3JlYXRlSGFzaChcInNoYTI1NlwiKVxuICAgIC51cGRhdGUoaW5TdHJpbmcpXG4gICAgLmRpZ2VzdChcImhleFwiKVxuICAgIC5zdWJzdHJpbmcoMCwgdHJpbUxlbmd0aCk7XG59O1xuXG4vKipcbiAqXG4gKiBAcGFyYW0gaW5wdXRTdHJpbmcgc3RyaW5nIHRvIHRydW5jYXRlXG4gKiBAcGFyYW0gbWF4TGVuZ3RoIG1heCBsZW5ndGggb2YgdGhpcyBzdHJpbmdcbiAqIEByZXR1cm5zIHRyaW1tZWQgc3RyaW5nXG4gKi9cbmV4cG9ydCBjb25zdCB0cmltU3RyaW5nTGVuZ3RoID0gKGlucHV0U3RyaW5nOiBzdHJpbmcsIG1heExlbmd0aDogbnVtYmVyKSA9PiB7XG4gIHJldHVybiBpbnB1dFN0cmluZy5sZW5ndGggPCBtYXhMZW5ndGhcbiAgICA/IGlucHV0U3RyaW5nXG4gICAgOiBpbnB1dFN0cmluZy5zdWJzdHJpbmcoMCwgbWF4TGVuZ3RoKTtcbn07XG4iXX0=
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param inString string to hash
|
|
4
|
+
* @param trimLength trim to this length (defaults to 999 chars)
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const hashString: (inString: string, trimLength?: number) => string;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param inputString string to truncate
|
|
11
|
+
* @param maxLength max length of this string
|
|
12
|
+
* @returns trimmed string
|
|
13
|
+
*/
|
|
14
|
+
export declare const trimStringLength: (inputString: string, maxLength: number) => string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.trimStringLength = exports.hashString = void 0;
|
|
37
|
+
const crypto = __importStar(require("node:crypto"));
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param inString string to hash
|
|
41
|
+
* @param trimLength trim to this length (defaults to 999 chars)
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
const hashString = (inString, trimLength = 999) => {
|
|
45
|
+
return crypto
|
|
46
|
+
.createHash("sha256")
|
|
47
|
+
.update(inString)
|
|
48
|
+
.digest("hex")
|
|
49
|
+
.substring(0, trimLength);
|
|
50
|
+
};
|
|
51
|
+
exports.hashString = hashString;
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param inputString string to truncate
|
|
55
|
+
* @param maxLength max length of this string
|
|
56
|
+
* @returns trimmed string
|
|
57
|
+
*/
|
|
58
|
+
const trimStringLength = (inputString, maxLength) => {
|
|
59
|
+
return inputString.length < maxLength
|
|
60
|
+
? inputString
|
|
61
|
+
: inputString.substring(0, maxLength);
|
|
62
|
+
};
|
|
63
|
+
exports.trimStringLength = trimStringLength;
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RyaW5nLXV0aWxzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0cmluZy9zdHJpbmctdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsb0RBQXNDO0FBRXRDOzs7OztHQUtHO0FBQ0ksTUFBTSxVQUFVLEdBQUcsQ0FBQyxRQUFnQixFQUFFLGFBQXFCLEdBQUcsRUFBRSxFQUFFO0lBQ3ZFLE9BQU8sTUFBTTtTQUNWLFVBQVUsQ0FBQyxRQUFRLENBQUM7U0FDcEIsTUFBTSxDQUFDLFFBQVEsQ0FBQztTQUNoQixNQUFNLENBQUMsS0FBSyxDQUFDO1NBQ2IsU0FBUyxDQUFDLENBQUMsRUFBRSxVQUFVLENBQUMsQ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9ydCBjb25zdCB0cmltU3RyaW5nTGVuZ3RoID0gKGlucHV0U3RyaW5nOiBzdHJpbmcsIG1heExlbmd0aDogbnVtYmVyKSA9PiB7XG4gIHJldHVybiBpbnB1dFN0cmluZy5sZW5ndGggPCBtYXhMZW5ndGhcbiAgICA/IGlucHV0U3RyaW5nXG4gICAgOiBpbnB1dFN0cmluZy5zdWJzdHJpbmcoMCwgbWF4TGVuZ3RoKTtcbn07XG4iXX0=
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codedrifters/utils",
|
|
3
|
+
"description": "Common utilities and helper functions for CodeDrifter projects.",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/codedrifters/packages"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "npx projen build",
|
|
10
|
+
"bump": "npx projen bump",
|
|
11
|
+
"compile": "npx projen compile",
|
|
12
|
+
"default": "npx projen default",
|
|
13
|
+
"eslint": "npx projen eslint",
|
|
14
|
+
"package": "npx projen package",
|
|
15
|
+
"post-compile": "npx projen post-compile",
|
|
16
|
+
"post-upgrade": "npx projen post-upgrade",
|
|
17
|
+
"pre-compile": "npx projen pre-compile",
|
|
18
|
+
"release": "npx projen release",
|
|
19
|
+
"test": "npx projen test",
|
|
20
|
+
"test:watch": "npx projen test:watch",
|
|
21
|
+
"unbump": "npx projen unbump",
|
|
22
|
+
"upgrade": "npx projen upgrade",
|
|
23
|
+
"watch": "npx projen watch",
|
|
24
|
+
"projen": "npx projen"
|
|
25
|
+
},
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "CodeDrifters",
|
|
28
|
+
"organization": true
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@swc/core": "^1.15.7",
|
|
32
|
+
"@swc/jest": "^0.2.39",
|
|
33
|
+
"@types/jest": "^30.0.0",
|
|
34
|
+
"@types/node": "^24.10.1",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^8",
|
|
36
|
+
"@typescript-eslint/parser": "^8",
|
|
37
|
+
"commit-and-tag-version": "^12",
|
|
38
|
+
"eslint": "^9",
|
|
39
|
+
"eslint-config-prettier": "^10.1.8",
|
|
40
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
41
|
+
"eslint-plugin-import": "^2.32.0",
|
|
42
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
43
|
+
"jest": "^30.2.0",
|
|
44
|
+
"jest-junit": "^16",
|
|
45
|
+
"prettier": "^3.6.2",
|
|
46
|
+
"typescript": "^5.9.3"
|
|
47
|
+
},
|
|
48
|
+
"main": "lib/index.js",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"version": "0.0.0",
|
|
51
|
+
"types": "lib/index.d.ts",
|
|
52
|
+
"packageManager": "pnpm@10.26.0",
|
|
53
|
+
"//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"."
|
|
54
|
+
}
|