@herowcode/utils 1.3.4 → 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/dist/api/index.cjs +12 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/{client.d.ts → index.d.mts} +19 -8
- package/dist/api/index.d.ts +36 -3
- package/dist/api/index.js +3 -0
- package/dist/api/index.js.map +1 -0
- package/dist/array/index.cjs +16 -0
- package/dist/array/index.cjs.map +1 -0
- package/dist/array/index.d.mts +5 -0
- package/dist/array/index.d.ts +5 -3
- package/dist/array/index.js +3 -0
- package/dist/array/index.js.map +1 -0
- package/dist/chunk-2MANLCNG.cjs +23 -0
- package/dist/chunk-2MANLCNG.cjs.map +1 -0
- package/dist/chunk-2RTW37WD.js +20 -0
- package/dist/chunk-2RTW37WD.js.map +1 -0
- package/dist/chunk-2Y6M7IOG.js +250 -0
- package/dist/chunk-2Y6M7IOG.js.map +1 -0
- package/dist/chunk-3JUB2OJL.js +3 -0
- package/dist/chunk-3JUB2OJL.js.map +1 -0
- package/dist/chunk-53JMVGIG.js +187 -0
- package/dist/chunk-53JMVGIG.js.map +1 -0
- package/dist/chunk-56NHIM5J.js +151 -0
- package/dist/chunk-56NHIM5J.js.map +1 -0
- package/dist/chunk-5OLQJUNS.js +66 -0
- package/dist/chunk-5OLQJUNS.js.map +1 -0
- package/dist/chunk-5YOEKMTJ.cjs +321 -0
- package/dist/chunk-5YOEKMTJ.cjs.map +1 -0
- package/dist/chunk-6TWPZ6LL.cjs +4 -0
- package/dist/chunk-6TWPZ6LL.cjs.map +1 -0
- package/dist/chunk-AQZBHMTO.js +96 -0
- package/dist/chunk-AQZBHMTO.js.map +1 -0
- package/dist/chunk-ATWN4SRX.js +29 -0
- package/dist/chunk-ATWN4SRX.js.map +1 -0
- package/dist/chunk-GRSF4RY2.cjs +20 -0
- package/dist/chunk-GRSF4RY2.cjs.map +1 -0
- package/dist/chunk-GX5E5B4L.cjs +70 -0
- package/dist/chunk-GX5E5B4L.cjs.map +1 -0
- package/dist/chunk-HK727IAV.cjs +201 -0
- package/dist/chunk-HK727IAV.cjs.map +1 -0
- package/dist/chunk-LJ6KOZD4.cjs +154 -0
- package/dist/chunk-LJ6KOZD4.cjs.map +1 -0
- package/dist/chunk-N2DRAZ3A.cjs +29 -0
- package/dist/chunk-N2DRAZ3A.cjs.map +1 -0
- package/dist/chunk-O7SH3E3T.js +18 -0
- package/dist/chunk-O7SH3E3T.js.map +1 -0
- package/dist/chunk-P5YNRND6.cjs +4 -0
- package/dist/chunk-P5YNRND6.cjs.map +1 -0
- package/dist/chunk-QAE6Q2SA.js +317 -0
- package/dist/chunk-QAE6Q2SA.js.map +1 -0
- package/dist/chunk-QRXVUXGJ.js +378 -0
- package/dist/chunk-QRXVUXGJ.js.map +1 -0
- package/dist/chunk-SLYUARZG.cjs +99 -0
- package/dist/chunk-SLYUARZG.cjs.map +1 -0
- package/dist/chunk-SWRIT7EE.js +3 -0
- package/dist/chunk-SWRIT7EE.js.map +1 -0
- package/dist/chunk-UXEUYHBD.cjs +401 -0
- package/dist/chunk-UXEUYHBD.cjs.map +1 -0
- package/dist/chunk-V6OKXUBQ.js +22 -0
- package/dist/chunk-V6OKXUBQ.js.map +1 -0
- package/dist/chunk-VAZJXZU5.cjs +31 -0
- package/dist/chunk-VAZJXZU5.cjs.map +1 -0
- package/dist/chunk-WGSFRFRO.cjs +252 -0
- package/dist/chunk-WGSFRFRO.cjs.map +1 -0
- package/dist/date/index.cjs +56 -0
- package/dist/date/index.cjs.map +1 -0
- package/dist/date/index.d.mts +63 -0
- package/dist/date/index.d.ts +63 -8
- package/dist/date/index.js +3 -0
- package/dist/date/index.js.map +1 -0
- package/dist/extract-youtube-video-id-HSYMYXIZ.js +3 -0
- package/dist/extract-youtube-video-id-HSYMYXIZ.js.map +1 -0
- package/dist/extract-youtube-video-id-XVGNPUDX.cjs +12 -0
- package/dist/extract-youtube-video-id-XVGNPUDX.cjs.map +1 -0
- package/dist/files/index.browser.cjs +21 -0
- package/dist/files/index.browser.cjs.map +1 -0
- package/dist/files/index.browser.d.mts +14 -0
- package/dist/files/index.browser.d.ts +14 -0
- package/dist/files/index.browser.js +4 -0
- package/dist/files/index.browser.js.map +1 -0
- package/dist/files/index.cjs +31 -0
- package/dist/files/index.cjs.map +1 -0
- package/dist/files/index.d.mts +3 -0
- package/dist/files/index.d.ts +3 -6
- package/dist/files/index.js +6 -0
- package/dist/files/index.js.map +1 -0
- package/dist/files/index.node.cjs +21 -0
- package/dist/files/index.node.cjs.map +1 -0
- package/dist/files/index.node.d.mts +7 -0
- package/dist/files/index.node.d.ts +7 -0
- package/dist/files/index.node.js +4 -0
- package/dist/files/index.node.js.map +1 -0
- package/dist/format-bytes-BGjeDnvM.d.mts +3 -0
- package/dist/format-bytes-BGjeDnvM.d.ts +3 -0
- package/dist/function/index.cjs +20 -0
- package/dist/function/index.cjs.map +1 -0
- package/dist/function/index.d.mts +22 -0
- package/dist/function/index.d.ts +22 -4
- package/dist/function/index.js +3 -0
- package/dist/function/index.js.map +1 -0
- package/dist/index.cjs +188 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/string/index.cjs +60 -0
- package/dist/string/index.cjs.map +1 -0
- package/dist/string/index.d.mts +28 -0
- package/dist/string/index.d.ts +28 -14
- package/dist/string/index.js +3 -0
- package/dist/string/index.js.map +1 -0
- package/dist/{cjs/function/try-catch.d.ts → try-catch-B7WzqcPU.d.mts} +4 -4
- package/dist/{function/try-catch.d.ts → try-catch-B7WzqcPU.d.ts} +4 -4
- package/dist/youtube/index.browser.cjs +35 -0
- package/dist/youtube/index.browser.cjs.map +1 -0
- package/dist/youtube/index.browser.d.mts +2 -0
- package/dist/youtube/index.browser.d.ts +2 -0
- package/dist/youtube/index.browser.js +6 -0
- package/dist/youtube/index.browser.js.map +1 -0
- package/dist/youtube/index.cjs +36 -0
- package/dist/youtube/index.cjs.map +1 -0
- package/dist/youtube/index.d.mts +12 -0
- package/dist/youtube/index.d.ts +12 -7
- package/dist/youtube/index.js +7 -0
- package/dist/youtube/index.js.map +1 -0
- package/dist/youtube/index.node.cjs +26 -0
- package/dist/youtube/index.node.cjs.map +1 -0
- package/dist/youtube/index.node.d.mts +49 -0
- package/dist/youtube/index.node.d.ts +49 -0
- package/dist/youtube/index.node.js +5 -0
- package/dist/youtube/index.node.js.map +1 -0
- package/package.json +134 -47
- package/dist/api/client.d.ts.map +0 -1
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/wrapper.d.ts +0 -27
- package/dist/api/wrapper.d.ts.map +0 -1
- package/dist/array/index.d.ts.map +0 -1
- package/dist/array/shuffle.d.ts +0 -2
- package/dist/array/shuffle.d.ts.map +0 -1
- package/dist/array/unique.d.ts +0 -2
- package/dist/array/unique.d.ts.map +0 -1
- package/dist/cjs/api/client.d.ts +0 -25
- package/dist/cjs/api/client.d.ts.map +0 -1
- package/dist/cjs/api/client.js +0 -148
- package/dist/cjs/api/client.js.map +0 -1
- package/dist/cjs/api/index.d.ts +0 -3
- package/dist/cjs/api/index.d.ts.map +0 -1
- package/dist/cjs/api/index.js +0 -6
- package/dist/cjs/api/index.js.map +0 -1
- package/dist/cjs/api/wrapper.d.ts +0 -27
- package/dist/cjs/api/wrapper.d.ts.map +0 -1
- package/dist/cjs/api/wrapper.js +0 -152
- package/dist/cjs/api/wrapper.js.map +0 -1
- package/dist/cjs/array/index.d.ts +0 -3
- package/dist/cjs/array/index.d.ts.map +0 -1
- package/dist/cjs/array/index.js +0 -19
- package/dist/cjs/array/index.js.map +0 -1
- package/dist/cjs/array/shuffle.d.ts +0 -2
- package/dist/cjs/array/shuffle.d.ts.map +0 -1
- package/dist/cjs/array/shuffle.js +0 -16
- package/dist/cjs/array/shuffle.js.map +0 -1
- package/dist/cjs/array/unique.d.ts +0 -2
- package/dist/cjs/array/unique.d.ts.map +0 -1
- package/dist/cjs/array/unique.js +0 -7
- package/dist/cjs/array/unique.js.map +0 -1
- package/dist/cjs/array.js +0 -1
- package/dist/cjs/date/dayjs.d.ts +0 -20
- package/dist/cjs/date/dayjs.d.ts.map +0 -1
- package/dist/cjs/date/dayjs.js +0 -123
- package/dist/cjs/date/dayjs.js.map +0 -1
- package/dist/cjs/date/fix-timezone-offset.d.ts +0 -3
- package/dist/cjs/date/fix-timezone-offset.d.ts.map +0 -1
- package/dist/cjs/date/fix-timezone-offset.js +0 -9
- package/dist/cjs/date/fix-timezone-offset.js.map +0 -1
- package/dist/cjs/date/format-date.d.ts +0 -23
- package/dist/cjs/date/format-date.d.ts.map +0 -1
- package/dist/cjs/date/format-date.js +0 -71
- package/dist/cjs/date/format-date.js.map +0 -1
- package/dist/cjs/date/get-current-date-in-utc.d.ts +0 -3
- package/dist/cjs/date/get-current-date-in-utc.d.ts.map +0 -1
- package/dist/cjs/date/get-current-date-in-utc.js +0 -8
- package/dist/cjs/date/get-current-date-in-utc.js.map +0 -1
- package/dist/cjs/date/get-date-in-utc.d.ts +0 -3
- package/dist/cjs/date/get-date-in-utc.d.ts.map +0 -1
- package/dist/cjs/date/get-date-in-utc.js +0 -8
- package/dist/cjs/date/get-date-in-utc.js.map +0 -1
- package/dist/cjs/date/get-relative-time.d.ts +0 -3
- package/dist/cjs/date/get-relative-time.d.ts.map +0 -1
- package/dist/cjs/date/get-relative-time.js +0 -8
- package/dist/cjs/date/get-relative-time.js.map +0 -1
- package/dist/cjs/date/index.d.ts +0 -8
- package/dist/cjs/date/index.d.ts.map +0 -1
- package/dist/cjs/date/index.js +0 -24
- package/dist/cjs/date/index.js.map +0 -1
- package/dist/cjs/date/parse-time-spent.d.ts +0 -15
- package/dist/cjs/date/parse-time-spent.d.ts.map +0 -1
- package/dist/cjs/date/parse-time-spent.js +0 -207
- package/dist/cjs/date/parse-time-spent.js.map +0 -1
- package/dist/cjs/date.js +0 -1
- package/dist/cjs/files/compress-image.d.ts +0 -10
- package/dist/cjs/files/compress-image.d.ts.map +0 -1
- package/dist/cjs/files/compress-image.js +0 -61
- package/dist/cjs/files/compress-image.js.map +0 -1
- package/dist/cjs/files/download-url.d.ts +0 -2
- package/dist/cjs/files/download-url.d.ts.map +0 -1
- package/dist/cjs/files/download-url.js +0 -29
- package/dist/cjs/files/download-url.js.map +0 -1
- package/dist/cjs/files/file-delete.d.ts +0 -2
- package/dist/cjs/files/file-delete.d.ts.map +0 -1
- package/dist/cjs/files/file-delete.js +0 -20
- package/dist/cjs/files/file-delete.js.map +0 -1
- package/dist/cjs/files/file-exists.d.ts +0 -2
- package/dist/cjs/files/file-exists.d.ts.map +0 -1
- package/dist/cjs/files/file-exists.js +0 -18
- package/dist/cjs/files/file-exists.js.map +0 -1
- package/dist/cjs/files/format-bytes.d.ts +0 -2
- package/dist/cjs/files/format-bytes.d.ts.map +0 -1
- package/dist/cjs/files/format-bytes.js +0 -17
- package/dist/cjs/files/format-bytes.js.map +0 -1
- package/dist/cjs/files/index.d.ts +0 -6
- package/dist/cjs/files/index.d.ts.map +0 -1
- package/dist/cjs/files/index.js +0 -22
- package/dist/cjs/files/index.js.map +0 -1
- package/dist/cjs/files.js +0 -1
- package/dist/cjs/function/debounce.d.ts +0 -11
- package/dist/cjs/function/debounce.d.ts.map +0 -1
- package/dist/cjs/function/debounce.js +0 -26
- package/dist/cjs/function/debounce.js.map +0 -1
- package/dist/cjs/function/index.d.ts +0 -4
- package/dist/cjs/function/index.d.ts.map +0 -1
- package/dist/cjs/function/index.js +0 -20
- package/dist/cjs/function/index.js.map +0 -1
- package/dist/cjs/function/throttle.d.ts +0 -10
- package/dist/cjs/function/throttle.d.ts.map +0 -1
- package/dist/cjs/function/throttle.js +0 -36
- package/dist/cjs/function/throttle.js.map +0 -1
- package/dist/cjs/function/try-catch.d.ts.map +0 -1
- package/dist/cjs/function/try-catch.js +0 -39
- package/dist/cjs/function/try-catch.js.map +0 -1
- package/dist/cjs/function.js +0 -1
- package/dist/cjs/index.d.ts +0 -8
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -24
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/string/camel-case.d.ts +0 -2
- package/dist/cjs/string/camel-case.d.ts.map +0 -1
- package/dist/cjs/string/camel-case.js +0 -25
- package/dist/cjs/string/camel-case.js.map +0 -1
- package/dist/cjs/string/capitalize.d.ts +0 -2
- package/dist/cjs/string/capitalize.d.ts.map +0 -1
- package/dist/cjs/string/capitalize.js +0 -13
- package/dist/cjs/string/capitalize.js.map +0 -1
- package/dist/cjs/string/format-hms-to-seconds.d.ts +0 -2
- package/dist/cjs/string/format-hms-to-seconds.d.ts.map +0 -1
- package/dist/cjs/string/format-hms-to-seconds.js +0 -30
- package/dist/cjs/string/format-hms-to-seconds.js.map +0 -1
- package/dist/cjs/string/format-seconds-to-fragment.d.ts +0 -3
- package/dist/cjs/string/format-seconds-to-fragment.d.ts.map +0 -1
- package/dist/cjs/string/format-seconds-to-fragment.js +0 -20
- package/dist/cjs/string/format-seconds-to-fragment.js.map +0 -1
- package/dist/cjs/string/format-seconds-to-hms.d.ts +0 -2
- package/dist/cjs/string/format-seconds-to-hms.d.ts.map +0 -1
- package/dist/cjs/string/format-seconds-to-hms.js +0 -17
- package/dist/cjs/string/format-seconds-to-hms.js.map +0 -1
- package/dist/cjs/string/format-string-to-time.d.ts +0 -2
- package/dist/cjs/string/format-string-to-time.d.ts.map +0 -1
- package/dist/cjs/string/format-string-to-time.js +0 -15
- package/dist/cjs/string/format-string-to-time.js.map +0 -1
- package/dist/cjs/string/index.d.ts +0 -14
- package/dist/cjs/string/index.d.ts.map +0 -1
- package/dist/cjs/string/index.js +0 -30
- package/dist/cjs/string/index.js.map +0 -1
- package/dist/cjs/string/kebab-case.d.ts +0 -2
- package/dist/cjs/string/kebab-case.d.ts.map +0 -1
- package/dist/cjs/string/kebab-case.js +0 -15
- package/dist/cjs/string/kebab-case.js.map +0 -1
- package/dist/cjs/string/markdown-to-text.d.ts +0 -2
- package/dist/cjs/string/markdown-to-text.d.ts.map +0 -1
- package/dist/cjs/string/markdown-to-text.js +0 -70
- package/dist/cjs/string/markdown-to-text.js.map +0 -1
- package/dist/cjs/string/remove-html-tags.d.ts +0 -2
- package/dist/cjs/string/remove-html-tags.d.ts.map +0 -1
- package/dist/cjs/string/remove-html-tags.js +0 -18
- package/dist/cjs/string/remove-html-tags.js.map +0 -1
- package/dist/cjs/string/slugify.d.ts +0 -2
- package/dist/cjs/string/slugify.d.ts.map +0 -1
- package/dist/cjs/string/slugify.js +0 -13
- package/dist/cjs/string/slugify.js.map +0 -1
- package/dist/cjs/string/snake-case.d.ts +0 -2
- package/dist/cjs/string/snake-case.d.ts.map +0 -1
- package/dist/cjs/string/snake-case.js +0 -15
- package/dist/cjs/string/snake-case.js.map +0 -1
- package/dist/cjs/string/to-sentence-case.d.ts +0 -2
- package/dist/cjs/string/to-sentence-case.d.ts.map +0 -1
- package/dist/cjs/string/to-sentence-case.js +0 -13
- package/dist/cjs/string/to-sentence-case.js.map +0 -1
- package/dist/cjs/string/truncate.d.ts +0 -2
- package/dist/cjs/string/truncate.d.ts.map +0 -1
- package/dist/cjs/string/truncate.js +0 -19
- package/dist/cjs/string/truncate.js.map +0 -1
- package/dist/cjs/string.js +0 -1
- package/dist/cjs/youtube/extract-youtube-video-id.d.ts +0 -2
- package/dist/cjs/youtube/extract-youtube-video-id.d.ts.map +0 -1
- package/dist/cjs/youtube/extract-youtube-video-id.js +0 -30
- package/dist/cjs/youtube/extract-youtube-video-id.js.map +0 -1
- package/dist/cjs/youtube/generate-youtube-url.d.ts +0 -20
- package/dist/cjs/youtube/generate-youtube-url.d.ts.map +0 -1
- package/dist/cjs/youtube/generate-youtube-url.js +0 -86
- package/dist/cjs/youtube/generate-youtube-url.js.map +0 -1
- package/dist/cjs/youtube/get-youtube-thumbnail.d.ts +0 -2
- package/dist/cjs/youtube/get-youtube-thumbnail.d.ts.map +0 -1
- package/dist/cjs/youtube/get-youtube-thumbnail.js +0 -68
- package/dist/cjs/youtube/get-youtube-thumbnail.js.map +0 -1
- package/dist/cjs/youtube/get-youtube-video-info.d.ts +0 -26
- package/dist/cjs/youtube/get-youtube-video-info.d.ts.map +0 -1
- package/dist/cjs/youtube/get-youtube-video-info.js +0 -244
- package/dist/cjs/youtube/get-youtube-video-info.js.map +0 -1
- package/dist/cjs/youtube/index.d.ts +0 -7
- package/dist/cjs/youtube/index.d.ts.map +0 -1
- package/dist/cjs/youtube/index.js +0 -23
- package/dist/cjs/youtube/index.js.map +0 -1
- package/dist/cjs/youtube/use-get-video-duration.d.ts +0 -7
- package/dist/cjs/youtube/use-get-video-duration.d.ts.map +0 -1
- package/dist/cjs/youtube/use-get-video-duration.js +0 -153
- package/dist/cjs/youtube/use-get-video-duration.js.map +0 -1
- package/dist/cjs/youtube/validate-youtube-link.d.ts +0 -2
- package/dist/cjs/youtube/validate-youtube-link.d.ts.map +0 -1
- package/dist/cjs/youtube/validate-youtube-link.js +0 -77
- package/dist/cjs/youtube/validate-youtube-link.js.map +0 -1
- package/dist/cjs/youtube.js +0 -1
- package/dist/date/dayjs.d.ts +0 -20
- package/dist/date/dayjs.d.ts.map +0 -1
- package/dist/date/fix-timezone-offset.d.ts +0 -3
- package/dist/date/fix-timezone-offset.d.ts.map +0 -1
- package/dist/date/format-date.d.ts +0 -23
- package/dist/date/format-date.d.ts.map +0 -1
- package/dist/date/get-current-date-in-utc.d.ts +0 -3
- package/dist/date/get-current-date-in-utc.d.ts.map +0 -1
- package/dist/date/get-date-in-utc.d.ts +0 -3
- package/dist/date/get-date-in-utc.d.ts.map +0 -1
- package/dist/date/get-relative-time.d.ts +0 -3
- package/dist/date/get-relative-time.d.ts.map +0 -1
- package/dist/date/index.d.ts.map +0 -1
- package/dist/date/parse-time-spent.d.ts +0 -15
- package/dist/date/parse-time-spent.d.ts.map +0 -1
- package/dist/esm/api/client.js +0 -143
- package/dist/esm/api/index.js +0 -1
- package/dist/esm/api/wrapper.js +0 -148
- package/dist/esm/array/index.js +0 -2
- package/dist/esm/array/shuffle.js +0 -12
- package/dist/esm/array/unique.js +0 -3
- package/dist/esm/array.js +0 -1
- package/dist/esm/date/dayjs.js +0 -111
- package/dist/esm/date/fix-timezone-offset.js +0 -5
- package/dist/esm/date/format-date.js +0 -67
- package/dist/esm/date/get-current-date-in-utc.js +0 -4
- package/dist/esm/date/get-date-in-utc.js +0 -4
- package/dist/esm/date/get-relative-time.js +0 -4
- package/dist/esm/date/index.js +0 -7
- package/dist/esm/date/parse-time-spent.js +0 -203
- package/dist/esm/date.js +0 -1
- package/dist/esm/files/compress-image.js +0 -57
- package/dist/esm/files/download-url.js +0 -24
- package/dist/esm/files/file-delete.js +0 -12
- package/dist/esm/files/file-exists.js +0 -10
- package/dist/esm/files/format-bytes.js +0 -13
- package/dist/esm/files/index.js +0 -5
- package/dist/esm/files.js +0 -1
- package/dist/esm/function/debounce.js +0 -22
- package/dist/esm/function/index.js +0 -3
- package/dist/esm/function/throttle.js +0 -32
- package/dist/esm/function/try-catch.js +0 -35
- package/dist/esm/function.js +0 -1
- package/dist/esm/index.js +0 -7
- package/dist/esm/string/camel-case.js +0 -21
- package/dist/esm/string/capitalize.js +0 -9
- package/dist/esm/string/format-hms-to-seconds.js +0 -25
- package/dist/esm/string/format-seconds-to-fragment.js +0 -15
- package/dist/esm/string/format-seconds-to-hms.js +0 -13
- package/dist/esm/string/format-string-to-time.js +0 -10
- package/dist/esm/string/index.js +0 -13
- package/dist/esm/string/kebab-case.js +0 -11
- package/dist/esm/string/markdown-to-text.js +0 -66
- package/dist/esm/string/remove-html-tags.js +0 -14
- package/dist/esm/string/slugify.js +0 -9
- package/dist/esm/string/snake-case.js +0 -11
- package/dist/esm/string/to-sentence-case.js +0 -9
- package/dist/esm/string/truncate.js +0 -15
- package/dist/esm/string.js +0 -1
- package/dist/esm/youtube/extract-youtube-video-id.js +0 -26
- package/dist/esm/youtube/generate-youtube-url.js +0 -81
- package/dist/esm/youtube/get-youtube-thumbnail.js +0 -31
- package/dist/esm/youtube/get-youtube-video-info.js +0 -207
- package/dist/esm/youtube/index.js +0 -6
- package/dist/esm/youtube/use-get-video-duration.js +0 -149
- package/dist/esm/youtube/validate-youtube-link.js +0 -40
- package/dist/esm/youtube.js +0 -1
- package/dist/files/compress-image.d.ts +0 -10
- package/dist/files/compress-image.d.ts.map +0 -1
- package/dist/files/download-url.d.ts +0 -2
- package/dist/files/download-url.d.ts.map +0 -1
- package/dist/files/file-delete.d.ts +0 -2
- package/dist/files/file-delete.d.ts.map +0 -1
- package/dist/files/file-exists.d.ts +0 -2
- package/dist/files/file-exists.d.ts.map +0 -1
- package/dist/files/format-bytes.d.ts +0 -2
- package/dist/files/format-bytes.d.ts.map +0 -1
- package/dist/files/index.d.ts.map +0 -1
- package/dist/function/debounce.d.ts +0 -11
- package/dist/function/debounce.d.ts.map +0 -1
- package/dist/function/index.d.ts.map +0 -1
- package/dist/function/throttle.d.ts +0 -10
- package/dist/function/throttle.d.ts.map +0 -1
- package/dist/function/try-catch.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/string/camel-case.d.ts +0 -2
- package/dist/string/camel-case.d.ts.map +0 -1
- package/dist/string/capitalize.d.ts +0 -2
- package/dist/string/capitalize.d.ts.map +0 -1
- package/dist/string/format-hms-to-seconds.d.ts +0 -2
- package/dist/string/format-hms-to-seconds.d.ts.map +0 -1
- package/dist/string/format-seconds-to-fragment.d.ts +0 -3
- package/dist/string/format-seconds-to-fragment.d.ts.map +0 -1
- package/dist/string/format-seconds-to-hms.d.ts +0 -2
- package/dist/string/format-seconds-to-hms.d.ts.map +0 -1
- package/dist/string/format-string-to-time.d.ts +0 -2
- package/dist/string/format-string-to-time.d.ts.map +0 -1
- package/dist/string/index.d.ts.map +0 -1
- package/dist/string/kebab-case.d.ts +0 -2
- package/dist/string/kebab-case.d.ts.map +0 -1
- package/dist/string/markdown-to-text.d.ts +0 -2
- package/dist/string/markdown-to-text.d.ts.map +0 -1
- package/dist/string/remove-html-tags.d.ts +0 -2
- package/dist/string/remove-html-tags.d.ts.map +0 -1
- package/dist/string/slugify.d.ts +0 -2
- package/dist/string/slugify.d.ts.map +0 -1
- package/dist/string/snake-case.d.ts +0 -2
- package/dist/string/snake-case.d.ts.map +0 -1
- package/dist/string/to-sentence-case.d.ts +0 -2
- package/dist/string/to-sentence-case.d.ts.map +0 -1
- package/dist/string/truncate.d.ts +0 -2
- package/dist/string/truncate.d.ts.map +0 -1
- package/dist/youtube/extract-youtube-video-id.d.ts +0 -2
- package/dist/youtube/extract-youtube-video-id.d.ts.map +0 -1
- package/dist/youtube/generate-youtube-url.d.ts +0 -20
- package/dist/youtube/generate-youtube-url.d.ts.map +0 -1
- package/dist/youtube/get-youtube-thumbnail.d.ts +0 -2
- package/dist/youtube/get-youtube-thumbnail.d.ts.map +0 -1
- package/dist/youtube/get-youtube-video-info.d.ts +0 -26
- package/dist/youtube/get-youtube-video-info.d.ts.map +0 -1
- package/dist/youtube/index.d.ts.map +0 -1
- package/dist/youtube/use-get-video-duration.d.ts +0 -7
- package/dist/youtube/use-get-video-duration.d.ts.map +0 -1
- package/dist/youtube/validate-youtube-link.d.ts +0 -2
- package/dist/youtube/validate-youtube-link.d.ts.map +0 -1
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function snakeCase(str) {
|
|
2
|
-
if (typeof str !== "string") {
|
|
3
|
-
throw new Error("Input must be a string");
|
|
4
|
-
}
|
|
5
|
-
return str
|
|
6
|
-
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
7
|
-
.replace(/[\s-]+/g, "_")
|
|
8
|
-
.replace(/[^a-zA-Z0-9_]/g, "")
|
|
9
|
-
.toLowerCase()
|
|
10
|
-
.replace(/^_+|_+$/g, "");
|
|
11
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function truncate(str, length, suffix = "...") {
|
|
2
|
-
if (typeof str !== "string") {
|
|
3
|
-
throw new Error("Input must be a string");
|
|
4
|
-
}
|
|
5
|
-
if (typeof length !== "number" || length < 0) {
|
|
6
|
-
throw new Error("Length must be a non-negative number");
|
|
7
|
-
}
|
|
8
|
-
if (str.length <= length) {
|
|
9
|
-
return str;
|
|
10
|
-
}
|
|
11
|
-
if (length === 0) {
|
|
12
|
-
return suffix;
|
|
13
|
-
}
|
|
14
|
-
return str.slice(0, Math.max(0, length - suffix.length)) + suffix;
|
|
15
|
-
}
|
package/dist/esm/string.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './string/index.js'
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export function extractYouTubeId(urlString) {
|
|
2
|
-
if (!urlString)
|
|
3
|
-
return null;
|
|
4
|
-
try {
|
|
5
|
-
const url = new URL(urlString);
|
|
6
|
-
const hostname = url.hostname.toLowerCase();
|
|
7
|
-
const pathname = url.pathname;
|
|
8
|
-
if (hostname.includes("youtu.be")) {
|
|
9
|
-
const id = pathname.replace(/^\/+/, "").split(/[?&#]/)[0];
|
|
10
|
-
return id || null;
|
|
11
|
-
}
|
|
12
|
-
if (hostname.includes("youtube.com")) {
|
|
13
|
-
if (url.searchParams.has("v")) {
|
|
14
|
-
return url.searchParams.get("v");
|
|
15
|
-
}
|
|
16
|
-
const parts = pathname.split("/").filter(Boolean);
|
|
17
|
-
const last = parts[parts.length - 1];
|
|
18
|
-
if (last)
|
|
19
|
-
return last.split(/[?&#]/)[0] || null;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch (_a) { }
|
|
23
|
-
const regex = /(?:v=|\/embed\/|\/shorts\/|youtu\.be\/)([0-9A-Za-z_-]{6,})/i;
|
|
24
|
-
const match = urlString.match(regex);
|
|
25
|
-
return match ? match[1] : null;
|
|
26
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { formatHMSToSeconds, formatSecondsToFragment } from "../string.js";
|
|
2
|
-
import { extractYouTubeId } from "./extract-youtube-video-id.js";
|
|
3
|
-
export const generateYoutubeURL = (opts) => {
|
|
4
|
-
const { videoURL, start, end, embed = false, short = false, useFragment = false, autoplay, controls, rel, loop, mute, modestbranding, origin, playlist, params = {}, } = opts;
|
|
5
|
-
const videoId = extractYouTubeId(videoURL);
|
|
6
|
-
if (!videoId)
|
|
7
|
-
return null;
|
|
8
|
-
const startSec = formatHMSToSeconds(start);
|
|
9
|
-
const endSec = formatHMSToSeconds(end);
|
|
10
|
-
// base url
|
|
11
|
-
const base = embed
|
|
12
|
-
? `https://www.youtube.com/embed/${videoId}`
|
|
13
|
-
: short
|
|
14
|
-
? `https://youtu.be/${videoId}`
|
|
15
|
-
: "https://www.youtube.com/watch";
|
|
16
|
-
const search = new URLSearchParams();
|
|
17
|
-
// Add video ID for watch URLs
|
|
18
|
-
if (!embed && !short) {
|
|
19
|
-
search.set("v", videoId);
|
|
20
|
-
}
|
|
21
|
-
// Standard param names for watch/embed
|
|
22
|
-
if (!useFragment) {
|
|
23
|
-
if (startSec != null) {
|
|
24
|
-
// youtu.be historically uses "t" as a query param, but "start" is widely supported.
|
|
25
|
-
// Use "t" for short links, otherwise "start".
|
|
26
|
-
search.set(short ? "t" : "start", String(startSec));
|
|
27
|
-
}
|
|
28
|
-
if (endSec != null) {
|
|
29
|
-
search.set("end", String(endSec));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// embed / player related params
|
|
33
|
-
if (typeof autoplay !== "undefined")
|
|
34
|
-
search.set("autoplay", autoplay ? "1" : "0");
|
|
35
|
-
if (typeof controls !== "undefined")
|
|
36
|
-
search.set("controls", String(controls));
|
|
37
|
-
if (typeof rel !== "undefined")
|
|
38
|
-
search.set("rel", String(rel));
|
|
39
|
-
if (typeof modestbranding !== "undefined")
|
|
40
|
-
search.set("modestbranding", String(modestbranding));
|
|
41
|
-
if (typeof origin !== "undefined")
|
|
42
|
-
search.set("origin", origin);
|
|
43
|
-
if (typeof mute !== "undefined")
|
|
44
|
-
search.set("mute", mute ? "1" : "0");
|
|
45
|
-
// loop requires playlist param when embedding a single video
|
|
46
|
-
if (loop) {
|
|
47
|
-
search.set("loop", "1");
|
|
48
|
-
if (playlist) {
|
|
49
|
-
search.set("playlist", playlist);
|
|
50
|
-
}
|
|
51
|
-
else if (embed) {
|
|
52
|
-
// for embed+loop, YouTube expects &playlist=VIDEO_ID
|
|
53
|
-
search.set("playlist", videoId);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (playlist) {
|
|
57
|
-
search.set("playlist", playlist);
|
|
58
|
-
}
|
|
59
|
-
// merge custom params (allow overriding)
|
|
60
|
-
Object.entries(params).forEach(([k, v]) => {
|
|
61
|
-
if (v === false)
|
|
62
|
-
search.set(k, "0");
|
|
63
|
-
else if (v === true)
|
|
64
|
-
search.set(k, "1");
|
|
65
|
-
else
|
|
66
|
-
search.set(k, String(v));
|
|
67
|
-
});
|
|
68
|
-
const qs = search.toString() ? `?${search.toString()}` : "";
|
|
69
|
-
// fragment handling (e.g. #t=1m2s)
|
|
70
|
-
let fragment = "";
|
|
71
|
-
if (useFragment && startSec != null) {
|
|
72
|
-
fragment = `#t=${formatSecondsToFragment(startSec)}`;
|
|
73
|
-
}
|
|
74
|
-
// For short links, people often prefer the short host and start as query or fragment.
|
|
75
|
-
if (short) {
|
|
76
|
-
// prefer fragment if requested, otherwise use search params (t)
|
|
77
|
-
return `${base}${qs}${fragment}`;
|
|
78
|
-
}
|
|
79
|
-
// watch/embed links
|
|
80
|
-
return `${base}${qs}${fragment}`;
|
|
81
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export async function getYoutubeThumbnail(videoUrl) {
|
|
2
|
-
const { extractYouTubeId } = await import("./extract-youtube-video-id.js");
|
|
3
|
-
const videoId = extractYouTubeId(videoUrl);
|
|
4
|
-
if (!videoId)
|
|
5
|
-
return null;
|
|
6
|
-
// Try loading YouTube thumbnail images — avoids CORS problems because
|
|
7
|
-
// creating an Image and listening for load/error is not blocked by CORS.
|
|
8
|
-
const thumbs = [
|
|
9
|
-
`https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`,
|
|
10
|
-
`https://img.youtube.com/vi/${videoId}/hqdefault.jpg`,
|
|
11
|
-
`https://img.youtube.com/vi/${videoId}/mqdefault.jpg`,
|
|
12
|
-
`https://img.youtube.com/vi/${videoId}/default.jpg`,
|
|
13
|
-
];
|
|
14
|
-
const loadImage = (src) => new Promise((resolve) => {
|
|
15
|
-
const img = new Image();
|
|
16
|
-
img.onload = () => resolve(true);
|
|
17
|
-
img.onerror = () => resolve(false);
|
|
18
|
-
img.src = src;
|
|
19
|
-
});
|
|
20
|
-
for (const url of thumbs) {
|
|
21
|
-
try {
|
|
22
|
-
const ok = await loadImage(url);
|
|
23
|
-
if (ok)
|
|
24
|
-
return url;
|
|
25
|
-
}
|
|
26
|
-
catch (_a) {
|
|
27
|
-
// ignore and try next thumbnail
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
const videoInfoCache = new Map();
|
|
2
|
-
export async function getYoutubeVideoInfo(videoUrl) {
|
|
3
|
-
const { extractYouTubeId } = await import("./extract-youtube-video-id.js");
|
|
4
|
-
const videoId = extractYouTubeId(videoUrl);
|
|
5
|
-
if (!videoId)
|
|
6
|
-
return null;
|
|
7
|
-
const cached = videoInfoCache.get(videoId);
|
|
8
|
-
if (cached)
|
|
9
|
-
return cached;
|
|
10
|
-
const fetchPromise = fetchYoutubeVideoInfo(videoId);
|
|
11
|
-
videoInfoCache.set(videoId, fetchPromise);
|
|
12
|
-
const info = await fetchPromise;
|
|
13
|
-
if (!info) {
|
|
14
|
-
videoInfoCache.delete(videoId);
|
|
15
|
-
}
|
|
16
|
-
return info;
|
|
17
|
-
}
|
|
18
|
-
async function fetchYoutubeVideoInfo(videoId) {
|
|
19
|
-
const watchUrl = `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`;
|
|
20
|
-
const htmlInfo = await fetchFromWatchPage(videoId, watchUrl);
|
|
21
|
-
if (htmlInfo)
|
|
22
|
-
return htmlInfo;
|
|
23
|
-
const oEmbedInfo = await fetchFromOEmbed(videoId, watchUrl);
|
|
24
|
-
if (oEmbedInfo)
|
|
25
|
-
return oEmbedInfo;
|
|
26
|
-
const noEmbedInfo = await fetchFromNoEmbed(videoId, watchUrl);
|
|
27
|
-
if (noEmbedInfo)
|
|
28
|
-
return noEmbedInfo;
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
async function fetchFromWatchPage(videoId, watchUrl) {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
33
|
-
try {
|
|
34
|
-
const response = await fetch(watchUrl);
|
|
35
|
-
if (!response.ok) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const html = await response.text();
|
|
39
|
-
const rawJson = extractJsonBlock(html, "ytInitialPlayerResponse");
|
|
40
|
-
if (!rawJson) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const data = JSON.parse(rawJson);
|
|
44
|
-
const details = data.videoDetails;
|
|
45
|
-
const microformat = (_a = data.microformat) === null || _a === void 0 ? void 0 : _a.playerMicroformatRenderer;
|
|
46
|
-
if (!details && !microformat) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const thumbnails = getThumbnails(details, microformat);
|
|
50
|
-
const bestThumbnail = selectBestThumbnail(thumbnails);
|
|
51
|
-
return {
|
|
52
|
-
id: (_b = details === null || details === void 0 ? void 0 : details.videoId) !== null && _b !== void 0 ? _b : videoId,
|
|
53
|
-
url: watchUrl,
|
|
54
|
-
title: (_d = (_c = details === null || details === void 0 ? void 0 : details.title) !== null && _c !== void 0 ? _c : extractText(microformat === null || microformat === void 0 ? void 0 : microformat.title)) !== null && _d !== void 0 ? _d : "",
|
|
55
|
-
channelTitle: (_f = (_e = details === null || details === void 0 ? void 0 : details.author) !== null && _e !== void 0 ? _e : microformat === null || microformat === void 0 ? void 0 : microformat.ownerChannelName) !== null && _f !== void 0 ? _f : "",
|
|
56
|
-
channelId: (_g = details === null || details === void 0 ? void 0 : details.channelId) !== null && _g !== void 0 ? _g : microformat === null || microformat === void 0 ? void 0 : microformat.externalChannelId,
|
|
57
|
-
channelUrl: microformat === null || microformat === void 0 ? void 0 : microformat.ownerProfileUrl,
|
|
58
|
-
description: (_h = extractText(microformat === null || microformat === void 0 ? void 0 : microformat.description)) !== null && _h !== void 0 ? _h : details === null || details === void 0 ? void 0 : details.shortDescription,
|
|
59
|
-
shortDescription: details === null || details === void 0 ? void 0 : details.shortDescription,
|
|
60
|
-
thumbnails,
|
|
61
|
-
thumbnail: bestThumbnail === null || bestThumbnail === void 0 ? void 0 : bestThumbnail.url,
|
|
62
|
-
publishedAt: (_j = microformat === null || microformat === void 0 ? void 0 : microformat.publishDate) !== null && _j !== void 0 ? _j : microformat === null || microformat === void 0 ? void 0 : microformat.uploadDate,
|
|
63
|
-
uploadedAt: microformat === null || microformat === void 0 ? void 0 : microformat.uploadDate,
|
|
64
|
-
keywords: details === null || details === void 0 ? void 0 : details.keywords,
|
|
65
|
-
viewCount: parseNumber(details === null || details === void 0 ? void 0 : details.viewCount),
|
|
66
|
-
lengthSeconds: parseNumber(details === null || details === void 0 ? void 0 : details.lengthSeconds),
|
|
67
|
-
isLive: (_k = details === null || details === void 0 ? void 0 : details.isLiveContent) !== null && _k !== void 0 ? _k : (_l = microformat === null || microformat === void 0 ? void 0 : microformat.liveBroadcastDetails) === null || _l === void 0 ? void 0 : _l.isLiveNow,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
catch (_m) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async function fetchFromOEmbed(videoId, watchUrl) {
|
|
75
|
-
var _a;
|
|
76
|
-
try {
|
|
77
|
-
const oEmbedUrl = `https://www.youtube.com/oembed?url=${encodeURIComponent(watchUrl)}&format=json`;
|
|
78
|
-
const response = await fetch(oEmbedUrl);
|
|
79
|
-
if (!response.ok) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
const data = (await response.json());
|
|
83
|
-
if (!(data === null || data === void 0 ? void 0 : data.title) || !(data === null || data === void 0 ? void 0 : data.author_name)) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
const thumbnails = createThumbnailList(data.thumbnail_url, data.thumbnail_width, data.thumbnail_height);
|
|
87
|
-
return {
|
|
88
|
-
id: videoId,
|
|
89
|
-
url: watchUrl,
|
|
90
|
-
title: data.title,
|
|
91
|
-
channelTitle: data.author_name,
|
|
92
|
-
channelUrl: data.author_url,
|
|
93
|
-
thumbnails,
|
|
94
|
-
thumbnail: (_a = thumbnails[0]) === null || _a === void 0 ? void 0 : _a.url,
|
|
95
|
-
description: undefined,
|
|
96
|
-
shortDescription: undefined,
|
|
97
|
-
publishedAt: undefined,
|
|
98
|
-
uploadedAt: undefined,
|
|
99
|
-
keywords: undefined,
|
|
100
|
-
viewCount: undefined,
|
|
101
|
-
lengthSeconds: undefined,
|
|
102
|
-
isLive: undefined,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
catch (_b) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
async function fetchFromNoEmbed(videoId, watchUrl) {
|
|
110
|
-
var _a;
|
|
111
|
-
try {
|
|
112
|
-
const noEmbedUrl = `https://noembed.com/embed?url=${encodeURIComponent(watchUrl)}`;
|
|
113
|
-
const response = await fetch(noEmbedUrl);
|
|
114
|
-
if (!response.ok) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
const data = (await response.json());
|
|
118
|
-
if (!(data === null || data === void 0 ? void 0 : data.title) || !(data === null || data === void 0 ? void 0 : data.author_name)) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const thumbnails = createThumbnailList(data.thumbnail_url, data.thumbnail_width, data.thumbnail_height);
|
|
122
|
-
return {
|
|
123
|
-
id: videoId,
|
|
124
|
-
url: watchUrl,
|
|
125
|
-
title: data.title,
|
|
126
|
-
channelTitle: data.author_name,
|
|
127
|
-
channelUrl: data.author_url,
|
|
128
|
-
description: data.description,
|
|
129
|
-
shortDescription: data.description,
|
|
130
|
-
thumbnails,
|
|
131
|
-
thumbnail: (_a = thumbnails[0]) === null || _a === void 0 ? void 0 : _a.url,
|
|
132
|
-
publishedAt: data.upload_date,
|
|
133
|
-
uploadedAt: data.upload_date,
|
|
134
|
-
keywords: undefined,
|
|
135
|
-
viewCount: undefined,
|
|
136
|
-
lengthSeconds: undefined,
|
|
137
|
-
isLive: undefined,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
catch (_b) {
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function extractJsonBlock(html, marker) {
|
|
145
|
-
const markerIndex = html.indexOf(marker);
|
|
146
|
-
if (markerIndex === -1)
|
|
147
|
-
return null;
|
|
148
|
-
const jsonStart = html.indexOf("{", markerIndex);
|
|
149
|
-
if (jsonStart === -1)
|
|
150
|
-
return null;
|
|
151
|
-
let depth = 0;
|
|
152
|
-
for (let i = jsonStart; i < html.length; i++) {
|
|
153
|
-
const char = html[i];
|
|
154
|
-
if (char === "{") {
|
|
155
|
-
depth += 1;
|
|
156
|
-
}
|
|
157
|
-
else if (char === "}") {
|
|
158
|
-
depth -= 1;
|
|
159
|
-
}
|
|
160
|
-
if (depth === 0) {
|
|
161
|
-
return html.slice(jsonStart, i + 1);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
function getThumbnails(details, microformat) {
|
|
167
|
-
var _a, _b, _c, _d;
|
|
168
|
-
if ((_b = (_a = details === null || details === void 0 ? void 0 : details.thumbnail) === null || _a === void 0 ? void 0 : _a.thumbnails) === null || _b === void 0 ? void 0 : _b.length) {
|
|
169
|
-
return details.thumbnail.thumbnails;
|
|
170
|
-
}
|
|
171
|
-
return (_d = (_c = microformat === null || microformat === void 0 ? void 0 : microformat.thumbnail) === null || _c === void 0 ? void 0 : _c.thumbnails) !== null && _d !== void 0 ? _d : [];
|
|
172
|
-
}
|
|
173
|
-
function selectBestThumbnail(thumbnails) {
|
|
174
|
-
if (!thumbnails.length)
|
|
175
|
-
return undefined;
|
|
176
|
-
return thumbnails.reduce((best, current) => {
|
|
177
|
-
if (!best)
|
|
178
|
-
return current;
|
|
179
|
-
if (!best.width)
|
|
180
|
-
return current;
|
|
181
|
-
if (!current.width)
|
|
182
|
-
return best;
|
|
183
|
-
return current.width > best.width ? current : best;
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
function extractText(field) {
|
|
187
|
-
var _a;
|
|
188
|
-
if (!field)
|
|
189
|
-
return undefined;
|
|
190
|
-
if (field.simpleText)
|
|
191
|
-
return field.simpleText;
|
|
192
|
-
if ((_a = field.runs) === null || _a === void 0 ? void 0 : _a.length) {
|
|
193
|
-
return field.runs.map((run) => { var _a; return (_a = run.text) !== null && _a !== void 0 ? _a : ""; }).join("");
|
|
194
|
-
}
|
|
195
|
-
return undefined;
|
|
196
|
-
}
|
|
197
|
-
function parseNumber(value) {
|
|
198
|
-
if (value === undefined)
|
|
199
|
-
return undefined;
|
|
200
|
-
const parsed = Number(value);
|
|
201
|
-
return Number.isNaN(parsed) ? undefined : parsed;
|
|
202
|
-
}
|
|
203
|
-
function createThumbnailList(url, width, height) {
|
|
204
|
-
if (!url)
|
|
205
|
-
return [];
|
|
206
|
-
return [{ url, width, height }];
|
|
207
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from "./extract-youtube-video-id.js";
|
|
2
|
-
export * from "./generate-youtube-url.js";
|
|
3
|
-
export * from "./get-youtube-thumbnail.js";
|
|
4
|
-
export * from "./get-youtube-video-info.js";
|
|
5
|
-
export * from "./use-get-video-duration.js";
|
|
6
|
-
export * from "./validate-youtube-link.js";
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/suspicious/noExplicitAny: Window is any */
|
|
2
|
-
import { formatSecondsToHMS } from "../string.js";
|
|
3
|
-
import { extractYouTubeId } from "./extract-youtube-video-id.js";
|
|
4
|
-
import { validateYoutubeLink } from "./validate-youtube-link.js";
|
|
5
|
-
let YtApiLoading = null;
|
|
6
|
-
function loadYouTubeIFrameAPI() {
|
|
7
|
-
var _a;
|
|
8
|
-
if ((_a = window.YT) === null || _a === void 0 ? void 0 : _a.Player)
|
|
9
|
-
return Promise.resolve();
|
|
10
|
-
if (YtApiLoading)
|
|
11
|
-
return YtApiLoading;
|
|
12
|
-
YtApiLoading = new Promise((resolve) => {
|
|
13
|
-
const existing = document.querySelector('script[src="https://www.youtube.com/iframe_api"]');
|
|
14
|
-
if (existing) {
|
|
15
|
-
// Poll until the API is ready
|
|
16
|
-
const poll = setInterval(() => {
|
|
17
|
-
var _a;
|
|
18
|
-
if ((_a = window.YT) === null || _a === void 0 ? void 0 : _a.Player) {
|
|
19
|
-
clearInterval(poll);
|
|
20
|
-
resolve();
|
|
21
|
-
}
|
|
22
|
-
}, 50);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const tag = document.createElement("script");
|
|
26
|
-
tag.src = "https://www.youtube.com/iframe_api";
|
|
27
|
-
tag.async = true;
|
|
28
|
-
document.body.appendChild(tag);
|
|
29
|
-
window.onYouTubeIframeAPIReady = () => {
|
|
30
|
-
resolve();
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
return YtApiLoading;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* useGetYoutubeVideoDuration
|
|
37
|
-
* Returns a function that accepts a YouTube URL (full or short) and returns a Promise
|
|
38
|
-
* resolving to the video duration formatted as "HH:MM:SS" or null on failure.
|
|
39
|
-
*/
|
|
40
|
-
export function useGetYoutubeVideoDuration() {
|
|
41
|
-
const getYoutubeVideoDuration = async (videoUrl) => {
|
|
42
|
-
const videoId = extractYouTubeId(videoUrl);
|
|
43
|
-
if (!videoId)
|
|
44
|
-
return null;
|
|
45
|
-
const videoIsValid = await validateYoutubeLink(videoUrl);
|
|
46
|
-
if (!videoIsValid)
|
|
47
|
-
return null;
|
|
48
|
-
try {
|
|
49
|
-
await loadYouTubeIFrameAPI();
|
|
50
|
-
}
|
|
51
|
-
catch (_a) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
return await new Promise((resolve) => {
|
|
55
|
-
const iframeId = `yt-duration-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
56
|
-
const iframe = document.createElement("iframe");
|
|
57
|
-
// create a minimal offscreen iframe for the player
|
|
58
|
-
iframe.id = iframeId;
|
|
59
|
-
iframe.style.position = "fixed";
|
|
60
|
-
iframe.style.left = "-9999px";
|
|
61
|
-
iframe.style.width = "1px";
|
|
62
|
-
iframe.style.height = "1px";
|
|
63
|
-
iframe.style.opacity = "0";
|
|
64
|
-
iframe.style.pointerEvents = "none";
|
|
65
|
-
// embed URL with enablejsapi so we can construct YT.Player
|
|
66
|
-
const origin = window.location.origin;
|
|
67
|
-
iframe.src = `https://www.youtube.com/embed/${encodeURIComponent(videoId)}?enablejsapi=1&origin=${encodeURIComponent(origin)}`;
|
|
68
|
-
let resolved = false;
|
|
69
|
-
let player = null;
|
|
70
|
-
let cleanupTimeout = null;
|
|
71
|
-
function cleanupAndResolve(result) {
|
|
72
|
-
if (resolved)
|
|
73
|
-
return;
|
|
74
|
-
resolved = true;
|
|
75
|
-
try {
|
|
76
|
-
if (player && typeof player.destroy === "function")
|
|
77
|
-
player.destroy();
|
|
78
|
-
}
|
|
79
|
-
catch (_a) {
|
|
80
|
-
/* ignore */
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
if (iframe.parentNode)
|
|
84
|
-
iframe.parentNode.removeChild(iframe);
|
|
85
|
-
}
|
|
86
|
-
catch (_b) {
|
|
87
|
-
/* ignore */
|
|
88
|
-
}
|
|
89
|
-
if (cleanupTimeout)
|
|
90
|
-
window.clearTimeout(cleanupTimeout);
|
|
91
|
-
resolve(result);
|
|
92
|
-
}
|
|
93
|
-
// timeout fallback
|
|
94
|
-
cleanupTimeout = window.setTimeout(() => {
|
|
95
|
-
cleanupAndResolve(null);
|
|
96
|
-
}, 10000); // 10s timeout
|
|
97
|
-
document.body.appendChild(iframe);
|
|
98
|
-
// Construct player
|
|
99
|
-
try {
|
|
100
|
-
player = new window.YT.Player(iframeId, {
|
|
101
|
-
events: {
|
|
102
|
-
onReady: (e) => {
|
|
103
|
-
try {
|
|
104
|
-
let duration = e.target.getDuration();
|
|
105
|
-
if (!duration || duration === 0) {
|
|
106
|
-
// Sometimes duration is 0 immediately; try a few short retries
|
|
107
|
-
let attempts = 0;
|
|
108
|
-
const tryInterval = setInterval(() => {
|
|
109
|
-
attempts += 1;
|
|
110
|
-
try {
|
|
111
|
-
duration = e.target.getDuration();
|
|
112
|
-
if (duration && duration > 0) {
|
|
113
|
-
clearInterval(tryInterval);
|
|
114
|
-
cleanupAndResolve(formatSecondsToHMS(duration));
|
|
115
|
-
}
|
|
116
|
-
else if (attempts >= 8) {
|
|
117
|
-
clearInterval(tryInterval);
|
|
118
|
-
cleanupAndResolve(null);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (_a) {
|
|
122
|
-
if (attempts >= 8) {
|
|
123
|
-
clearInterval(tryInterval);
|
|
124
|
-
cleanupAndResolve(null);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}, 300);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
cleanupAndResolve(formatSecondsToHMS(duration));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
catch (_a) {
|
|
134
|
-
cleanupAndResolve(null);
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
onError: () => {
|
|
138
|
-
cleanupAndResolve(null);
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
catch (_a) {
|
|
144
|
-
cleanupAndResolve(null);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
return getYoutubeVideoDuration;
|
|
149
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export async function validateYoutubeLink(videoUrl) {
|
|
2
|
-
const { extractYouTubeId } = await import("./extract-youtube-video-id.js");
|
|
3
|
-
const videoId = extractYouTubeId(videoUrl);
|
|
4
|
-
if (!videoId)
|
|
5
|
-
return false;
|
|
6
|
-
// Try loading YouTube thumbnail images — avoids CORS problems because
|
|
7
|
-
// creating an Image and listening for load/error is not blocked by CORS.
|
|
8
|
-
const thumbs = [
|
|
9
|
-
`https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`,
|
|
10
|
-
`https://img.youtube.com/vi/${videoId}/hqdefault.jpg`,
|
|
11
|
-
`https://img.youtube.com/vi/${videoId}/mqdefault.jpg`,
|
|
12
|
-
`https://img.youtube.com/vi/${videoId}/default.jpg`,
|
|
13
|
-
];
|
|
14
|
-
const loadImage = (src) => new Promise((resolve) => {
|
|
15
|
-
const img = new Image();
|
|
16
|
-
img.onload = () => resolve(true);
|
|
17
|
-
img.onerror = () => resolve(false);
|
|
18
|
-
img.src = src;
|
|
19
|
-
});
|
|
20
|
-
for (const url of thumbs) {
|
|
21
|
-
try {
|
|
22
|
-
const ok = await loadImage(url);
|
|
23
|
-
if (ok)
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
catch (_a) {
|
|
27
|
-
// ignore and try next thumbnail
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// Fallback: try oEmbed endpoint (may be subject to CORS in some environments)
|
|
31
|
-
try {
|
|
32
|
-
const watchUrl = `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`;
|
|
33
|
-
const oembedUrl = `https://www.youtube.com/oembed?url=${encodeURIComponent(watchUrl)}&format=json`;
|
|
34
|
-
const res = await fetch(oembedUrl, { method: "GET" });
|
|
35
|
-
return res.ok;
|
|
36
|
-
}
|
|
37
|
-
catch (_b) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
package/dist/esm/youtube.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './youtube/index.js'
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
interface ICompressImageParams {
|
|
2
|
-
file: File;
|
|
3
|
-
maxWidth?: number;
|
|
4
|
-
maxHeight?: number;
|
|
5
|
-
quality?: number;
|
|
6
|
-
allowedFileTypes?: string[];
|
|
7
|
-
}
|
|
8
|
-
export declare function compressImage({ file, maxWidth, maxHeight, quality, allowedFileTypes, }: ICompressImageParams): Promise<File>;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=compress-image.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress-image.d.ts","sourceRoot":"","sources":["../../src/files/compress-image.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC5B;AAYD,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAmC,EACnC,SAAoC,EACpC,OAAW,EACX,gBAAyE,GAC1E,EAAE,oBAAoB,iBAiEtB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download-url.d.ts","sourceRoot":"","sources":["../../src/files/download-url.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,OAAO,CAyB9D,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-delete.d.ts","sourceRoot":"","sources":["../../src/files/file-delete.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,kBAOhD,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-exists.d.ts","sourceRoot":"","sources":["../../src/files/file-exists.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,GAAU,UAAU,MAAM,qBAOhD,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format-bytes.d.ts","sourceRoot":"","sources":["../../src/files/format-bytes.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAejD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type TAnyFunction = (...args: unknown[]) => unknown;
|
|
2
|
-
/**
|
|
3
|
-
* Creates a debounced function that delays invoking func until after delay milliseconds
|
|
4
|
-
* have elapsed since the last time the debounced function was invoked
|
|
5
|
-
* @param fn - The function to debounce
|
|
6
|
-
* @param delay - The number of milliseconds to delay
|
|
7
|
-
* @returns The debounced function
|
|
8
|
-
*/
|
|
9
|
-
export declare function debounce<T extends TAnyFunction>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=debounce.d.ts.map
|