Skip to content

Commit d7a7f94

Browse files
committed
chore(many): initial commit
0 parents  commit d7a7f94

17 files changed

Lines changed: 3744 additions & 0 deletions

.czrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"path": "cz-conventional-changelog",
3+
"skipScope": false
4+
}

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
# Unix-style newlines with a newline ending every file
4+
[*]
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Node.js generated files
2+
node_modules/
3+
4+
# Build output
5+
coverage/
6+
dist/
7+
8+
# macOS 🍏 generated files
9+
.DS_Store
10+
11+
# Local env files
12+
.env
13+
.env.*
14+
!.env.example
15+
16+
# ide specific files
17+
.idea
18+
19+
# Kilocode specific files
20+
.kilocode

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pnpm lint
2+
pnpm test:coverage

.scripts/generate-docs.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Generate TypeDoc documentation and organize output
3+
4+
pnpm typedoc
5+
6+
if [ -d "docs" ]; then
7+
# Rename the main class documentation file
8+
if [ -f "docs/Class.DynamicURL.md" ]; then
9+
mv docs/Class.DynamicURL.md docs/api.md
10+
fi
11+
12+
# Remove duplicate README
13+
if [ -f "docs/README.md" ]; then
14+
rm docs/README.md
15+
fi
16+
17+
# Remove "Defined in:" lines from api.md (must come after rename)
18+
if [ -f "docs/api.md" ]; then
19+
sed -i '' '/^Defined in:/d' docs/api.md
20+
echo "✅ API documentation generated at docs/api.md"
21+
else
22+
echo "❌ api.md not found"
23+
exit 1
24+
fi
25+
else
26+
echo "❌ Failed to generate documentation"
27+
exit 1
28+
fi

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# @ambitiondev/dynamic-url
2+
3+
A lightweight JavaScript library for generating dynamic URLs based on templates and parameters.
4+
5+
## Installation
6+
7+
You can install the library using npm:
8+
9+
```bash
10+
npm install @ambitiondev/dynamic-url
11+
```
12+
13+
## Usage
14+
15+
Here's a simple example of how to use the library:
16+
17+
```typescript
18+
import { DynamicURL } from "@ambitiondev/dynamic-url";
19+
20+
// Init the url with your template
21+
const url = new DynamicURL("https://example.com/{user}/{id}");
22+
// Set route and query parameters
23+
url.setRouteParams({ user: "john_doe", id: 123 });
24+
url.setQueryParams({ ref: "newsletter", campaign: "spring_sale" });
25+
26+
// Resolve the final URL
27+
console.log(url.resolve());
28+
// Output: https://example.com/john_doe/123?ref=newsletter&campaign=spring_sale
29+
```
30+
31+
## More docs
32+
33+
- [API](./docs/api.md)

commitlint.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ["@commitlint/config-conventional"],
3+
};

docs/api.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Class: DynamicURL
2+
3+
## Constructors
4+
5+
### Constructor
6+
7+
> **new DynamicURL**(`url`): `DynamicURL`
8+
9+
10+
#### Parameters
11+
12+
##### url
13+
14+
`string`
15+
16+
#### Returns
17+
18+
`DynamicURL`
19+
20+
## Methods
21+
22+
### resolve()
23+
24+
> **resolve**(): `string`
25+
26+
27+
Resolves and returns the final URL as a string.
28+
29+
#### Returns
30+
31+
`string`
32+
33+
#### Example
34+
35+
```ts
36+
const url = new DynamicURL("https://example.com/{citizen}/{hero}");
37+
url.setRouteParams({ citizen: "robespierre", hero: "ironman" });
38+
39+
// Resolve the final URL
40+
console.log(url.resolve()); // "https://example.com/robespierre/ironman"
41+
```
42+
43+
---
44+
45+
### setQueryParams()
46+
47+
> **setQueryParams**(`query`): `DynamicURL`
48+
49+
50+
Takes a query object and appends it to the URL as a query string.
51+
52+
#### Parameters
53+
54+
##### query
55+
56+
`Record`\<`string`, `any`\>
57+
58+
An object representing the query parameters.
59+
60+
#### Returns
61+
62+
`DynamicURL`
63+
64+
#### Example
65+
66+
```ts
67+
const url = new DynamicURL("https://example.com");
68+
url.setQueryParams({ citizen: "robespierre", hero: "ironman" });
69+
console.log(url.resolve()); // "https://example.com?citizen=robespierre&hero=ironman"
70+
```
71+
72+
---
73+
74+
### setRouteParams()
75+
76+
> **setRouteParams**(`replaceValue`): `DynamicURL`
77+
78+
79+
Replaces route parameters in the URL with the provided values.
80+
81+
#### Parameters
82+
83+
##### replaceValue
84+
85+
An object or string to replace the route parameters.
86+
87+
`string` | `TParamsObject`
88+
89+
#### Returns
90+
91+
`DynamicURL`
92+
93+
#### See
94+
95+
TParamsObject
96+
97+
#### Example
98+
99+
```ts
100+
const url = new DynamicURL("https://example.com/{citizen}/{hero}");
101+
url.setRouteParams({ citizen: "robespierre", hero: "ironman" });
102+
console.log(url.resolve()); // "https://example.com/robespierre/ironman"
103+
```

eslint.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @ts-check
2+
3+
import { defineConfig } from "eslint/config";
4+
import tseslint from "typescript-eslint";
5+
6+
export default defineConfig(
7+
tseslint.configs.strict,
8+
tseslint.configs.stylistic
9+
);

package.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "@ambitiondev/dynamic-url",
3+
"description": "lightweight util for creating dynamic endpoint strings",
4+
"version": "0.0.0",
5+
"main": "./dist/src/url.js",
6+
"types": "./dist/src/url.d.ts",
7+
"files": [
8+
"dist"
9+
],
10+
"authors": [
11+
{
12+
"name": "Berrie Nachtweh - Ambition Concepts",
13+
"email": "info@ambitiondev.io",
14+
"url": "https://ambitiondev.io"
15+
}
16+
],
17+
"devDependencies": {
18+
"@commitlint/config-conventional": "^20.3.1",
19+
"@eslint/js": "^9.39.2",
20+
"@types/qs": "^6.14.0",
21+
"@vitest/coverage-v8": "^4.0.17",
22+
"commitizen": "^4.3.1",
23+
"eslint": "^9.39.2",
24+
"husky": "^9.1.7",
25+
"typedoc": "^0.28.16",
26+
"typedoc-plugin-markdown": "^4.9.0",
27+
"typescript": "^5.9.3",
28+
"typescript-eslint": "^8.53.0",
29+
"vitest": "^4.0.17"
30+
},
31+
"dependencies": {
32+
"qs": "^6.14.1"
33+
},
34+
"scripts": {
35+
"--- 🎣 Hooks ---": "",
36+
"prepare": "husky",
37+
"--- 🧪 Testing ---": "",
38+
"test": "vitest",
39+
"test:coverage": "vitest run --coverage",
40+
"--- 🎗️ Lint ---": "",
41+
"lint": "eslint src/*.ts",
42+
"--- 📚 Documentation ---": "",
43+
"docs:generate": "./.scripts/generate-docs.sh",
44+
"--- 🤓 Developer Tools ---": "",
45+
"commit": "git-cz",
46+
"build": "tsc"
47+
},
48+
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6"
49+
}

0 commit comments

Comments
 (0)