Skip to content

Commit 2d1bd3f

Browse files
committedMay 23, 2020
feat: add options args to fm
1 parent 854bab6 commit 2d1bd3f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed
 

‎index.d.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ export interface FrontMatterResult<T> {
55
readonly frontmatter?: string
66
}
77

8+
export interface FrontMatterOptions {
9+
/**
10+
* Whether to use [safeload](https://github.com/nodeca/js-yaml#safeload-string---options-)
11+
* @default true
12+
*/
13+
allowUnsafe?: boolean
14+
}
15+
816
interface FM {
9-
<T>(file: string): FrontMatterResult<T>
17+
<T>(file: string, options?: FrontMatterOptions): FrontMatterResult<T>
1018
test(file: string): boolean
1119
}
1220

‎test/index.errors.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let nullBox: null;
1919
/* ===================== fm ===================== */
2020

2121
{
22-
// THROWS 1 arguments, but got 0.
22+
// THROWS Expected 1-2 arguments, but got 0.
2323
fm()
2424
}
2525

@@ -28,6 +28,11 @@ let nullBox: null;
2828
fm(null)
2929
}
3030

31+
{
32+
// THROWS 'string' is not assignable to type 'boolean | undefined'.
33+
fm(file, {allowUnsafe: 'yes'})
34+
}
35+
3136
{
3237

3338
// THROWS 'FrontMatterResult<unknown>' is not assignable to type 'null'.
@@ -69,7 +74,6 @@ let nullBox: null;
6974
}
7075

7176
{
72-
7377
// THROWS Type 'boolean' is not assignable to type 'null'.
7478
nullBox = fm.test(file)
7579
}

‎test/index.types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ This is some text about some stuff that happened sometime ago`;
2828
console.log(bodyBegin);
2929
console.log(frontmatter);
3030
}
31+
32+
{
33+
fm(file)
34+
}
35+
36+
{
37+
fm(file, {allowUnsafe: true})
38+
}
3139
}
3240

3341
{

0 commit comments

Comments
 (0)
Please sign in to comment.