fafbea8b74
This PR introduces [Edge Runtime](https://edge-runtime.vercel.app/) for emulating [Edge Functions](https://vercel.com/features/edge-functions) locally. Every time you run a [middleware](https://nextjs.org/docs/advanced-features/middleware) locally via `next dev`, an isolated edge runtime context will be created. These contexts have the same constraints as production servers, plus they don't pollute the global scope; Instead, all the code run in a vm on top of a Node.js process. Additionally, `@edge-runtime/jest-environment` has been added to make easier testing Edge Functions in a programmatic way. It dropped the following polyfills from Next.js codebase, since they are now part of Edge Runtime: - abort-controller - formdata - uuid - web-crypto - web-streams Co-authored-by: Gal Schlezinger <2054772+Schniz@users.noreply.github.com>
22 lines
674 B
TypeScript
22 lines
674 B
TypeScript
export function getObjectClassLabel(value: any): string {
|
|
return Object.prototype.toString.call(value)
|
|
}
|
|
|
|
export function isPlainObject(value: any): boolean {
|
|
if (getObjectClassLabel(value) !== '[object Object]') {
|
|
return false
|
|
}
|
|
|
|
const prototype = Object.getPrototypeOf(value)
|
|
|
|
/**
|
|
* this used to be previously:
|
|
*
|
|
* `return prototype === null || prototype === Object.prototype`
|
|
*
|
|
* but Edge Runtime expose Object from vm, being that kind of type-checking wrongly fail.
|
|
*
|
|
* It was changed to the current implementation since it's resilient to serialization.
|
|
*/
|
|
return prototype === null || prototype.hasOwnProperty('isPrototypeOf')
|
|
}
|