feat: convert some helpers to typescript
This commit is contained in:
parent
ba9f69344a
commit
b5f867cc66
5 changed files with 11 additions and 6 deletions
|
@ -4,7 +4,7 @@
|
|||
* @param color
|
||||
* @returns {string}
|
||||
*/
|
||||
export const colorFromHex = color => {
|
||||
export function colorFromHex(color) {
|
||||
if (color.substring(0, 1) === '#') {
|
||||
color = color.substring(1, 7)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import {i18n} from '@/i18n'
|
||||
|
||||
export const getListTitle = (l) => {
|
||||
import ListModal from '@/modals/list'
|
||||
|
||||
export function getListTitle(l: ListModal) {
|
||||
if (l.id === -1) {
|
||||
return i18n.global.t('list.pseudo.favorites.title')
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* @param replace
|
||||
* @returns {*}
|
||||
*/
|
||||
export const replaceAll = (str, search, replace) => {
|
||||
export const replaceAll = (str: string, search: string, replace: string) => {
|
||||
const esc = search.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
|
||||
const reg = new RegExp(esc, 'ig')
|
||||
return str.replace(reg, replace)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import ListModel from '@/models/list'
|
||||
|
||||
const key = 'collapsedBuckets'
|
||||
|
||||
const getAllState = () => {
|
||||
|
@ -9,7 +11,7 @@ const getAllState = () => {
|
|||
return JSON.parse(saved)
|
||||
}
|
||||
|
||||
export const saveCollapsedBucketState = (listId, collapsedBuckets) => {
|
||||
export const saveCollapsedBucketState = (listId: ListModel['id'], collapsedBuckets) => {
|
||||
const state = getAllState()
|
||||
state[listId] = collapsedBuckets
|
||||
for (const bucketId in state[listId]) {
|
||||
|
@ -20,7 +22,7 @@ export const saveCollapsedBucketState = (listId, collapsedBuckets) => {
|
|||
localStorage.setItem(key, JSON.stringify(state))
|
||||
}
|
||||
|
||||
export const getCollapsedBucketState = listId => {
|
||||
export const getCollapsedBucketState = (listId : ListModel['id']) => {
|
||||
const state = getAllState()
|
||||
if (typeof state[listId] !== 'undefined') {
|
||||
return state[listId]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import ListModel from '@/models/list'
|
||||
|
||||
export function getSavedFilterIdFromListId(listId) {
|
||||
export function getSavedFilterIdFromListId(listId: ListModel['id']) {
|
||||
let filterId = listId * -1 - 1
|
||||
// FilterIds from listIds are always positive
|
||||
if (filterId < 0) {
|
||||
|
|
Loading…
Reference in a new issue