This repository was archived by the owner on Feb 22, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +61
-2
lines changed
Expand file tree Collapse file tree 6 files changed +61
-2
lines changed Original file line number Diff line number Diff line change 1- const unm : string = '1'
1+ import * as Check from './utils/check'
2+ import { LoaderOptions } from './types'
23
3- console . log ( unm )
4+ export class BackLoader {
5+
6+ constructor ( ops : LoaderOptions ) {
7+ Check . options ( ops )
8+ }
9+
10+
11+ }
Original file line number Diff line number Diff line change 1+
2+ export type LoaderOptions = {
3+ pages : string [ ]
4+ scripts : string [ ]
5+ }
6+
Original file line number Diff line number Diff line change 1+ import * as Log from './log'
2+ import { LoaderOptions } from '../types'
3+
4+ const regs = {
5+ page : / ^ h t t p | ^ \/ \/ / ,
6+ js : / ( ^ h t t p | ^ \/ \/ ) \S + \. j s $ / ,
7+ }
8+
9+ export const pages = ( pages : string [ ] ) : boolean => {
10+ if ( ! Array . isArray ( pages ) ) return Log . options . pagesError ( )
11+ const unnormalLinks = pages . filter ( page => ! regs . page . test ( page ) )
12+ if ( unnormalLinks && unnormalLinks . length ) return Log . options . pagesError ( )
13+ return true
14+ }
15+
16+ export const scripts = ( scripts : string [ ] ) : boolean => {
17+ if ( ! Array . isArray ( scripts ) ) return Log . options . scriptsError ( )
18+ const unnormalLinks = scripts . filter ( s => ! regs . js . test ( s ) )
19+ if ( unnormalLinks && unnormalLinks . length ) return Log . options . scriptsError ( )
20+ return true
21+ }
22+
23+
24+ export const options = ( ops : LoaderOptions ) : boolean => {
25+ const checkResults : boolean [ ] = [ ]
26+ ops . pages && checkResults . push ( pages ( ops . pages ) )
27+ ops . scripts && checkResults . push ( scripts ( ops . scripts ) )
28+
29+ if ( ! checkResults . length ) return Log . options . isEmpty ( )
30+ return ! `${ checkResults } ` . includes ( 'false' )
31+ }
32+
Original file line number Diff line number Diff line change 1+
2+
Original file line number Diff line number Diff line change 1+
2+ export const warning = ( msg : string ) => {
3+ console . warn ( `BackLoader: ${ msg } ` )
4+ return false
5+ }
6+
7+ export const options = {
8+ pagesError : ( ) => warning ( 'options [pages] error.' ) ,
9+ scriptsError : ( ) => warning ( 'options [scripts] error.' ) ,
10+ isEmpty : ( ) => warning ( 'options is empty!' ) ,
11+ }
You can’t perform that action at this time.
0 commit comments