-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: is server side context type guard (#19)
* feat: is server side context type guard * update readme * Update README.md
- Loading branch information
1 parent
affda60
commit 04f5554
Showing
6 changed files
with
49 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import isServerSidePropsContext from './is-server-side-props-context'; | ||
|
||
it('returns true if there is a req and res', () => { | ||
expect(isServerSidePropsContext({ req: true, res: true } as any)).toBe(true); | ||
expect(isServerSidePropsContext({} as any)).toBe(false); | ||
}); |
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,14 @@ | ||
import { GetServerSidePropsContext, GetStaticPropsContext } from 'next'; | ||
|
||
function isServerSidePropsContext( | ||
context: GetServerSidePropsContext | GetStaticPropsContext | ||
): context is GetServerSidePropsContext { | ||
if (typeof context !== 'object' || !context) return false; | ||
|
||
return ( | ||
!!(context as GetServerSidePropsContext).req && | ||
!!(context as GetServerSidePropsContext).res | ||
); | ||
} | ||
|
||
export default isServerSidePropsContext; |