Skip to content

Commit d478760

Browse files
committed
feat(hf): dString to
1 parent 71591cc commit d478760

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+509
-161
lines changed

docs/en/v1/api/string/concat.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ prev:
55
text: "sortCompare"
66
link: "/en/v1/api/string/sortCompare"
77
next:
8-
text: "isKeyof"
9-
link: "/en/v1/api/string/isKeyof"
8+
text: "to"
9+
link: "/en/v1/api/string/to"
1010
---
1111

1212
# concat

docs/en/v1/api/string/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ Removes whitespace from the end of a string.
114114
### [concat](/en/v1/api/string/concat)
115115
Concatenates multiple strings together.
116116

117+
### [to](/en/v1/api/string/to)
118+
Converts a primitive value to its string representation.
119+
117120
### [sort](/en/v1/api/string/sort)
118121
Sorts an array of strings in ascending or descending order.
119122

docs/en/v1/api/string/isKeyof.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
outline: [2, 3]
33
description: "The isKeyof() method checks whether a key exists in an object and narrows the key type accordingly."
44
prev:
5-
text: "concat"
6-
link: "/en/v1/api/string/concat"
5+
text: "to"
6+
link: "/en/v1/api/string/to"
77
next:
88
text: "String"
99
link: "/en/v1/api/string/"

docs/en/v1/api/string/to.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
outline: [2, 3]
3+
description: "The to() function converts a primitive value to its string representation."
4+
prev:
5+
text: "concat"
6+
link: "/en/v1/api/string/concat"
7+
next:
8+
text: "isKeyof"
9+
link: "/en/v1/api/string/isKeyof"
10+
---
11+
12+
# to
13+
14+
The **`to()`** function converts a primitive value to its string representation.
15+
16+
## Interactive example
17+
18+
<MonacoTSEditor
19+
src="/examples/v1/api/string/to/tryout.doc.ts"
20+
majorVersion="v1"
21+
height="187px"
22+
/>
23+
24+
## Syntax
25+
26+
### Classic signature
27+
28+
```typescript
29+
function to<
30+
GenericValue extends string | boolean | null | number | undefined | bigint
31+
>(
32+
value: GenericValue
33+
): `${GenericValue}`
34+
```
35+
36+
## Parameters
37+
38+
- `value`: The primitive value to convert.
39+
40+
## Return value
41+
42+
A string representation of the input value, preserving literal types when possible.
43+
44+
## See also
45+
46+
- [`concat`](/en/v1/api/string/concat) - Concatenates multiple strings
47+
- [`toLowerCase`](/en/v1/api/string/toLowerCase) - Converts a string to lowercase
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { DString } from "@duplojs/utils";
2+
3+
const total = 42;
4+
const totalText = DString.to(total);
5+
6+
const isActive = false;
7+
const activeText = DString.to(isActive);

docs/fr/v1/api/string/concat.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ prev:
55
text: "sortCompare"
66
link: "/fr/v1/api/string/sortCompare"
77
next:
8-
text: "isKeyof"
9-
link: "/fr/v1/api/string/isKeyof"
8+
text: "to"
9+
link: "/fr/v1/api/string/to"
1010
---
1111

1212
# concat

docs/fr/v1/api/string/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ Supprime les espaces en fin de chaîne.
114114
### [concat](/fr/v1/api/string/concat)
115115
Concatène plusieurs chaînes ensemble.
116116

117+
### [to](/fr/v1/api/string/to)
118+
Convertit une valeur primitive en chaîne de caractères.
119+
117120
### [sort](/fr/v1/api/string/sort)
118121
Trie un tableau de chaînes en ordre croissant ou décroissant.
119122

docs/fr/v1/api/string/isKeyof.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
outline: [2, 3]
33
description: "La méthode isKeyof() vérifie si une clé existe dans un objet et affine le type de la clé en conséquence."
44
prev:
5-
text: "concat"
6-
link: "/fr/v1/api/string/concat"
5+
text: "to"
6+
link: "/fr/v1/api/string/to"
77
next:
88
text: "String"
99
link: "/fr/v1/api/string/"

docs/fr/v1/api/string/to.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
outline: [2, 3]
3+
description: "La fonction to() convertit une valeur primitive en sa representation en chaine de caracteres."
4+
prev:
5+
text: "concat"
6+
link: "/fr/v1/api/string/concat"
7+
next:
8+
text: "isKeyof"
9+
link: "/fr/v1/api/string/isKeyof"
10+
---
11+
12+
# to
13+
14+
La **`to()`** fonction convertit une valeur primitive en sa representation en chaine de caracteres.
15+
16+
## Exemple interactif
17+
18+
<MonacoTSEditor
19+
src="/examples/v1/api/string/to/tryout.doc.ts"
20+
majorVersion="v1"
21+
height="187px"
22+
/>
23+
24+
## Syntaxe
25+
26+
### Signature classique
27+
28+
```typescript
29+
function to<
30+
GenericValue extends string | boolean | null | number | undefined | bigint
31+
>(
32+
value: GenericValue
33+
): `${GenericValue}`
34+
```
35+
36+
## Parametres
37+
38+
- `value` : La valeur primitive a convertir.
39+
40+
## Valeur de retour
41+
42+
Une representation en chaine de caracteres de la valeur d'entree, en preservant les types litteraux quand c'est possible.
43+
44+
## Voir aussi
45+
46+
- [`concat`](/fr/v1/api/string/concat) - Concatene plusieurs chaines
47+
- [`toLowerCase`](/fr/v1/api/string/toLowerCase) - Convertit une chaine en minuscules

docs/public/libs/v1/common/simpleClone.cjs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ function simpleClone(unknownValue) {
1212
}
1313
else if (unknownValue.constructor === undefined
1414
|| unknownValue.constructor.name === "Object") {
15-
return Object.entries(unknownValue).reduce((pv, [key, value]) => {
16-
pv[key] = simpleClone(value);
17-
return pv;
18-
}, {});
15+
const result = {};
16+
for (const key in unknownValue) {
17+
const desc = Object.getOwnPropertyDescriptor(unknownValue, key);
18+
if (desc?.set || desc?.get) {
19+
Object.defineProperty(result, key, desc);
20+
}
21+
else {
22+
result[key] = simpleClone(unknownValue[key]);
23+
}
24+
}
25+
return result;
1926
}
2027
else if (unknownValue instanceof Array && unknownValue.constructor.name === "Array") {
2128
return unknownValue.map(simpleClone);

0 commit comments

Comments
 (0)