Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of assert.invariant #298

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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