New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@produck/mold

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@produck/mold - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

11

package.json
{
"name": "@produck/mold",
"version": "0.0.3",
"version": "0.1.0",
"description": "For helping to create a final options from a defined specification.",

@@ -35,4 +35,6 @@ "keywords": [

"build": "rollup -c script/rollup.config.mjs",
"prepublishOnly": "npm run build",
"test": "mocha"
"lint": "eslint --fix **/*.mjs",
"test": "mocha \"**/*-spec.mjs\" -t 999999999 ",
"coverage": "c8 --reporter=lcov npm test",
"prepublishOnly": "npm run lint && npm test && npm run build"
},

@@ -44,6 +46,7 @@ "bugs": {

"c8": "^7.12.0",
"eslint": "^8.23.1",
"mocha": "^10.0.0",
"rollup": "^2.79.0"
},
"gitHead": "48c1b4d07ee3a663c57202ecd4a52429042bc430"
"gitHead": "5b6b545116b9a36107fa70de676bb13de6b3af5d"
}

@@ -1,84 +0,111 @@

# `mold`
# @produck/mold
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/produck/mold/Node.js%20CI)](https://github.com/produck/mold/actions/workflows/node.js.yml)
[![Coveralls](https://img.shields.io/coveralls/github/produck/mold)](https://coveralls.io/github/produck/mold)
[![npm (scoped)](https://img.shields.io/npm/v/@produck/mold)](https://www.npmjs.com/package/@produck/mold)
[![npm](https://img.shields.io/npm/dw/@produck/koa-forker)](https://www.npmjs.com/package/@produck/mold)
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg?style=flat-square)](https://lerna.js.org/)
[![NPM](https://img.shields.io/npm/l/@produck/mold)](https://opensource.org/licenses/MIT)
> TODO: description
A tool module for defining data type schemas to a normalize function. It has been published as a "Dual CommonJS/ES module [[1]](https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#dual-commonjses-module-packages)" package. It is very simple, flexible. There is also some default "Catcher" for helping to throw a "TypeError" with good readability messages. It can work in "node.js" and browsers.
## Usage
## Installation
```
$ npm install @produck/mold
```
## Examples
The "options" in fs.appendFile(path, data[, options], callback),
```js
import { S, C, P, Normalizer, Circular } from '@produck/mold';
/**
* S = Simplex { Object, Array, Tuple, Value }
* C = Compound { Not, And, Or, If }
* P = Preset { Constant, Enum, Null, NotNull, Instance, Number, String, ... }
*/
import { S, C, P, Normalizer } from '@produck/mold';
const Object = S.Object({
c: P.Constant(1),
a: S.Object({
b: P.String('foo'),
c: P.Boolean(true)
}),
l: S.Array(S.Object({
s: P.String('')
})),
d: S.Object({}),
e: P.OrNull(P.Symbol()),
route: Circular(schema => S.Object({
name: P.String(),
next: schema,
previous: schema
})),
D: P.Instance(Date),
point: S.Tuple([P.Number(0), P.Number(0), P.String('baz')]),
port: P.Port(80),
p: P.StringPattern(/[a-f0-9]+/)('9f'),
l: P.StringLength(5)('33333'),
m5: P.IntegerMultipleOf(5)(10)
const flags = [
'a', 'ax', 'a+', 'ax+', 'as', 'as+',
'r', 'r+', 'rs+',
'w', 'wx', 'w+', 'wx+'
];
const schema = S.Object({
encoding: P.OrNull(P.String('utf-8')),
mode: P.Integer(0o666),
flag: P.Enum(flags);
});
const normalize = Normalizer(Object);
const normalize = Normalizer(schema);
try {
const finalOptions = normalize({
c: 1,
route: {
name: 'a',
next: {
name: 'b',
previous: null,
next: {
}
},
previous: null
},
e: null,
D: new Date(),
point: [0],
});
normalize(); // ok
normalize({ encoding: 'utf-8' }); // ok
normalize({ encoding: 123 }); // throws
normalize({ flag: 'f' }); // throws
```
console.log(finalOptions);
} catch (error) {
console.log(error);
## Usage
### Creating a normalize() from schema
### Custom Simplex Value Schema
```js
import { Simplex } from '@produck/mold';
import net from 'node:net';
// A optional schema.
const IPv4 = Simplex.Value(net.isIPv4, 'IP string', () => '0.0.0.0');
// A required schmea
const IPv4 = Simplex.Value(net.isIPv4, 'IP string');
```
### Circular Schema
### Custom Proxy Schema
## API by Levels
### L0 - Manual Functions as Schemas
```js
const l0 = (_value, _empty) => {
// Some statement...
}
```
## Base
* Schema
### L1 - Simplex Schemas
```js
import { S, Simp, Simplex } from '@produck/mold';
## Native
* ObjectSchema
* ArraySchema
* TupleSchema
* ValueSchema
Simplex.Value();
Simplex.Object();
Simplex.Array();
Simplex.Tuple();
```
## Proxy
* CustomSchema
* CircularSchema
* NotSchema
* AndSchema
* OrSchema
* BranchSchema
### L2 - Compound Schemas
```js
import { C, Comp, Compound } from '@produck/mold';
## Preset
Compound.Not();
Compound.And();
Compound.Or();
Compound.If();
```
## Normalizer
### L3 - Special Proxy Schemas
```js
import { Circular, Custom } from '@produck/mold';
Circular();
Custom();
```
### L4 - Preset Schemas & Schema Providers
```js
import { P, Pre, Preset } from '@produck/mold';
Preset.Constant();
Preset.Enum();
Preset.Null;
Preset.NotNull;
Preset.Instance();
Preset.OrNull();
Preset.Number();
...
```
## License
[MIT](https://github.com/produck/mold/blob/main/LICENSE)

@@ -16,4 +16,6 @@ import { Schema } from './schema';

export namespace Catcher {
const Origin: () => {};
const Throw: () => {};
const Simple: () => {};
const Complete: () => {};
const Visual: () => {};
}

@@ -20,0 +22,0 @@

@@ -32,10 +32,6 @@ import { Schema } from './schema';

type NumberNativeSchema = NativeSchema<number>;
type Edge = number | [number];
export const Number: NumberNativeSchema;
export const NumberRange: (
edge?: [minValue?: number, maxValue?: number],
open?: [minOpen?: boolean, maxOpen?: boolean],
) => NumberNativeSchema;
export const NumberRange: (min?: Edge, max?: Edge) => NumberNativeSchema;
export const Integer: NumberNativeSchema;

@@ -42,0 +38,0 @@ export const IntegerMultipleOf: (base: number) => NumberNativeSchema;

@@ -18,20 +18,5 @@ type Validate<Type = any> = (any: Type) => boolean;

const PlainObjectLike: Validate<object>;
}
export namespace Number {
const RegExp: Validate<RegExp>;
const Error: Validate<Error>;
const Integer: Validate<number>;
const Infinity: Validate<number>;
const NaN: Validate<number>;
}
export namespace Object {
const RegExp: Validate<RegExp>;
const Date: Validate<Date>;
const Array: Validate<Array<any>>;
const Error: Validate<Error>;
const Map: Validate<Map<any, any>>;
const Set: Validate<Set<any>>;
const WeakMap: Validate<WeakMap<any, any>>;
const WeakSet: Validate<WeakSet<any>>;
const Promise: Validate<Promise<any>>;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc