Skip to content

Commit e1c3e29

Browse files
display message for deprecated functions in docs
1 parent dfd2d26 commit e1c3e29

File tree

7 files changed

+33
-19
lines changed

7 files changed

+33
-19
lines changed

package/src/array/difference.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import type { ArrayMinLength } from "@type/ArrayMinLength.js";
44
import { fastArrayFlat } from "@helpers/fastArrayFlat.js";
55

66
/**
7-
* @deprecated **Deprecated: Use the native [Set.prototype.difference()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference) function instead.**
8-
*
97
* Create a new array with values from the first array that are not present in the other arrays.
108
* Optionally, use a compare function to determine the comparison of elements (default is `===`).
119
*
10+
* @deprecated
11+
* **Deprecated: Use the native [Set.prototype.difference()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference) function instead.**
1212
*
1313
* @example
1414
* difference([2, 1], [2, 3], [6])
@@ -25,12 +25,12 @@ import { fastArrayFlat } from "@helpers/fastArrayFlat.js";
2525
*
2626
* difference(arr1, arr2, (a, b) => a.id === b.id)
2727
* // => [{ id: 1, name: 'Yeet' }]
28+
*
2829
* @param arraysOrCompareFn Two or more arrays with an optional compare function at the end
2930
* @template TElem The type of the array elements
3031
* @template TArrays The type of the arrays provided
3132
* @returns Returns a new array of filtered values
3233
*/
33-
3434
export function difference<TElem>(...arraysOrCompareFn: ArrayMinLength<TElem[], 2>): TElem[];
3535
export function difference<TArrays extends ArrayMinLength<unknown[], 2>>(...arraysOrCompareFn: [...TArrays, CompareFunction<TArrays>]): TArrays[0];
3636
export function difference<TArrays extends ArrayMinLength<unknown[], 2>, TElem>(...arraysOrCompareFn: ArrayMinLength<TElem[], 2> | [...TArrays, CompareFunction<TArrays>]): TArrays[0] {
@@ -54,4 +54,4 @@ export function difference<TArrays extends ArrayMinLength<unknown[], 2>, TElem>(
5454
}
5555

5656
return difference;
57-
}
57+
}

package/src/array/group.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Creates an object with grouped items in the array.
3-
* @deprecated Use the javascript "Object.groupBy()" version instead.
3+
*
4+
* @deprecated
5+
* **Deprecated: Use the native "Object.groupBy()" function instead.**
46
*
57
* @example
68
* group([6.1, 4.2, 6.3], Math.floor)

package/src/array/intersection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import { fastArrayFlat } from "@helpers/fastArrayFlat.js";
66
import { unique } from "./unique.js";
77

