File tree Expand file tree Collapse file tree 2 files changed +22
-26
lines changed Expand file tree Collapse file tree 2 files changed +22
-26
lines changed Original file line number Diff line number Diff line change 1
1
import type { Denops } from "https://deno.land/x/denops_core@v5.0.0/mod.ts" ;
2
+ import { maybe } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts#^" ;
2
3
import * as autocmd from "../autocmd/mod.ts" ;
3
4
import * as batch from "../batch/mod.ts" ;
4
5
import * as fn from "../function/mod.ts" ;
@@ -7,7 +8,7 @@ import { execute } from "../helper/mod.ts";
7
8
import {
8
9
FileFormat ,
9
10
findFileFormat ,
10
- maybeFileFormat ,
11
+ isFileFormat ,
11
12
splitText ,
12
13
} from "./fileformat.ts" ;
13
14
import { tryDecode } from "./fileencoding.ts" ;
@@ -284,7 +285,7 @@ export async function decode(
284
285
} else {
285
286
[ enc , text ] = tryDecode ( data , fileencodings ) ;
286
287
}
287
- const ff = maybeFileFormat ( options . fileformat ) ??
288
+ const ff = maybe ( options . fileformat , isFileFormat ) ??
288
289
findFileFormat ( text , fileformats ) ?? fileformat ;
289
290
return {
290
291
content : splitText ( text , ff ) ,
Original file line number Diff line number Diff line change 1
- import { is } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts#^" ;
1
+ import {
2
+ assert ,
3
+ ensure ,
4
+ is ,
5
+ maybe ,
6
+ PredicateType ,
7
+ } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts#^" ;
2
8
3
- export type FileFormat = "unix" | "dos" | "mac" ;
9
+ export const isFileFormat = is . LiteralOneOf ( [ "unix" , "dos" , "mac" ] as const ) ;
10
+
11
+ export type FileFormat = PredicateType < typeof isFileFormat > ;
12
+
13
+ export const assertFileFormat = ( v : unknown ) : asserts v is FileFormat =>
14
+ assert ( v , isFileFormat ) ;
15
+
16
+ export const ensureFileFormat = ( v : unknown ) : FileFormat =>
17
+ ensure ( v , isFileFormat ) ;
18
+
19
+ export const maybeFileFormat = ( v : unknown ) : FileFormat | undefined =>
20
+ maybe ( v , isFileFormat ) ;
4
21
5
22
const fileFormatDelimiters = {
6
23
unix : "\n" ,
7
24
dos : "\r\n" ,
8
25
mac : "\r" ,
9
26
} ;
10
27
11
- export function isFileFormat ( v : unknown ) : v is FileFormat {
12
- return is . String ( v ) && v in fileFormatDelimiters ;
13
- }
14
-
15
- export function assertFileFormat ( v : unknown ) : asserts v is FileFormat {
16
- if ( ! isFileFormat ( v ) ) {
17
- throw new Error ( `Unknown fileformat '${ v } ' is specified` ) ;
18
- }
19
- }
20
-
21
- export function ensureFileFormat ( v : unknown ) : FileFormat {
22
- assertFileFormat ( v ) ;
23
- return v ;
24
- }
25
-
26
- export function maybeFileFormat ( v : unknown ) : FileFormat | undefined {
27
- if ( isFileFormat ( v ) ) {
28
- return v ;
29
- }
30
- return undefined ;
31
- }
32
-
33
28
/**
34
29
* Split text as Text File in POSIX.
35
30
*/
You can’t perform that action at this time.
0 commit comments