From 493feda33e3b935c6aa5d94d24068a4f7825413c Mon Sep 17 00:00:00 2001 From: hunghg255 Date: Mon, 15 Jul 2024 16:03:59 +0700 Subject: [PATCH] docs: update --- docs/.vitepress/config.ts | 61 ++++++++++++++++++++---- docs/.vitepress/locale.ts | 4 +- docs/.vitepress/theme/index.ts | 3 ++ docs/.vitepress/theme/style.css | 50 +++++++++++++++++++ docs/index.md | 6 --- docs/package.json | 3 +- docs/public/favicon.ico | Bin 0 -> 15406 bytes docs/public/logo.svg | 1 + docs/reference/array/chunk.md | 2 +- docs/reference/array/compact.md | 4 +- docs/reference/array/countBy.md | 2 +- docs/reference/array/difference.md | 2 +- docs/reference/array/differenceBy.md | 2 - docs/reference/array/drop.md | 4 +- docs/reference/array/dropRight.md | 4 +- docs/reference/array/dropRightWhile.md | 4 +- docs/reference/array/dropWhile.md | 4 +- docs/reference/array/fill.md | 4 +- docs/reference/array/flatten.md | 4 +- docs/reference/array/flattenDeep.md | 4 +- docs/reference/array/groupBy.md | 4 +- docs/reference/array/head.md | 4 +- docs/reference/array/keyBy.md | 4 +- docs/reference/array/orderBy.md | 4 +- docs/reference/array/sample.md | 4 +- docs/reference/array/sampleSize.md | 4 +- docs/reference/array/shuffle.md | 4 +- docs/reference/array/take.md | 4 +- docs/reference/array/takeRight.md | 4 +- docs/reference/array/takeRightWhile.md | 4 +- docs/reference/array/takeWhile.md | 4 +- docs/reference/array/toFilled.md | 4 +- docs/reference/array/union.md | 4 +- docs/reference/array/unionBy.md | 4 +- docs/reference/array/uniq.md | 4 +- docs/reference/array/uniqBy.md | 4 +- docs/reference/array/unzipWith.md | 4 +- docs/reference/array/without.md | 2 +- docs/reference/array/xor.md | 4 +- docs/reference/array/xorBy.md | 4 +- docs/reference/array/xorWith.md | 4 +- docs/reference/array/zip.md | 4 +- docs/reference/array/zipObject.md | 4 +- docs/reference/function/debounce.md | 8 +++- docs/reference/function/negate.md | 2 +- docs/reference/function/noop.md | 2 +- docs/reference/math/clamp.md | 4 +- docs/reference/math/inRange.md | 4 +- docs/reference/math/mean.md | 4 +- docs/reference/math/random.md | 4 +- docs/reference/math/randomInt.md | 4 +- docs/reference/math/range.md | 4 +- docs/reference/math/round.md | 4 +- docs/reference/math/sum.md | 4 +- docs/reference/object/clone.md | 4 +- docs/reference/object/invert.md | 4 +- docs/reference/object/omit.md | 4 +- docs/reference/object/pick.md | 4 +- docs/reference/predicate/isEqual.md | 24 +++++++--- docs/reference/predicate/isNil.md | 2 +- docs/reference/predicate/isNotNil.md | 4 +- docs/reference/predicate/isNull.md | 4 +- docs/reference/predicate/isUndefined.md | 4 +- docs/reference/promise/delay.md | 8 +++- docs/reference/string/camelCase.md | 2 +- docs/reference/string/capitalize.md | 2 +- docs/reference/string/kebabCase.md | 2 +- docs/reference/string/lowerCase.md | 2 +- docs/reference/string/snakeCase.md | 2 +- docs/vite.config.ts | 1 + package.json | 2 +- pnpm-lock.yaml | 5 +- src/array/chunk.ts | 4 ++ src/string/snakeCase.ts | 2 + 74 files changed, 300 insertions(+), 88 deletions(-) create mode 100644 docs/public/favicon.ico create mode 100644 docs/public/logo.svg diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index c874ae6..eda135f 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -1,6 +1,6 @@ import { defineConfig } from 'vitepress' -import { transformerTwoslash } from '@shikijs/vitepress-twoslash' -import ts from 'typescript' +import { defaultHoverInfoProcessor, transformerTwoslash } from '@shikijs/vitepress-twoslash' +import { transformerRemoveNotationEscape } from '@shikijs/transformers' import { getLocaleConfig } from './locale' const docsLink = 'https://js-utils-es.vercel.app' @@ -41,15 +41,60 @@ export default defineConfig({ }, markdown: { codeTransformers: [ + { + // Render custom themes with codeblocks + name: 'shiki:inline-theme', + preprocess(code, options) { + const reg = /\btheme:([\w,-]+)\b/ + const match = options.meta?.__raw?.match(reg) + if (!match?.[1]) + return + const theme = match[1] + const themes = theme.split(',').map(i => i.trim()) + if (!themes.length) + return + if (themes.length === 1) { + // @ts-expect-error anyway + delete options.themes + // @ts-expect-error anyway + options.theme = themes[0] + } + else if (themes.length === 2) { + // @ts-expect-error anyway + delete options.theme + // @ts-expect-error anyway + options.themes = { + light: themes[0], + dark: themes[1], + } + } + else { + throw new Error(`Only 1 or 2 themes are supported, got ${themes.length}`) + } + return code + }, + }, + { + name: 'shiki:inline-decorations', + preprocess(code, options) { + const reg = /^\/\/ @decorations:(.*)\n/ + code = code.replace(reg, (match, decorations) => { + options.decorations ||= [] + options.decorations.push(...JSON.parse(decorations)) + return '' + }) + return code + }, + }, transformerTwoslash({ - twoslashOptions: { - compilerOptions: { - jsx: ts.JsxEmit.Preserve, - jsxFactory: 'vue', - types: ['unplugin-vue-macros/macros-global', 'vue/jsx'], - }, + // errorRendering: 'hover', + processHoverInfo(info) { + return defaultHoverInfoProcessor(info) + // Remove shiki_core namespace + .replace(/_shikijs_core\w*\./g, '') }, }), + transformerRemoveNotationEscape(), ], }, }) diff --git a/docs/.vitepress/locale.ts b/docs/.vitepress/locale.ts index c40a1f2..6b66ffa 100644 --- a/docs/.vitepress/locale.ts +++ b/docs/.vitepress/locale.ts @@ -20,7 +20,7 @@ export function getLocaleConfig(lang: string) { ['meta', { property: 'og:url', content: docsLink }], ['meta', { property: 'twitter:card', content: 'summary_large_image' }], ['meta', { property: 'twitter:image', content: `${docsLink}/og.png` }], - ['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }], + ['link', { rel: 'icon', href: '/logo.svg', type: 'image/svg+xml' }], ['meta', { name: 'theme-color', content: '#914796' }], ] @@ -174,7 +174,7 @@ export function getLocaleConfig(lang: string) { ] const themeConfig: DefaultTheme.Config = { - logo: '/favicon.svg', + logo: '/logo.svg', nav, sidebar, socialLinks: [ diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index ac1dacd..53c71bf 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -20,6 +20,9 @@ export default { mapAuthors: [ { name: 'hunghg255', + username: 'hunghg255', + mapByNameAliases: ['Hung Hoang', 'Hoang Hung'], + mapByEmailAliases: ['giahunghust@gmail.com'], }, ], }) diff --git a/docs/.vitepress/theme/style.css b/docs/.vitepress/theme/style.css index 940dd44..3fb3e40 100644 --- a/docs/.vitepress/theme/style.css +++ b/docs/.vitepress/theme/style.css @@ -1,3 +1,49 @@ +/** + * Customize default theme styling by overriding CSS variables: + * https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css + */ + +/** + * Colors + * + * Each colors have exact same color scale system with 3 levels of solid + * colors with different brightness, and 1 soft color. + * + * - `XXX-1`: The most solid color used mainly for colored text. It must + * satisfy the contrast ratio against when used on top of `XXX-soft`. + * + * - `XXX-2`: The color used mainly for hover state of the button. + * + * - `XXX-3`: The color for solid background, such as bg color of the button. + * It must satisfy the contrast ratio with pure white (#ffffff) text on + * top of it. + * + * - `XXX-soft`: The color used for subtle background such as custom container + * or badges. It must satisfy the contrast ratio when putting `XXX-1` colors + * on top of it. + * + * The soft color must be semi transparent alpha channel. This is crucial + * because it allows adding multiple "soft" colors on top of each other + * to create a accent, such as when having inline code block inside + * custom containers. + * + * - `default`: The color used purely for subtle indication without any + * special meanings attched to it such as bg color for menu hover state. + * + * - `brand`: Used for primary brand colors, such as link text, button with + * brand theme, etc. + * + * - `tip`: Used to indicate useful information. The default theme uses the + * brand color for this by default. + * + * - `warning`: Used to indicate warning to the users. Used in custom + * container, badges, etc. + * + * - `danger`: Used to show error, or dangerous message to the users. Used + * in custom container, badges, etc. + * -------------------------------------------------------------------------- */ + + /** * Colors * -------------------------------------------------------------------------- */ @@ -135,3 +181,7 @@ .VPLocalSearchBox .excerpt-wrapper { margin-top: 4px; } + +.VPHomeHero .VPImage { + border-radius: 16px; +} diff --git a/docs/index.md b/docs/index.md index 49a2c42..a7f0a6b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,10 +21,4 @@ features: details: js-utils-es ships up to 97% less JavaScript code compared to other alternative libraries. - title: Modern implementation details: js-utils-es fully leverages modern JavaScript APIs for straightforward and error-free implementation. - - title: Robust types - details: js-utils-es offers simple yet robust types for all functions. - - title: Battle-tested - details: js-utils-es has 100% test coverage, ensuring maximum robustness. - - title: Comprehensive runtime support - details: js-utils-es supports all JavaScript environments, including Node.js, Deno, Bun, and browsers. --- diff --git a/docs/package.json b/docs/package.json index e4b9ee5..0d45b26 100644 --- a/docs/package.json +++ b/docs/package.json @@ -9,13 +9,14 @@ "preview": "vitepress preview" }, "dependencies": { + "@shikijs/transformers": "^1.10.3", "prettier": "^3.3.2", "shiki": "^1.10.3" }, "devDependencies": { "@nolebase/vitepress-plugin-enhanced-mark": "^2.2.1", "@nolebase/vitepress-plugin-enhanced-readabilities": "^2.2.1", - "@nolebase/vitepress-plugin-git-changelog": "^2.2.1", + "@nolebase/vitepress-plugin-git-changelog": "^2.2.2", "@nolebase/vitepress-plugin-highlight-targeted-heading": "^2.2.1", "@shikijs/vitepress-twoslash": "^1.10.3", "@vitejs/plugin-vue-jsx": "^4.0.0", diff --git a/docs/public/favicon.ico b/docs/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..51536bb4a92da7f010b10c1cbb5b804578144f53 GIT binary patch literal 15406 zcmeHN>2p*?5Pz2b0r*EvzyIk&s-29D21RvlvBbfihu}Wuz*4k5GW8q z5i3FoatK6@KmZ{?0))c@Zvnx-pzYrz^YY&2Eo^pKUo2j#rsnO-boXz1dU~e2pQ1dW zJgE#Cq;Q|5jDJc|T#BM(Wp)1^{IsHMO%4_$? z|LI<;?E0Hx+#Hb@<-hcbA-z@?&YGc=KXyX5ewfa;emglUYbe`pBk!86{h}|NGE>mG zn5Td1F2U1i{zmelE6l%m_I#$hN6|~a_lq9$cT|MP5v`K&tFQV z@2?fILPy$p{id_t8pyX{M^f^&b1`~;*!+!XwC^nX`(h2Dhg4cE(-}I2e!PUA$>QeW z2LF`kuZm@v)rQTVkds(^gQ}A)J!4HO8uj=>)_8cc?b*(x^jzyn0>Scf)4Kr z8m6fH$~Ns3?_-y5lc#A7<&7LevCco$u^3-8bDlcBbj5~#$v3jG!l|=We!g|vb+Y2e z<6Oe|CT#)sh%w3NKc1KTos9hGgM9fSkDU97aKDkdmc8BUW4rxam7OX57fzm`lkMcY1?(R>k!vUWM?L@8)jO1v zm#512uG++RyaYZn1NIl;{i*7^%&(ho@W2_}?@Z_)eoeJGz88AeZKF`j1#-W+m~q*u zsBtbu+kaMZJZk-8PTjJ4&j_gx+57nn%hdXVFMMFU4MH~T!n=BlDmz{MV?F)bz7j2b zvP;JoyhD6$!S3OYaWBTbTFzVc>F8hbNT;{tCx8D+N6(39E&W^iPh=ba#e2*CEc-(Y zY*wph*@^N3kIQ@HNjOETjN5fy3RTD z4hnsHiNeP^MJ^}S*`3Ev1|#wqk+vIx7CgW!+}cIa^S3B=wL2$c#3vp7BS&7gxmm;n z&dO@Cx!occV=MKNYiK4E^Wb`fBN!Gn z4aD`KV;zQkQpFE_6*j(3wxVJ+u9R_<+H;&|_mxrEmS#iQ$W5U>l9S&X7pt^AISCOT zxm;o{t$y^M00uaUg?cXp1Kg9lFc%4VCZ*xO3Bl9Ht8B|q?~`1)io zACARR!4LbimsjXzyPV`2HiGkOqlM0;OwptEw4jOWS9gT$P|HQbJSgJx-1-rseuR9Y z8n4T>;PphVF4obTze@!_@-4{o*^1p_4#=S*9~?RJJw?9zk%C;evHSHoUF2t@oIir? z2X-Ij`3H6LM~w^lPw+rJ4>2v)$R3Cr$N8s7+jVsfQo%3xUx@uo{@7Q^J$F%`98$@m z<$8RvDhi*vrpkq1DW3Hf*?F%!t7-&p$yeK#ab8TjmNs_@@8wRFPdfM^2f2G-(aOX# z@}^q34%TD%gg&2+oEGYwp+o2T&`W;E|7!VQ&EZ?+|I@`U`Na3W^`GkGV!z1TYW&zl zzr)8b6LN%F{ElEmoC}g>py9`Q0yk=)wi1sHJLXX^Zj#s^0}VgULew5`<~hPqQ9IV^ z9nUuQPd?NW*#8bB{J49dMs4%3zS&2{xGmYjlBKE$k!X&JyYG(ev4X zIy}A|kUH1)X5xn*bk)=u>zmiX8LK9I47FtYjO`{3cr8*Ucxshvf!gC-~_z|N4ui7}Ss_gkTMPk?X*qazDaxffUiu?)3JMz0f z?O5$|rtoWJWb)aheb8XMkzoq}j ceg6*QZ&3cPZRE{=9{ca4`12_1FAWX+3okH@l>h($ literal 0 HcmV?d00001 diff --git a/docs/public/logo.svg b/docs/public/logo.svg new file mode 100644 index 0000000..7cf4be1 --- /dev/null +++ b/docs/public/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/reference/array/chunk.md b/docs/reference/array/chunk.md index ae380c7..1707531 100644 --- a/docs/reference/array/chunk.md +++ b/docs/reference/array/chunk.md @@ -27,7 +27,7 @@ Throws an error if `size` is not a positive integer. ## Examples -```typescript +```typescript twoslash import { chunk } from 'js-utils-es/array'; // Splits an array of numbers into sub-arrays of length 2 diff --git a/docs/reference/array/compact.md b/docs/reference/array/compact.md index 04d6ac3..e2cb927 100644 --- a/docs/reference/array/compact.md +++ b/docs/reference/array/compact.md @@ -18,7 +18,9 @@ function compact(arr: T[]): Array(arr: T[], mapper: (item: T) => string): Record(firstArr: T[], secondArr: T[], mapper: (value: T) => ## Examples ```typescript -import { differenceBy } from 'js-utils-es/array'; - const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]; const array2 = [{ id: 2 }, { id: 4 }]; const mapper = item => item.id; diff --git a/docs/reference/array/drop.md b/docs/reference/array/drop.md index 8f8609a..7dabd57 100644 --- a/docs/reference/array/drop.md +++ b/docs/reference/array/drop.md @@ -22,7 +22,9 @@ function drop(arr: T[], itemsCount: number): T[]; ## Examples -```typescript +```typescript twoslash +import { drop } from 'js-utils-es/array'; + const array = [1, 2, 3, 4, 5]; const result = drop(array, 2); // result will be [3, 4, 5] since the first two elements are dropped. diff --git a/docs/reference/array/dropRight.md b/docs/reference/array/dropRight.md index de54a48..5d00b56 100644 --- a/docs/reference/array/dropRight.md +++ b/docs/reference/array/dropRight.md @@ -22,7 +22,9 @@ function dropRight(arr: T[], itemsCount: number): T[]; ## Examples -```typescript +```typescript twoslash +import { dropRight } from 'js-utils-es/array'; + const array = [1, 2, 3, 4, 5]; const result = dropRight(array, 2); // result will be [1, 2, 3] since the last two elements are dropped. diff --git a/docs/reference/array/dropRightWhile.md b/docs/reference/array/dropRightWhile.md index feecda6..c25be5b 100644 --- a/docs/reference/array/dropRightWhile.md +++ b/docs/reference/array/dropRightWhile.md @@ -22,7 +22,9 @@ function dropRightWhile(arr: T[], canContinueDropping: (item: T) => boolean): ## Examples -```typescript +```typescript twoslash +import { dropRightWhile } from 'js-utils-es/array'; + const array = [1, 2, 3, 4, 5]; const result = dropRightWhile(array, x => x > 3); // result will be [1, 2, 3] since elements greater than 3 are dropped from the end. diff --git a/docs/reference/array/dropWhile.md b/docs/reference/array/dropWhile.md index ea36dd6..e1203ff 100644 --- a/docs/reference/array/dropWhile.md +++ b/docs/reference/array/dropWhile.md @@ -22,7 +22,9 @@ function dropWhile(arr: T[], canContinueDropping: (item: T) => boolean): T[]; ## Examples -```typescript +```typescript twoslash +import { dropWhile } from 'js-utils-es/array'; + const array = [1, 2, 3, 4, 5]; const result = dropWhile(array, x => x < 3); // result will be [3, 4, 5] since elements less than 3 are dropped. diff --git a/docs/reference/array/fill.md b/docs/reference/array/fill.md index 3d89ef8..0fa3a72 100644 --- a/docs/reference/array/fill.md +++ b/docs/reference/array/fill.md @@ -25,7 +25,9 @@ function fill(array: T[], value: P, start: number, end: number): Array ['a', 'a', 'a'] diff --git a/docs/reference/array/flatten.md b/docs/reference/array/flatten.md index 3d95b99..32ef267 100644 --- a/docs/reference/array/flatten.md +++ b/docs/reference/array/flatten.md @@ -21,7 +21,9 @@ function flatten(arr: T[], depth?: D): Array(arr: T[]): Array>; ## Examples -```typescript +```typescript twoslash +import { flattenDeep } from 'js-utils-es/array'; + const array = [1, [2, [3]], [4, [5, 6]]]; const result = flattenDeep(array); diff --git a/docs/reference/array/groupBy.md b/docs/reference/array/groupBy.md index b958b2f..198e431 100644 --- a/docs/reference/array/groupBy.md +++ b/docs/reference/array/groupBy.md @@ -24,7 +24,9 @@ share that key. ## Examples -```typescript +```typescript twoslash +import { groupBy } from 'js-utils-es/array'; + const array = [ { category: 'fruit', name: 'apple' }, { category: 'fruit', name: 'banana' }, diff --git a/docs/reference/array/head.md b/docs/reference/array/head.md index d1ac148..7585f84 100644 --- a/docs/reference/array/head.md +++ b/docs/reference/array/head.md @@ -21,7 +21,9 @@ export function head(arr: T[]): T | undefined; ## Examples -```typescript +```typescript twoslash +import { head } from 'js-utils-es/array'; + const arr1 = [1, 2, 3]; const firstElement1 = head(arr1); // firstElement1 will be 1 diff --git a/docs/reference/array/keyBy.md b/docs/reference/array/keyBy.md index 347e91f..d525233 100644 --- a/docs/reference/array/keyBy.md +++ b/docs/reference/array/keyBy.md @@ -23,7 +23,9 @@ function keyBy(arr: T[], getKeyFromItem: (item: T) => ## Examples -```typescript +```typescript twoslash +import { keyBy } from 'js-utils-es/array'; + const array = [ { category: 'fruit', name: 'apple' }, { category: 'fruit', name: 'banana' }, diff --git a/docs/reference/array/orderBy.md b/docs/reference/array/orderBy.md index 90d25fe..5fb693d 100644 --- a/docs/reference/array/orderBy.md +++ b/docs/reference/array/orderBy.md @@ -25,7 +25,9 @@ function orderBy(collection: T[], keys: Array, orders: Order[]): T[] ## Examples -```typescript +```typescript twoslash +import { orderBy } from 'js-utils-es/array'; + const users = [ { user: 'fred', age: 48 }, { user: 'barney', age: 34 }, diff --git a/docs/reference/array/sample.md b/docs/reference/array/sample.md index 3140098..70297e6 100644 --- a/docs/reference/array/sample.md +++ b/docs/reference/array/sample.md @@ -20,7 +20,9 @@ function sample(arr: T[]): T; ## Examples -```typescript +```typescript twoslash +import { sample } from 'js-utils-es/array'; + const array = [1, 2, 3, 4, 5]; const randomElement = sample(array); // randomElement will be one of the elements from the array, selected randomly. diff --git a/docs/reference/array/sampleSize.md b/docs/reference/array/sampleSize.md index cf3f53a..494e079 100644 --- a/docs/reference/array/sampleSize.md +++ b/docs/reference/array/sampleSize.md @@ -25,7 +25,9 @@ Throws an error if `size` is greater than the length of `array`. ## Examples -```typescript +```typescript twoslash +import { sampleSize } from 'js-utils-es/array'; + const result = sampleSize([1, 2, 3], 2); // result will be an array containing two of the elements from the array. // [1, 2] or [1, 3] or [2, 3] diff --git a/docs/reference/array/shuffle.md b/docs/reference/array/shuffle.md index 80cf179..bc05974 100644 --- a/docs/reference/array/shuffle.md +++ b/docs/reference/array/shuffle.md @@ -20,7 +20,9 @@ function shuffle(arr: T[]): T[]; ## Examples -```typescript +```typescript twoslash +import { shuffle } from 'js-utils-es/array'; + const array = [1, 2, 3, 4, 5]; const shuffledArray = shuffle(array); // shuffledArray will be a new array with elements of array in random order, e.g., [3, 1, 4, 5, 2] diff --git a/docs/reference/array/take.md b/docs/reference/array/take.md index 478a947..713bd08 100644 --- a/docs/reference/array/take.md +++ b/docs/reference/array/take.md @@ -21,7 +21,9 @@ function take(arr: T[], count: number): T[]; ## Examples -```typescript +```typescript twoslash +import { take } from 'js-utils-es/array'; + // Returns [1, 2, 3] take([1, 2, 3, 4, 5], 3); diff --git a/docs/reference/array/takeRight.md b/docs/reference/array/takeRight.md index bf7363b..a244853 100644 --- a/docs/reference/array/takeRight.md +++ b/docs/reference/array/takeRight.md @@ -21,7 +21,9 @@ function takeRight(arr: T[], count: number): T[]; ## Examples -```typescript +```typescript twoslash +import { takeRight } from 'js-utils-es/array'; + // Returns [4, 5] takeRight([1, 2, 3, 4, 5], 2); diff --git a/docs/reference/array/takeRightWhile.md b/docs/reference/array/takeRightWhile.md index eb91bfe..b89f58e 100644 --- a/docs/reference/array/takeRightWhile.md +++ b/docs/reference/array/takeRightWhile.md @@ -19,7 +19,9 @@ function takeRightWhile(arr: T[], shouldContinueTaking: (item: T) => boolean) ## Examples -```typescript +```typescript twoslash +import { takeRightWhile } from 'js-utils-es/array'; + // Returns [3, 2, 1] takeRightWhile([5, 4, 3, 2, 1], n => n < 4); diff --git a/docs/reference/array/takeWhile.md b/docs/reference/array/takeWhile.md index fe10ad6..9e88b4e 100644 --- a/docs/reference/array/takeWhile.md +++ b/docs/reference/array/takeWhile.md @@ -21,7 +21,9 @@ function takeWhile(arr: T[], shouldContinueTaking: (element: T) => boolean): ## Examples -```typescript +```typescript twoslash +import { takeWhile } from 'js-utils-es/array'; + // Returns [1, 2] takeWhile([1, 2, 3, 4], x => x < 3); diff --git a/docs/reference/array/toFilled.md b/docs/reference/array/toFilled.md index 7447e11..a6e85eb 100644 --- a/docs/reference/array/toFilled.md +++ b/docs/reference/array/toFilled.md @@ -27,7 +27,9 @@ function toFilled(arr: T[], value: U, start: number, end: number): Array(arr1: T[], arr2: T[]): T[]; ## Examples -```typescript +```typescript twoslash +import { union } from 'js-utils-es/array'; + const array1 = [1, 2, 3]; const array2 = [3, 4, 5]; const result = union(array1, array2); diff --git a/docs/reference/array/unionBy.md b/docs/reference/array/unionBy.md index bcf2f43..108824b 100644 --- a/docs/reference/array/unionBy.md +++ b/docs/reference/array/unionBy.md @@ -20,7 +20,9 @@ function unionBy(arr1: T[], arr2: T[], mapper: (item: T) => U): T[]; ## Examples -```typescript +```typescript twoslash +import { unionBy } from 'js-utils-es/array'; + unionBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], x => x.id); // Returns [{ id: 1 }, { id: 2 }, { id: 3 }] ``` diff --git a/docs/reference/array/uniq.md b/docs/reference/array/uniq.md index 85d06e4..58f952d 100644 --- a/docs/reference/array/uniq.md +++ b/docs/reference/array/uniq.md @@ -21,7 +21,9 @@ function uniq(arr: T[]): T[]; ## Examples -```typescript +```typescript twoslash +import { uniq } from 'js-utils-es/array'; + const array = [1, 2, 2, 3, 4, 4, 5]; const result = uniq(array); // result will be [1, 2, 3, 4, 5] diff --git a/docs/reference/array/uniqBy.md b/docs/reference/array/uniqBy.md index 9bb8ac7..01617e3 100644 --- a/docs/reference/array/uniqBy.md +++ b/docs/reference/array/uniqBy.md @@ -19,7 +19,9 @@ function uniqBy(arr: T[], mapper: (item: T) => U): T[]; ## Examples -```typescript +```typescript twoslash +import { uniqBy } from 'js-utils-es/array'; + uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor); // [1.2, 2.1, 3.3, 5.7, 7.19] ``` diff --git a/docs/reference/array/unzipWith.md b/docs/reference/array/unzipWith.md index 48fbec3..20d96c3 100644 --- a/docs/reference/array/unzipWith.md +++ b/docs/reference/array/unzipWith.md @@ -19,7 +19,9 @@ function unzipWith(target: T[][], iteratee: (...args: T[]) => R): R[]; ## Examples -```typescript +```typescript twoslash +import { unzipWith } from 'js-utils-es/array'; + const nestedArray = [ [1, 2], [3, 4], diff --git a/docs/reference/array/without.md b/docs/reference/array/without.md index be62337..123cd29 100644 --- a/docs/reference/array/without.md +++ b/docs/reference/array/without.md @@ -21,7 +21,7 @@ function without(array: T[], ...values: T[]): T[]; ## Examples -```typescript +```typescript twoslash import { without } from 'js-utils-es/array'; // Removes the specified values from the array diff --git a/docs/reference/array/xor.md b/docs/reference/array/xor.md index 6a3178a..49d08a5 100644 --- a/docs/reference/array/xor.md +++ b/docs/reference/array/xor.md @@ -20,7 +20,9 @@ function xor(arr1: T[], arr2: T[]): T[]; ## Examples -```typescript +```typescript twoslash +import { xor } from 'js-utils-es/array'; + // Returns [1, 2, 5, 6] xor([1, 2, 3, 4], [3, 4, 5, 6]); diff --git a/docs/reference/array/xorBy.md b/docs/reference/array/xorBy.md index e1f921f..3b795e3 100644 --- a/docs/reference/array/xorBy.md +++ b/docs/reference/array/xorBy.md @@ -22,7 +22,9 @@ function xorBy(arr1: T[], arr2: T[], mapper: (item: T) => U): T[]; ## Examples -```typescript +```typescript twoslash +import { xorBy } from 'js-utils-es/array'; + // Returns [{ id: 1 }, { id: 3 }] xorBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], x => x.id); ``` diff --git a/docs/reference/array/xorWith.md b/docs/reference/array/xorWith.md index 067f4cd..b99b5c5 100644 --- a/docs/reference/array/xorWith.md +++ b/docs/reference/array/xorWith.md @@ -22,7 +22,9 @@ function xorWith(arr1: T[], arr2: T[], areElementsEqual: (item1: T, item2: T) ## Examples -```typescript +```typescript twoslash +import { xorWith } from 'js-utils-es/array'; + // Returns [{ id: 1 }, { id: 3 }] xorWith([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], (a, b) => a.id === b.id); ``` diff --git a/docs/reference/array/zip.md b/docs/reference/array/zip.md index 08ba95f..62969c5 100644 --- a/docs/reference/array/zip.md +++ b/docs/reference/array/zip.md @@ -27,7 +27,9 @@ function zip(...arrs: T[][]): T[][]; ## Examples -```typescript +```typescript twoslash +import { zip } from 'js-utils-es/array'; + const arr1 = [1, 2, 3]; const arr2 = ['a', 'b', 'c']; const result = zip(arr1, arr2); diff --git a/docs/reference/array/zipObject.md b/docs/reference/array/zipObject.md index 46396f9..8424bf1 100644 --- a/docs/reference/array/zipObject.md +++ b/docs/reference/array/zipObject.md @@ -21,7 +21,9 @@ function zipObject

(keys: P[], values: V[] ## Examples -```typescript +```typescript twoslash +import { zipObject } from 'js-utils-es/array'; + const keys = ['a', 'b', 'c']; const values = [1, 2, 3]; const result = zipObject(keys, values); diff --git a/docs/reference/function/debounce.md b/docs/reference/function/debounce.md index 5a63d65..8bfb4e7 100644 --- a/docs/reference/function/debounce.md +++ b/docs/reference/function/debounce.md @@ -29,7 +29,9 @@ function debounce void>( ### Basic Usage -```typescript +```typescript twoslash +import { debounce } from 'js-utils-es/function'; + const debouncedFunction = debounce(() => { console.log('Function executed'); }, 1000); @@ -43,7 +45,9 @@ debouncedFunction.cancel(); ### Using with an AbortSignal -```typescript +```typescript twoslash +import { debounce } from 'js-utils-es/function'; + const controller = new AbortController(); const signal = controller.signal; const debouncedWithSignalFunction = debounce( diff --git a/docs/reference/function/negate.md b/docs/reference/function/negate.md index 4da6b1a..91b2614 100644 --- a/docs/reference/function/negate.md +++ b/docs/reference/function/negate.md @@ -18,7 +18,7 @@ function negate boolean>(func: F): F; ## Examples -```typescript +```typescript twoslash import { negate } from 'js-utils-es/function'; negate(() => true)(); // returns 'false' diff --git a/docs/reference/function/noop.md b/docs/reference/function/noop.md index a5fc7a6..b228bb9 100644 --- a/docs/reference/function/noop.md +++ b/docs/reference/function/noop.md @@ -14,7 +14,7 @@ function noop(): void; ## Examples -```typescript +```typescript twoslash import { noop } from 'js-utils-es/function'; interface Props { diff --git a/docs/reference/math/clamp.md b/docs/reference/math/clamp.md index 094f50a..a0368a0 100644 --- a/docs/reference/math/clamp.md +++ b/docs/reference/math/clamp.md @@ -24,7 +24,9 @@ function clamp(value: number, minimum: number, maximum: number): number; ## Examples -```typescript +```typescript twoslash +import { clamp } from 'js-utils-es/math'; + const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5 const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15 const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5 diff --git a/docs/reference/math/inRange.md b/docs/reference/math/inRange.md index bfbd12b..60256ee 100644 --- a/docs/reference/math/inRange.md +++ b/docs/reference/math/inRange.md @@ -25,7 +25,9 @@ Throws an error if the `minimum` is greater or equal than the `maximum`. ## Examples -```typescript +```typescript twoslash +import { inRange } from 'js-utils-es/math'; + const result1 = inRange(3, 5); // result1 will be true. const result2 = inRange(1, 2, 5); // result2 will be false. const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown. diff --git a/docs/reference/math/mean.md b/docs/reference/math/mean.md index a8dd844..78cb318 100644 --- a/docs/reference/math/mean.md +++ b/docs/reference/math/mean.md @@ -20,7 +20,9 @@ function mean(nums: number[]): number; ## Examples -```typescript +```typescript twoslash +import { mean } from 'js-utils-es/math'; + const numbers = [1, 2, 3, 4, 5]; const result = mean(numbers); // result will be 3 diff --git a/docs/reference/math/random.md b/docs/reference/math/random.md index d59a65d..a07d067 100644 --- a/docs/reference/math/random.md +++ b/docs/reference/math/random.md @@ -22,7 +22,9 @@ function random(minimum: number, maximum: number): number; ## Examples -```typescript +```typescript twoslash +import { random } from 'js-utils-es/math'; + const result1 = random(0, 5); // Returns a random number between 0 and 5. const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown. diff --git a/docs/reference/math/randomInt.md b/docs/reference/math/randomInt.md index 19fa6e2..705f846 100644 --- a/docs/reference/math/randomInt.md +++ b/docs/reference/math/randomInt.md @@ -22,7 +22,9 @@ function randomInt(minimum: number, maximum: number): number; ## Examples -```typescript +```typescript twoslash +import { randomInt } from 'js-utils-es/math'; + const result1 = randomInt(0, 5); // Returns a random integer between 0 and 5. const result2 = randomInt(5, 0); // If the minimum is greater than the maximum, an error is thrown const result3 = randomInt(5, 5); // If the minimum is equal to the maximum, an error is thrown. diff --git a/docs/reference/math/range.md b/docs/reference/math/range.md index 2e620bf..f30ab82 100644 --- a/docs/reference/math/range.md +++ b/docs/reference/math/range.md @@ -24,7 +24,9 @@ function range(start: number, end: number, step: number): number[]; ## Examples -```typescript +```typescript twoslash +import { range } from 'js-utils-es/math'; + // Returns [0, 1, 2, 3] range(4); diff --git a/docs/reference/math/round.md b/docs/reference/math/round.md index 5225b04..1b7e48f 100644 --- a/docs/reference/math/round.md +++ b/docs/reference/math/round.md @@ -22,7 +22,9 @@ function round(value: number, precision?: number): number; ## Examples -```typescript +```typescript twoslash +import { round } from 'js-utils-es/math'; + const result1 = round(1.2345); // result1 will be 1 const result2 = round(1.2345, 2); // result2 will be 1.23 const result3 = round(1.2345, 3); // result3 will be 1.235 diff --git a/docs/reference/math/sum.md b/docs/reference/math/sum.md index 5ed8958..7ec3574 100644 --- a/docs/reference/math/sum.md +++ b/docs/reference/math/sum.md @@ -20,7 +20,9 @@ function sum(nums: number[]): number; ## Examples -```typescript +```typescript twoslash +import { sum } from 'js-utils-es/math'; + const numbers = [1, 2, 3, 4, 5]; const result = sum(numbers); // result will be 15 diff --git a/docs/reference/object/clone.md b/docs/reference/object/clone.md index dbdecc7..5673ce2 100644 --- a/docs/reference/object/clone.md +++ b/docs/reference/object/clone.md @@ -18,7 +18,9 @@ function clone(value: T): T; ## Examples -```typescript +```typescript twoslash +import { clone } from 'js-utils-es/object'; + const num = 29; const clonedNum = clone(num); console.log(clonedNum); // 29 diff --git a/docs/reference/object/invert.md b/docs/reference/object/invert.md index 217e79d..e416d69 100644 --- a/docs/reference/object/invert.md +++ b/docs/reference/object/invert.md @@ -22,7 +22,9 @@ function invert, K extends keyof T>(obj: T, keys: K[ ## Examples -```typescript +```typescript twoslash +import { omit } from 'js-utils-es/object'; + const obj = { a: 1, b: 2, c: 3 }; const result = omit(obj, ['b', 'c']); // result will be { a: 1 } diff --git a/docs/reference/object/pick.md b/docs/reference/object/pick.md index f5df542..2e70d21 100644 --- a/docs/reference/object/pick.md +++ b/docs/reference/object/pick.md @@ -22,7 +22,9 @@ function pick, K extends keyof T>(obj: T, keys: K[ ## Examples -```typescript +```typescript twoslash +import { pick } from 'js-utils-es/object'; + const obj = { a: 1, b: 2, c: 3 }; const result = pick(obj, ['a', 'c']); // result will be { a: 1, c: 3 } diff --git a/docs/reference/predicate/isEqual.md b/docs/reference/predicate/isEqual.md index 47ddd64..208c985 100644 --- a/docs/reference/predicate/isEqual.md +++ b/docs/reference/predicate/isEqual.md @@ -21,7 +21,9 @@ function isEqual(a: unknown, b: unknown): boolean; ### Example 1: Comparing Primitive Values -```javascript +```typescript twoslash +import { isEqual } from 'js-utils-es/predicate'; + isEqual(1, 1); // true isEqual('hello', 'hello'); // true isEqual(true, true); // true @@ -32,14 +34,18 @@ isEqual(true, false); // false ### Example 2: Comparing Special Cases -```javascript +```typescript twoslash +import { isEqual } from 'js-utils-es/predicate'; + isEqual(Number.NaN, Number.NaN); // true isEqual(+0, -0); // false ``` ### Example 3: Comparing Date Objects -```javascript +```typescript twoslash +import { isEqual } from 'js-utils-es/predicate'; + const date1 = new Date('2020-01-01'); const date2 = new Date('2020-01-01'); isEqual(date1, date2); // true @@ -50,7 +56,9 @@ isEqual(date1, date3); // false ### Example 4: Comparing RegExp Objects -```javascript +```typescript twoslash +import { isEqual } from 'js-utils-es/predicate'; + const regex1 = /hello/g; const regex2 = /hello/g; isEqual(regex1, regex2); // true @@ -61,7 +69,9 @@ isEqual(regex1, regex3); // false ### Example 5: Comparing Objects -```javascript +```typescript twoslash +import { isEqual } from 'js-utils-es/predicate'; + const obj1 = { a: 1, b: { c: 2 } }; const obj2 = { a: 1, b: { c: 2 } }; isEqual(obj1, obj2); // true @@ -76,7 +86,9 @@ isEqual(obj4, obj5); // false ### Example 6: Comparing Arrays -```javascript +```typescript twoslash +import { isEqual } from 'js-utils-es/predicate'; + const arr1 = [1, 2, 3]; const arr2 = [1, 2, 3]; isEqual(arr1, arr2); // true diff --git a/docs/reference/predicate/isNil.md b/docs/reference/predicate/isNil.md index a003059..4211989 100644 --- a/docs/reference/predicate/isNil.md +++ b/docs/reference/predicate/isNil.md @@ -15,7 +15,7 @@ function isNil(x: unknown): x is null | undefined; ## Examples -```typescript +```typescript twoslash import { isNil } from 'js-utils-es/predicate'; const value1 = null; diff --git a/docs/reference/predicate/isNotNil.md b/docs/reference/predicate/isNotNil.md index 7dbfaa3..03f0641 100644 --- a/docs/reference/predicate/isNotNil.md +++ b/docs/reference/predicate/isNotNil.md @@ -20,7 +20,9 @@ function isNotNil(x: T | null | undefined): x is T; ## Examples -```typescript +```typescript twoslash +import { isNotNil } from 'js-utils-es/predicate'; + // Here the type of `arr` is (number | undefined)[] const arr = [1, undefined, 3]; // Here the type of `result` is number[] diff --git a/docs/reference/predicate/isNull.md b/docs/reference/predicate/isNull.md index e8cde85..8ad6b02 100644 --- a/docs/reference/predicate/isNull.md +++ b/docs/reference/predicate/isNull.md @@ -23,7 +23,9 @@ function isNull(x: unknown): x is null; ## Examples -```typescript +```typescript twoslash +import { isNull } from 'js-utils-es/predicate'; + const value1 = null; const value2 = undefined; const value3 = 42; diff --git a/docs/reference/predicate/isUndefined.md b/docs/reference/predicate/isUndefined.md index 0aa1c09..ef1649a 100644 --- a/docs/reference/predicate/isUndefined.md +++ b/docs/reference/predicate/isUndefined.md @@ -23,7 +23,9 @@ function isUndefined(x: unknown): x is undefined; ## Examples -```typescript +```typescript twoslash +import { isUndefined } from 'js-utils-es/predicate'; + const value1 = undefined; const value2 = null; const value3 = 42; diff --git a/docs/reference/promise/delay.md b/docs/reference/promise/delay.md index a955d6d..b2e048d 100644 --- a/docs/reference/promise/delay.md +++ b/docs/reference/promise/delay.md @@ -26,7 +26,9 @@ function delay(ms: number, options?: DelayOptions): Promise; ### Basic Usage -```typescript +```typescript twoslash +import { delay } from 'js-utils-es/promise'; + async function foo() { console.log('Start'); await delay(1000); // Delays execution for 1 second @@ -38,7 +40,9 @@ foo(); ### Using with an AbortSignal -```typescript +```typescript twoslash +import { delay } from 'js-utils-es/promise'; + async function foo() { const controller = new AbortController(); const signal = controller.signal; diff --git a/docs/reference/string/camelCase.md b/docs/reference/string/camelCase.md index 28f3eb3..02d31b1 100644 --- a/docs/reference/string/camelCase.md +++ b/docs/reference/string/camelCase.md @@ -20,7 +20,7 @@ function camelCase(str: string): string; ## Examples -```typescript +```typescript twoslash import { camelCase } from 'js-utils-es/string'; camelCase('camelCase'); // returns 'camelCase' diff --git a/docs/reference/string/capitalize.md b/docs/reference/string/capitalize.md index f23d629..bd1cfbb 100644 --- a/docs/reference/string/capitalize.md +++ b/docs/reference/string/capitalize.md @@ -18,7 +18,7 @@ function capitalize(str: T): Capitalize; ## Examples -```typescript +```typescript twoslash import { capitalize } from 'js-utils-es/string'; capitalize('fred'); // returns 'Fred' diff --git a/docs/reference/string/kebabCase.md b/docs/reference/string/kebabCase.md index bbf072d..23b6c8d 100644 --- a/docs/reference/string/kebabCase.md +++ b/docs/reference/string/kebabCase.md @@ -20,7 +20,7 @@ function kebabCase(str: string): string; ## Examples -```typescript +```typescript twoslash import { kebabCase } from 'js-utils-es/string'; kebabCase('camelCase'); // returns 'camel-case' diff --git a/docs/reference/string/lowerCase.md b/docs/reference/string/lowerCase.md index 74302e0..5422c1e 100644 --- a/docs/reference/string/lowerCase.md +++ b/docs/reference/string/lowerCase.md @@ -20,7 +20,7 @@ function lowerCase(str: string): string; ## Examples -```typescript +```typescript twoslash import { lowerCase } from 'js-utils-es/string'; lowerCase('camelCase'); // returns 'camel case' diff --git a/docs/reference/string/snakeCase.md b/docs/reference/string/snakeCase.md index 9dd4491..5ba508b 100644 --- a/docs/reference/string/snakeCase.md +++ b/docs/reference/string/snakeCase.md @@ -20,7 +20,7 @@ function snakeCase(str: string): string; ## Examples -```typescript +```typescript twoslash import { snakeCase } from 'js-utils-es/string'; snakeCase('camelCase'); // returns 'camel_case' diff --git a/docs/vite.config.ts b/docs/vite.config.ts index 1586d6f..171da49 100644 --- a/docs/vite.config.ts +++ b/docs/vite.config.ts @@ -14,6 +14,7 @@ export default defineConfig({ VueJsx(), Unocss(), GitChangelog({ + maxGitLogCount: 2000, repoURL: () => githubLink, }), GitChangelogMarkdownSection(), diff --git a/package.json b/package.json index f5dc981..6b7ea41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-utils-es", - "version": "1.0.4", + "version": "1.0.5", "packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903", "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.", "license": "MIT", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 00a7b04..922d539 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,6 +54,9 @@ importers: docs: dependencies: + '@shikijs/transformers': + specifier: ^1.10.3 + version: 1.10.3 prettier: specifier: ^3.3.2 version: 3.3.3 @@ -68,7 +71,7 @@ importers: specifier: ^2.2.1 version: 2.2.2(@algolia/client-search@4.24.0)(@types/node@18.19.39)(postcss@8.4.39)(search-insights@2.15.0)(typescript@5.5.3) '@nolebase/vitepress-plugin-git-changelog': - specifier: ^2.2.1 + specifier: ^2.2.2 version: 2.2.2(@algolia/client-search@4.24.0)(@types/node@18.19.39)(postcss@8.4.39)(search-insights@2.15.0)(typescript@5.5.3) '@nolebase/vitepress-plugin-highlight-targeted-heading': specifier: ^2.2.1 diff --git a/src/array/chunk.ts b/src/array/chunk.ts index b4265f3..a5ad48c 100644 --- a/src/array/chunk.ts +++ b/src/array/chunk.ts @@ -12,14 +12,18 @@ * @throws {Error} Throws an error if `size` is not a positive integer. * * @example + * ```javascript * // Splits an array of numbers into sub-arrays of length 2 * chunk([1, 2, 3, 4, 5], 2); * // Returns: [[1, 2], [3, 4], [5]] + * ``` * * @example + * ```javascript * // Splits an array of strings into sub-arrays of length 3 * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3); * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']] + * ``` */ export function chunk(arr: readonly T[], size: number): T[][] { if (!Number.isInteger(size) || size <= 0) { diff --git a/src/string/snakeCase.ts b/src/string/snakeCase.ts index e2e4bf3..e04f9ad 100644 --- a/src/string/snakeCase.ts +++ b/src/string/snakeCase.ts @@ -9,10 +9,12 @@ import { getWords } from './_internal/getWords.ts'; * @returns {string} - The converted string to snake case. * * @example + * ```javascript * const convertedStr1 = snakeCase('camelCase') // returns 'camel_case' * const convertedStr2 = snakeCase('some whitespace') // returns 'some_whitespace' * const convertedStr3 = snakeCase('hyphen-text') // returns 'hyphen_text' * const convertedStr4 = snakeCase('HTTPRequest') // returns 'http_request' + * ``` */ export function snakeCase(str: string): string {