generated from hemengke1997/ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
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
567d6da
commit c402676
Showing
10 changed files
with
83 additions
and
26 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 was deleted.
Oops, something went wrong.
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,3 +1,9 @@ | ||
import NotFound from '@/components/not-found' | ||
import { useEffect } from 'react' | ||
|
||
export default NotFound | ||
export default function NotFound() { | ||
useEffect(() => { | ||
console.log('not found') | ||
}, []) | ||
|
||
return null | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,4 +1,4 @@ | ||
import createDebug from 'debug' | ||
import { PKGNAME } from './constant' | ||
import { I18nAlly } from './constant' | ||
|
||
export const debug = createDebug(PKGNAME) | ||
export const debug = createDebug(I18nAlly) |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { get, isObject, set } from 'lodash-es' | ||
|
||
export const ROOT_KEY = '__i18n_ally_root__' | ||
|
||
export function flatten(data: any) { | ||
const output: any = {} | ||
|
||
function step(obj: any, prev?: string) { | ||
Object.keys(obj).forEach((key) => { | ||
const value = obj[key] | ||
const isarray = Array.isArray(value) | ||
const type = Object.prototype.toString.call(value) | ||
const isobject = type === '[object Object]' || type === '[object Array]' | ||
|
||
const newKey = key === ROOT_KEY ? prev || '' : prev ? `${prev}.${key}` : key | ||
|
||
if (!isarray && isobject && Object.keys(value).length) return step(value, newKey) | ||
|
||
output[newKey] = value | ||
}) | ||
} | ||
|
||
step(data) | ||
|
||
return output | ||
} | ||
|
||
export function unflatten(data: any) { | ||
const output: any = {} | ||
|
||
Object.keys(data || {}) | ||
.sort((a, b) => b.length - a.length) | ||
.forEach((key) => { | ||
const original = key ? get(output, key) : output | ||
|
||
if (isObject(original)) set(output, key ? `${key}.${ROOT_KEY}` : ROOT_KEY, data[key]) | ||
else if (original === undefined) set(output, key, data[key]) | ||
else throw new Error(`Duplicated key ${key} found`) | ||
}) | ||
|
||
return output | ||
} |