Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
cleaners
Advanced tools
Changelog
0.3.16 (2023-04-24)
Readme
Cleans & validates untrusted data, with TypeScript & Flow support
Do you ever read JSON data from the outside world? If you, you should probably clean & validate that data before you start using it. That can be a lot of work, so cleaners
is here to help with:
If features:
If you are using Deno, just import cleaners directly:
import { asString } from 'https://deno.land/x/cleaners/mod.ts'
If you are using Node, first install the package using npm i cleaners
or yarn add cleaners
, and then import it using either syntax:
// The oldschool way:
const { asString } = require('cleaners')
// Or using Node's new native module support:
import { asString } from 'cleaners'
See the documentation website for details, but here is a quick overview:
This library contains a collection of composable Cleaner
functions. A cleaner function validates some incoming data, and either returns it with the proper type or throws an exception. Here are some simple examples:
import { asDate, asString } from 'cleaners'
asString('hey') // Returns 'hey'
asString(1) // TypeError: Expected a string
asDate('2020-02-20') // Returns a JavaScript Date object
To handle objects, arrays, and other nested data types, this library includes some helpers for combining Cleaner
functions together:
import { asArray, asNumber, asObject, asOptional } from 'cleaners'
const asMessage = asObject({
message: asString,
title: asOptional(asString), // Optional string
recipients: asArray(asString), // Array of strings
replyCount: asOptional(asNumber, 0) // Number with default value
})
// Let's clean some network data:
try {
const response = await fetch('https://message-api')
const message = asMessage(await response.json())
} catch (error) {}
Thanks to our TypeScript & Flow support, the custom asMessage
function above has a detailed return type. The means you will get the same error-checking & auto-completion as if you had entered the following type declaration by hand:
interface Message {
text: string
title: string | undefined
recipients: string[]
replyCount: number
}
FAQs
Cleans & validates untrusted data, with TypeScript & Flow support
The npm package cleaners receives a total of 234 weekly downloads. As such, cleaners popularity was classified as not popular.
We found that cleaners demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.