Skip to content

Commit

Permalink
Remove usage of assert.invariant
Browse files Browse the repository at this point in the history
This reduces dependencies when building for the browser target, since
the assert module is a Node.js dependency.
  • Loading branch information
eliandoran committed Jun 30, 2024
1 parent 4973436 commit 6981e32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ export function getClass(prototype: Record<string, any>) {
PhpClass.prototype = prototype
return PhpClass
}

/**
* Ensures that the given {@link value} is truthy, throws an {@link Error} otherwise.
* @param value the value to check to be truthy.
* @param message the message of the {@link Error} if the value is falsy.
*/
export function invariant(value: any, message?: string) {
if (!value) {
throw new Error(message)
}
}
3 changes: 1 addition & 2 deletions src/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import invariant from 'assert'
import { isInteger, getByteLength } from './helpers'
import { isInteger, getByteLength, invariant } from './helpers'

function getClassNamespace(item: any, scope: Record<string, any>) {
return (
Expand Down
3 changes: 1 addition & 2 deletions src/unserialize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import invariant from 'assert'
// eslint-disable-next-line import/no-cycle
import Parser from './parser'
import { isInteger, getClass, getIncompleteClass, __PHP_Incomplete_Class } from './helpers'
import { isInteger, getClass, getIncompleteClass, __PHP_Incomplete_Class, invariant } from './helpers'

export type Options = {
strict: boolean
Expand Down

0 comments on commit 6981e32

Please sign in to comment.