Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

x-value

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

x-value - npm Package Compare versions

Comparing version 0.1.14 to 0.1.15

bld/library/cjs/x-utils/function.d.ts

2

bld/library/cjs/core/@type-issue.d.ts
export type TypePath = (string | number | symbol | {
key: string | number | symbol;
} | {
argument: number;
})[];

@@ -6,0 +4,0 @@ export interface TypeIssue {

@@ -15,3 +15,2 @@ export * from './medium';

export * from './recursive-type';
export * from './function-type';
export * from './json-schema';

@@ -18,4 +18,3 @@ "use strict";

tslib_1.__exportStar(require("./recursive-type"), exports);
tslib_1.__exportStar(require("./function-type"), exports);
tslib_1.__exportStar(require("./json-schema"), exports);
//# sourceMappingURL=index.js.map

@@ -191,5 +191,3 @@ "use strict";

.map(segment => `[${typeof segment === 'object'
? 'key' in segment
? `key:${JSON.stringify(segment.key)}`
: `args[${segment.argument}]`
? `key:${JSON.stringify(segment.key)}`
: JSON.stringify(segment)}]`)

@@ -196,0 +194,0 @@ .join('')} `

@@ -6,2 +6,2 @@ import type { Type, TypeInMediumsPartial, __type_in_mediums } from './core';

export declare function constraint(condition: boolean, message?: string | (() => string)): void;
export declare function refinement<T>(condition: boolean, refined: T, message?: string | (() => string)): T;
export declare function refinement<T>(condition: boolean, refined: T extends Function ? () => T : (() => T) | T, message?: string | (() => string)): T;

@@ -20,5 +20,5 @@ "use strict";

}
return refined;
return typeof refined === 'function' ? refined() : refined;
}
exports.refinement = refinement;
//# sourceMappingURL=utils.js.map
export * from './miscellaneous';
export * from './number';
export * from './string';
export * from './function';

@@ -7,2 +7,3 @@ "use strict";

tslib_1.__exportStar(require("./string"), exports);
tslib_1.__exportStar(require("./function"), exports);
//# sourceMappingURL=index.js.map

@@ -1,3 +0,2 @@

import type { NominalPartial, TypeInMediumsPartial, TypeOf, __nominal, __type } from '../core';
import { RefinedType } from '../core';
import type { NominalPartial, RefinedType, TypeInMediumsPartial, TypeOf, __nominal, __type } from '../core';
import { boolean, number, string, unknown } from '../types';

@@ -12,1 +11,2 @@ export type TransformNominal<TFrom, T> = TFrom extends NominalPartial ? T & Record<__type, T> & Record<__nominal, TFrom[__nominal]> : T;

export type UnknownRecord = TypeOf<typeof UnknownRecord>;
export declare function Promise<TType extends TypeInMediumsPartial>(Type: TType): RefinedType<typeof unknown, never, Promise<TypeOf<TType>>>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnknownRecord = exports.equal = exports.literal = void 0;
exports.Promise = exports.UnknownRecord = exports.equal = exports.literal = void 0;
const tslib_1 = require("tslib");

@@ -18,3 +18,3 @@ const lodash_isequal_1 = tslib_1.__importDefault(require("lodash.isequal"));

default:
throw new TypeError('Unsupported literal value');
throw new TypeError('Unsupported literal value.');
}

@@ -24,8 +24,10 @@ }

function equal(comparison, Type = types_1.unknown) {
return new core_1.RefinedType(Type, [
value => (0, utils_1.refinement)((0, lodash_isequal_1.default)(value, comparison), value),
]);
return Type.refined(value => (0, utils_1.refinement)((0, lodash_isequal_1.default)(value, comparison), value, 'Expected equal values.'));
}
exports.equal = equal;
exports.UnknownRecord = (0, core_1.record)(types_1.string, types_1.unknown);
function Promise(Type) {
return types_1.unknown.refined(value => (0, utils_1.refinement)(value instanceof globalThis.Promise, () => value.then(fulfilled => Type.satisfies(fulfilled)), 'Expected a Promise.'));
}
exports.Promise = Promise;
//# sourceMappingURL=miscellaneous.js.map

@@ -15,4 +15,3 @@ export * from './medium';

export * from './recursive-type';
export * from './function-type';
export * from './json-schema';
//# sourceMappingURL=index.js.map

@@ -187,5 +187,3 @@ import { ExactContext } from './@exact-context';

.map(segment => `[${typeof segment === 'object'
? 'key' in segment
? `key:${JSON.stringify(segment.key)}`
: `args[${segment.argument}]`
? `key:${JSON.stringify(segment.key)}`
: JSON.stringify(segment)}]`)

@@ -192,0 +190,0 @@ .join('')} `

