Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Abstract structure for JavaScript data validation
Abstruct(not abstract!) provides features for defining data structures. It used for any operation. For example, validation.
Define the data structure and validate.
import {
and,
assert,
maxCount,
pattern,
props,
string,
validDate,
} from "https://deno.land/x/abstruct@$VERSION/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
const Id = and(string, pattern(/^\d$/));
const Book = props({
id: Id,
title: maxCount(256).expect(`length should be less than or equal to 256`),
publishAt: validDate,
});
assertThrows(() =>
assert(Book, {
id: 0,
title: "Harry Potter and the Philosopher's Stone",
publishAt: new Date("1997/6/26"),
})
);
Validators do only one thing, so they can be combined to make new validator.
import {
and,
gte,
int,
lte,
validate,
} from "https://deno.land/x/abstruct@$VERSION/mod.ts";
const Int8 = and(
int,
gte(-127),
lte(128),
);
declare const input: number;
const result = validate(Int8, input);
if (result.isOk()) {
// result.value;
} else {
// result.value;
}
And narrowing works correctly.
import {
and,
assert,
gte,
instance,
lte,
validDate,
} from "https://deno.land/x/abstruct@$VERSION/mod.ts";
import { Assert, IsExact } from "https://deno.land/std/testing/types.ts";
const ValidDate = and(
instance(Date),
validDate,
gte(new Date("1970/1/1")),
lte(new Date("2038/1/19")),
);
const input: unknown = null;
assert(ValidDate, input);
type doTest = Assert<IsExact<typeof input, Date>, true>;
Fully customizable messages:
import { int8, string } from "https://deno.land/x/abstruct@$VERSION/mod.ts";
const Int8 = int8.expect("should be int8!!!");
const ID = string.expect(({ input }) =>
`id should be string, actual ${typeof input}`
);
Composable: All features are composable. Being composable brings the following features:
Library first: It can use in library. To fulfill this, special attention has been paid to the following:
Type first: Type safety is a matter of course.
You have very little to learn.
Few examples of common patterns:
Copyright © 2023-present Tomoki Miyauci.
Released under the MIT license
1.0.0-beta.12 (2023-06-02)
FAQs
Abstract structure for JavaScript data validation
The npm package abstruct receives a total of 0 weekly downloads. As such, abstruct popularity was classified as not popular.
We found that abstruct 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.