-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50ece78
commit 01b119a
Showing
3 changed files
with
64 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,36 @@ | ||
import { positions } from '../index' | ||
import type { Script, Position } from '../index' | ||
|
||
export const hasErrors = (items: Script[]) => { | ||
const hasNoScripts = items.length === 0 | ||
const hasInvalidPositions = items.filter(item => !positions.includes(item.position)).length > 0 | ||
const hasMissingContent = items.filter(item => !item.hasOwnProperty('content')).length > 0 | ||
export const hasErrors = (scripts: Script[]): Boolean => { | ||
const hasNoScripts = scripts.length === 0 | ||
const hasInvalidPositions = scripts.filter(script => !positions.includes(script.position)).length > 0 | ||
const hasMissingContent = scripts.filter(script => !script.hasOwnProperty('content')).length > 0 | ||
|
||
return hasNoScripts || hasInvalidPositions || hasMissingContent | ||
} | ||
|
||
export const filterByPosition = (items: Script[], position: Position) => { | ||
return items.filter(item => item.position === position) | ||
export const filterByPosition = (scripts: Script[], position: Position): Script[] => { | ||
return scripts.filter(script => script.position === position) | ||
} | ||
|
||
export const sortScripts = (scripts: Script[]): Script[] => { | ||
return scripts.sort((first, second) => { | ||
if (!first.sort) { | ||
first.sort = 0 | ||
} | ||
|
||
if (!second.sort) { | ||
second.sort = 0 | ||
} | ||
|
||
if (first.sort < second.sort) { | ||
return -1 | ||
} | ||
|
||
if (first.sort > second.sort) { | ||
return 1 | ||
} | ||
|
||
return 0 | ||
}) | ||
} |