Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@recoiljs/refine
Advanced tools
A type-refinement / validator combinator library for mixed / unknown values in Flow or TypeScript
Refine is a type-refinement / validator combinator library for mixed / unknown values in Flow or TypeScript.
Refine is currently released as @recoiljs/refine on NPM.
Please see the Refine Documentation. To get started learning about Refine, check out the documentation on the core concepts of Utilities and Checkers.
unknown
TypeScript type or mixed
Flow type values and you need to assert those values have a specific static type.Coerce unknown types to a strongly typed variable. assertion()
will throw if the input doesn't match the expected type while coercion()
will return null
.
const myObjectChecker = object({
numberProperty: number(),
stringProperty: optional(string()),
arrayProperty: array(number()),
});
const myObjectAssertion = assertion(myObjectChecker);
const myObject: CheckerReturnType<myObjectChecker> = myObjectAssertion({
numberProperty: 123,
stringProperty: 'hello',
arrayProperty: [1, 2, 3],
});
Using match()
and asType()
you can upgrade from previous types to the latest version.
const myChecker: Checker<{str: string}> = match(
object({str: string()}),
asType(string(), str => ({str: str})),
asType(number(), num => ({str: String(num)})),
);
const obj1: {str: string} = coercion(myChecker({str: 'hello'}));
const obj2: {str: string} = coercion(myChecker('hello'));
const obj3: {str: string} = coercion(myChecker(123));
Refine wraps JSON
to provide a built-in strongly typed parser.
const myParser = jsonParser(array(object({num: number()})));
const result = myParser('[{"num": 1}, {"num": 2}]');
if (result != null) {
// we can now access values in num typesafe way
assert(result[0].num === 1);
} else {
// value failed to match parser spec
}
The Recoil Sync library leverages Refine for type refinement, input validation, and upgrading types for backward compatibility. See the recoil-sync
docs for more details.
Refine is currently bundled as part of the Recoil Sync package.
Development of Recoil happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving Recoil.
Recoil is MIT licensed.
FAQs
A type-refinement / validator combinator library for mixed / unknown values in Flow or TypeScript
The npm package @recoiljs/refine receives a total of 22,822 weekly downloads. As such, @recoiljs/refine popularity was classified as popular.
We found that @recoiljs/refine 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.