Skip to content

Commit 1f5e105

Browse files
committed
[FIX] generateMarkdown.js
1 parent f0ce3fa commit 1f5e105

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.vscode

apps/react-tools-demo/scripts/generateMarkdown.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ function buildHooksUtilsMarkdownObject(file) {
242242
type: getTypeString(returnSplitted, true),
243243
...getNameDescriptionParam(returnSplitted)
244244
};
245+
let lastDescriptionIndex = index+1;
246+
while(lastDescriptionIndex < lines.length && ![" */", "*/"].includes(lines[lastDescriptionIndex])) {
247+
lastDescriptionIndex++;
248+
}
249+
if(lastDescriptionIndex !== index+1) {
250+
const temp = returns.type.join("\n").substring(1);
251+
returns.description = temp;
252+
returns.type = lines.splice(index+1, lastDescriptionIndex-1).map(el => el.split(" * ")[1]);
253+
}
245254
obj.returns = returns;
246255
}
247256
if(depuratedLine.startsWith("__") || depuratedLine.startsWith("**")) {

apps/react-tools-demo/src/markdown/useBattery.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const UseBattery = () => {
1010
return (<div style={{ textAlign: "center" }}>
1111
{
1212
Object.keys(status).map(el => (
13-
<p key={el}>{el}: {JSON.stringify(status[el as keyof typeof status])}</p>
13+
<p key={el}>{el}: {status[el as keyof typeof status]}</p>
1414
))
1515
}
1616
</div>)
@@ -23,7 +23,7 @@ export const UseBattery = () => {
2323
## API
2424

2525
```tsx
26-
useBattery (opts?: { onChargingChange?: (evt: Event) => void, onChargingTimeChange?: (evt: Event) => void, onDischargingTimeChange?: (evt: Event) => void, onLevelChange?: (evt: Event) => void }): BatteryStatus
26+
useBattery * - __isSupported__: boolean that indicates if Battery Status API is available.
2727
```
2828

2929
> ### Params
@@ -42,6 +42,11 @@ callback that will be executed when levelchange event is fired.
4242
4343
> ### Returns
4444
>
45-
> __result__: object:
46-
> - _BatteryStatus_
45+
> __result__: _BatteryStatus_
46+
> Object with:
47+
> - __isSupported__: boolean that indicates if Battery Status API is available.
48+
> - __level__: number that indicates battery level: is a number between 0 and 1.
49+
> - __charging__: boolean that indicates if battery is charging.
50+
> - __chargingTime__: number that indicates time in seconds remaining to full charge, or infinity.
51+
> - __dischargingTime__: number that indicates time in seconds remaining to empty charge, rounded in 15 minutes by API.
4752
>

packages/react-tools/src/hooks/useBattery.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ let batteryCached: undefined | BatteryStatus & { onchargingchange: null | ((evt:
1818
* @param {(evt: Event) => void} [opts.onChargingTimeChange] - callback that will be executed when chargingtimechange event is fired.
1919
* @param {(evt: Event) => void} [opts.onDischargingTimeChange] - callback that will be executed when dischargingtimechange event is fired.
2020
* @param {(evt: Event) => void} [opts.onLevelChange] - callback that will be executed when levelchange event is fired.
21-
* @returns {BatteryStatus} result - object:
21+
* @returns {BatteryStatus} result
22+
* Object with:
2223
* - __isSupported__: boolean that indicates if Battery Status API is available.
2324
* - __level__: number that indicates battery level: is a number between 0 and 1.
2425
* - __charging__: boolean that indicates if battery is charging.

0 commit comments

Comments
 (0)