
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
type-assurer
Advanced tools
TypeScript library that provides shorthand type assertions and type guard functions for multiple types.
type-assurer
is a TypeScript-first type checking library, providing compatibility with lodash's type guard functions while ensuring type safety. Designed with ESModules in mind, it allows for tree-shaking to minimize bundle sizes.
npm install type-assurer
The library provides 8 utility functions for each type guard, such as isString
, isNull
, etc.
And, note that fallbackNotNil
can be replaced with the ??
operator. Functions that can be simplified using standard JavaScript expressions, like this example, are not targeted for implementation.
Functions such as is
simply provide type guards that can be used in conditional branches.
import { isString } from 'type-assurer'
declare const value: unknown
if (isString(value)) {
console.log(`This is a string: ${value}`)
} else {
console.log('This is not a string')
}
Functions such as isNot
are useful in cases that require a type guard function as an argument, such as Array.prototype.filter.
import { isNotNil } from 'type-assurer'
declare const values: string | null
const result = values.filter(isNotNil)
// ^? string[]
Functions with names like assert
assertNot
are type assertion functions.
If the type check does not pass, it throws a TypeError.
The second argument can contain an error message.
import { assertString } from 'type-assurer'
declare const value: unknown
assertString(value, 'Value must be a string')
// No error if value is a string, otherwise throws an error with the message "Value must be a string"
Functions with names like ensure
ensureNot
are type assertion functions, but return the same value if the type check passes.
It is convenient to write type assertions on a single line.
The second argument can contain an error message.
import { ensureString } from 'type-assurer'
declare function fetchData(): Promise<string | undefined>
const value = ensureString(await fetchData(), 'Value must be a string')
// ^? string
// No error if fetchData returns a string, otherwise throws an error with the message "Value must be a string"
Functions like fallback
fallbackNot
are type modification functions.
They return the same value if the type check passes, otherwise they return the fallback value specified in the second argument.
import { fallbackString } from 'type-assurer'
declare function fetchData(): Promise<string | undefined>
const value = fallbackString(await fetchData(), 'default')
// ^? string
// Returns value if it's a string, otherwise returns the fallbackValue
Contributions are welcome! Please submit a pull request or open an issue to discuss any proposed changes or feature requests.
FAQs
TypeScript library that provides shorthand type assertions and type guard functions for multiple types.
We found that type-assurer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.