Skip to content

Commit

Permalink
Merge pull request #298 from eliandoran/feature/remove_invariant
Browse files Browse the repository at this point in the history
Remove usage of `assert.invariant`
  • Loading branch information
steelbrain authored Jul 1, 2024
2 parents 4973436 + 6981e32 commit fd2ac5b
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 fd2ac5b

Please sign in to comment.