Skip to content

Commit 7d78804

Browse files
docs: add parameterized API Reference
1 parent 202898b commit 7d78804

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,46 @@ console.log(parseValue("String value")); // Outputs: 'String value'
15161516

15171517
---
15181518

1519+
##### `parameterized`
1520+
1521+
Creates a parameterized string with placeholder values.
1522+
1523+
###### Types
1524+
1525+
###### `ParameterizedValue`
1526+
1527+
Represents a value that can be used as a parameter in string operations.
1528+
1529+
```ts
1530+
type ParameterizedValue = string | boolean | number | bigint;
1531+
```
1532+
1533+
###### `Parameterized`
1534+
1535+
Represents a parameterized string with its corresponding values.
1536+
1537+
```ts
1538+
type Parameterized = [string, ParameterizedValue[]];
1539+
```
1540+
1541+
<details>
1542+
1543+
<summary style="cursor:pointer">Examples</summary>
1544+
1545+
```ts
1546+
import { parameterized } from "@alessiofrittoli/web-utils";
1547+
1548+
const data = {
1549+
value: "parameterized",
1550+
};
1551+
1552+
console.log(parameterized`My string with ${data.value} values.`); // [ 'My string with ? values.', [ 'parameterized' ] ]
1553+
```
1554+
1555+
</details>
1556+
1557+
---
1558+
15191559
#### Types utilities
15201560

15211561
⚠️ Docs coming soon

src/strings.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export const emailDataToString = (
348348
* Represents a value that can be used as a parameter in string operations.
349349
*
350350
*/
351-
type ParameterizedValue = string | boolean | number | bigint
351+
export type ParameterizedValue = string | boolean | number | bigint
352352

353353

354354
/**
@@ -357,23 +357,23 @@ type ParameterizedValue = string | boolean | number | bigint
357357
* @property {string} 0 - The template string
358358
* @property {ParameterizedValue[]} 1 - Array of values to be substituted into the template string
359359
*/
360-
type Parameterized = [ string, ParameterizedValue[] ]
360+
export type Parameterized = [ string, ParameterizedValue[] ]
361361

362362

363363
/**
364-
* Creates a parameterized query string with placeholder values.
364+
* Creates a parameterized string with placeholder values.
365365
*
366366
* @param strings - The template string parts from a template literal.
367367
* @param values - One or more parameter values or arrays of values to be substituted into the template.
368-
* @returns A tuple containing the normalized query string with `?` placeholders and an array of parameter values.
368+
* @returns A tuple containing the normalized string with `?` placeholders and an array of parameter values.
369369
*
370370
* @example
371371
* ```ts
372-
* const [ query, params ] = parameterized`
372+
* const [ string, params ] = parameterized`
373373
* SELECT * FROM users WHERE id = ${ 1 } AND status IN ( ${ [ 'active', 'pending' ] } )
374374
* ` )
375375
*
376-
* // query: "SELECT * FROM users WHERE id = ? AND status IN ( ?, ? )"
376+
* // string: "SELECT * FROM users WHERE id = ? AND status IN ( ?, ? )"
377377
* // params: [ 1, 'active', 'pending' ]
378378
* ```
379379
*

0 commit comments

Comments
 (0)