@@ -16,4 +16,4 @@ export function constraint(condition, message) {

}
return refined;
return typeof refined === 'function' ? refined() : refined;
}
//# sourceMappingURL=utils.js.map
export * from './miscellaneous';
export * from './number';
export * from './string';
export * from './function';
//# sourceMappingURL=index.js.map
import isEqual from 'lodash.isequal';
import { RefinedType, record } from '../core';
import { record } from '../core';
import { boolean, number, string, unknown } from '../types';

@@ -14,11 +14,12 @@ import { refinement } from '../utils';

default:
throw new TypeError('Unsupported literal value');
throw new TypeError('Unsupported literal value.');
}
}
export function equal(comparison, Type = unknown) {
return new RefinedType(Type, [
value => refinement(isEqual(value, comparison), value),
]);
return Type.refined(value => refinement(isEqual(value, comparison), value, 'Expected equal values.'));
}
export const UnknownRecord = record(string, unknown);
export function Promise(Type) {
return unknown.refined(value => refinement(value instanceof globalThis.Promise, () => value.then(fulfilled => Type.satisfies(fulfilled)), 'Expected a Promise.'));
}
//# sourceMappingURL=miscellaneous.js.map
{
"name": "x-value",
"version": "0.1.14",
"version": "0.1.15",
"repository": "https://github.com/vilic/x-value.git",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -29,3 +29,2 @@ [![NPM version](https://img.shields.io/npm/v/x-value?color=%23cb3837&style=flat-square)](https://www.npmjs.com/package/x-value)

- [Recursive Type](#recursive-type)
- [Function Type](#function-type)
- [Refined Type](#refined-type)

@@ -314,20 +313,2 @@ - [Nominal Type](#nominal-type)

### Function Type
```ts
const FunctionType = x.function([x.string], x.number);
type FunctionType = x.TypeOf<typeof FunctionType>; // (arg_0: string) => number
```
It important to understand function type validates **neither** the function parameters **nor** the return value.
However, you may create guarded functions using function type:
```ts
const fn = FunctionType.guard(value => value.length);
```
> Please note that `x.Function` is not a function type, instead it's a pre-defined, non-generic atomic type that matches all functions.
### Refined Type

@@ -334,0 +315,0 @@

@@ -6,3 +6,2 @@ export type TypePath = (

| {key: string | number | symbol}
| {argument: number}
)[];

@@ -9,0 +8,0 @@

@@ -15,3 +15,2 @@ export * from './medium';

export * from './recursive-type';
export * from './function-type';
export * from './json-schema';

@@ -284,5 +284,3 @@ import type {Exact} from './@exact-context';

typeof segment === 'object'
? 'key' in segment
? `key:${JSON.stringify(segment.key)}`
: `args[${segment.argument}]`
? `key:${JSON.stringify(segment.key)}`
: JSON.stringify(segment)

@@ -289,0 +287,0 @@ }]`,

@@ -33,3 +33,3 @@ import type {Type, TypeInMediumsPartial, __type_in_mediums} from './core';

condition: boolean,
refined: T,
refined: T extends Function ? () => T : (() => T) | T,
message?: string | (() => string),

@@ -45,3 +45,3 @@ ): T {

return refined;
return typeof refined === 'function' ? refined() : refined;
}
export * from './miscellaneous';
export * from './number';
export * from './string';
export * from './function';

@@ -5,2 +5,4 @@ import isEqual from 'lodash.isequal';

NominalPartial,
RefinedType,
Type,
TypeInMediumsPartial,

@@ -11,3 +13,3 @@ TypeOf,

} from '../core';
import {RefinedType, record} from '../core';
import {record} from '../core';
import {boolean, number, string, unknown} from '../types';

@@ -67,3 +69,3 @@ import {refinement} from '../utils';

default:
throw new TypeError('Unsupported literal value');
throw new TypeError('Unsupported literal value.');
}

@@ -81,5 +83,5 @@ }

): RefinedType<TypeInMediumsPartial, never, unknown> {
return new RefinedType(Type, [
value => refinement(isEqual(value, comparison), value),
]);
return Type.refined(value =>
refinement(isEqual(value, comparison), value, 'Expected equal values.'),
);
}

@@ -90,1 +92,19 @@

export type UnknownRecord = TypeOf<typeof UnknownRecord>;
export function Promise<TType extends TypeInMediumsPartial>(
Type: TType,
): RefinedType<typeof unknown, never, Promise<TypeOf<TType>>>;
export function Promise(
Type: Type,
): RefinedType<TypeInMediumsPartial, never, Promise<unknown>> {
return unknown.refined(value =>
refinement(
value instanceof globalThis.Promise,
() =>
(value as Promise<unknown>).then(fulfilled =>
Type.satisfies(fulfilled),
),
'Expected a Promise.',
),
);
}

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