get, set global values in any js env
import { setGlobal, getEnv } from '@polioan/global-js'
function toTest() {
return 333
}
if (getEnv('NODE_ENV') === 'test') {
setGlobal('toTest', toTest)
}
import { getEnv, getGlobal, setGlobal } from '@polioan/global-js'
import { PrismaClient } from '@prisma/client'
export const prisma: PrismaClient = getGlobal('prisma') ?? new PrismaClient({})
if (getEnv('NODE_ENV') !== 'production') {
setGlobal('prisma', prisma)
}
import { setGlobal } from '@polioan/global-js'
class Myjquery {}
setGlobal('$', new Myjquery())
import { setGlobal } from '@polioan/global-js'
if (typeof structuredClone === 'undefined') {
setGlobal('structuredClone', value => JSON.parse(JSON.stringify(value)))
}
import { setGlobal } from '@polioan/global-js'
declare global {
var calculate: (a: number, b: number) => number
}
setGlobal('calculate', (a: number, b: number) => a + b)
const test = calculate(2, 3) // will work
npm i @polioan/global-js
yarn add @polioan/global-js
<script src="https://unpkg.com/@polioan/global-js@2.0.1/dist/index.global.js"></script>
<script>
setGlobal('some', 'test')
</script>
import { setGlobal } from 'https://deno.land/x/global_js@2.0.1/src/index.ts'
setGlobal('some', 'test')