@corentinth/chisels
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -144,2 +144,30 @@ /** | ||
export { type DeepPartial, type Dictionary, type Expand, type PartialBy, type Subtract, castError, formatBytes, injectArguments, safely, safelySync }; | ||
/** | ||
* Join URL parts and trim slashes. | ||
* | ||
* @example | ||
* ```typescript | ||
* const url = joinUrlPaths('/part1/', '/part2/', 'part3', 'part4/'); | ||
* | ||
* console.log(url); // 'part1/part2/part3/part4' | ||
* ``` | ||
*/ | ||
declare function joinUrlPaths(...parts: string[]): string; | ||
/** | ||
* Functional wrapper around URL constructor to build an URL string from a base URL and optional path, query params and hash. | ||
* | ||
* @example | ||
* ```typescript | ||
* const url = buildUrl({ baseUrl: 'https://example.com', path: 'foo', queryParams: { a: '1', b: '2' }, hash: 'hash' }); | ||
* | ||
* console.log(url); // 'https://example.com/foo?a=1&b=2#hash' | ||
* ``` | ||
*/ | ||
declare function buildUrl({ path, baseUrl, queryParams, hash, }: { | ||
path?: string; | ||
baseUrl: string; | ||
queryParams?: Record<string, string> | URLSearchParams; | ||
hash?: string; | ||
}): string; | ||
export { type DeepPartial, type Dictionary, type Expand, type PartialBy, type Subtract, buildUrl, castError, formatBytes, injectArguments, joinUrlPaths, safely, safelySync }; |
{ | ||
"name": "@corentinth/chisels", | ||
"type": "module", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"packageManager": "pnpm@9.9.0", | ||
@@ -6,0 +6,0 @@ "description": "Collection of utilities for JavaScript and TypeScript, lightweight and tree-shakable.", |
@@ -43,2 +43,36 @@ # Chisels - JS/TS utilities and types | ||
### `safelySync` | ||
Function - [See source](./src/safely.ts#L43) | ||
Safely executes a function and return a tuple with the result and an error if any. | ||
```typescript | ||
const [result, error] = safelySync(myFunction); | ||
if (error) { | ||
console.error(error); | ||
} | ||
console.log(result); | ||
``` | ||
### `safely` | ||
Function - [See source](./src/safely.ts#L20) | ||
Safely executes an async function or promise and return a tuple with the result and an error if any. | ||
```typescript | ||
const [result, error] = await safely(myFunction); | ||
if (error) { | ||
console.error(error); | ||
} | ||
console.log(result); | ||
``` | ||
### `formatBytes` | ||
@@ -74,34 +108,26 @@ | ||
### `safelySync` | ||
### `joinUrlPaths` | ||
Function - [See source](./src/safely.ts#L43) | ||
Function - [See source](./src/url.ts#L13) | ||
Safely executes a function and return a tuple with the result and an error if any. | ||
Join URL parts and trim slashes. | ||
```typescript | ||
const [result, error] = safelySync(myFunction); | ||
const url = joinUrlPaths('/part1/', '/part2/', 'part3', 'part4/'); | ||
if (error) { | ||
console.error(error); | ||
} | ||
console.log(result); | ||
console.log(url); // 'part1/part2/part3/part4' | ||
``` | ||
### `safely` | ||
### `buildUrl` | ||
Function - [See source](./src/safely.ts#L20) | ||
Function - [See source](./src/url.ts#L27) | ||
Safely executes an async function or promise and return a tuple with the result and an error if any. | ||
Functional wrapper around URL constructor to build an URL string from a base URL and optional path, query params and hash. | ||
```typescript | ||
const [result, error] = await safely(myFunction); | ||
const url = buildUrl({ baseUrl: 'https://example.com', path: 'foo', queryParams: { a: '1', b: '2' }, hash: 'hash' }); | ||
if (error) { | ||
console.error(error); | ||
} | ||
console.log(result); | ||
console.log(url); // 'https://example.com/foo?a=1&b=2#hash' | ||
``` | ||
@@ -108,0 +134,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39258
310
227