88
/**
9-
* @deprecated **Deprecated: Use the native [Set.prototype.intersection()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection) function instead.**
10-
*
119
* Create an array with unique values that are present in all arrays.
1210
* The order of the values is based on the first array.
1311
*
1412
* Optionally, use a compare function for element comparison (default is `===`).
1513
*
14+
* @deprecated
15+
* **Deprecated: Use the native [Set.prototype.intersection()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection) function instead.**
16+
*
1617
* @example
1718
* intersection([2, 1], [2, 3], [6, 2])
1819
* // => [2]

package/src/validate/isUrl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Checks if given string is a valid URL
3-
* @deprecated Use the native "URL.canParse" method instead.
3+
*
4+
* @deprecated
5+
* **Deprecated: Use the native "URL.canParse" method instead.**
46
*
57
* @example
68
* isUrl('https://google.com')

website/src/components/Meta.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts">
22
import { MetaTags } from "svelte-meta-tags";
33
4-
5-
import { page } from "$app/stores";
64
import icon from "$assets/moderndashIcon.svg?url";
75
import logo from "$assets/moderndashLogo.svg?url";
86
7+
import { page } from "$app/stores";
8+
99
export let title = "";
1010
export let description = "ModernDash is a modern and lightweight alternative to utility libraries like Lodash. It provides important functions while encouraging use of native JS where possible.";
1111

website/src/routes/docs/[method]/+page.server.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { unique } from "moderndash";
55
import { docData } from "$utils/docData.js";
66
import { markdownParser } from "$utils/markdown.js";
77

8-
export const load: PageServerLoad = (({ params }) => {
8+
export const load: PageServerLoad = (async ({ params }) => {
99
const methodName = params.method;
1010

1111
const methodDoc = docData.functions.find(func => func.name.toLowerCase() === methodName.toLowerCase());
@@ -14,27 +14,30 @@ export const load: PageServerLoad = (({ params }) => {
1414

1515
const signature = methodDoc?.signatures[0] ?? typeDoc ?? classDoc;
1616
const fileSource = methodDoc?.source ?? typeDoc?.source ?? classDoc?.source;
17+
const deprecated = signature?.comment.blockTags.find(tag => tag.name === "deprecated")?.text;
1718

1819
if (!signature) return { status: 404 };
1920

2021
const codeMarkdown = signature.comment.blockTags.find(tag => tag.name === "example")?.text;
2122
const code = getEmbedCode(signature.name, codeMarkdown);
2223

2324
const description = signature.comment.description ?? "No description";
24-
const parsedMarkdown = markdownParser(description).replace(/{@link ([^}]+)}/g, '<a href="/docs/$1">$1</a>');
25+
let [parsedDescription, parsedDeprecated] = await Promise.all([markdownParser(description), markdownParser(deprecated ?? "")]);
26+
parsedDescription = parsedDescription.replaceAll(/{@link ([^}]+)}/g, '<a href="/docs/$1">$1</a>');
2527

2628
return {
2729
name: methodDoc?.name ?? typeDoc?.name ?? classDoc?.name,
2830
description,
31+
parsedDeprecated,
2932
code,
30-
parsedMarkdown,
33+
parsedDescription,
3134
path: fileSource && (fileSource.path + "/" + fileSource.file)
3235
};
3336
});
3437

35-
function getEmbedCode(functionName: string, codetext: string | undefined) {
36-
if (!codetext) return "";
37-
let code = codetext.replace(/```(ts|typescript)\n/, "").replace("```", "");
38+
function getEmbedCode(functionName: string, codeText: string | undefined) {
39+
if (!codeText) return "";
40+
let code = codeText.replace(/```(ts|typescript)\n/, "").replace("```", "");
3841

3942
// Deals with Top Level Await Bug in Stackblitz
4043
if (code.includes("await")) {
@@ -46,7 +49,7 @@ function getEmbedCode(functionName: string, codetext: string | undefined) {
4649

4750

4851
function generateImportString(functionName: string, code: string) {
49-
const codeWithOutComments = code.replace(/\/\*[\S\s]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, "");
52+
const codeWithOutComments = code.replaceAll(/\/\*[\S\s]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, "");
5053
const foundFunctionNames = codeWithOutComments.match(
5154
new RegExp(`(?<!\\.)\\b(${docData.functions.map(func => func.name).join("|")})\\b`, "g")
5255
);

website/src/routes/docs/[method]/+page.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@
1010
$: name = data.name;
1111
$: description = data.description;
1212
$: code = data.code;
13-
$: parsedMarkdown = data.parsedMarkdown;
13+
$: parsedDescription = data.parsedDescription;
1414
$: path = data.path;
15+
$: parsedDeprecated = data.parsedDeprecated;
1516
</script>
1617

1718
<Meta title={name} {description}/>
1819

1920
{#if name}
2021
<h2>{name}</h2>
21-
{@html parsedMarkdown}
2222

23+
{#if parsedDeprecated}
24+
{@html parsedDeprecated}
25+
{/if}
26+
27+
{@html parsedDescription}
28+
2329
{#if code}
2430
<h3>Example</h3>
2531
<Playground {code}/>

0 commit comments

Comments
 (0)