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

just-types

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-types - npm Package Compare versions

Comparing version 1.4.2 to 1.5.0

5

dist/index.d.ts

@@ -1,2 +0,5 @@

type StartsWith<Text extends string, Prefix extends string> = Text extends `${Prefix}${infer _}` ? true : false;
export type Is<T extends true> = T;
export type Not<T extends boolean> = true extends T ? false : true;
export type Equal<X, Y> = Exclude<X, Y> | Exclude<Y, X> extends never ? true : false;
export type StartsWith<Text extends string, Prefix extends string> = Text extends `${Prefix}${infer _}` ? true : false;
type IndexMinusOne = [

@@ -3,0 +6,0 @@ -1,

10

package.json

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "1.4.2",
"version": "1.5.0",
"repository": "webNeat/just-types",

@@ -24,7 +24,7 @@ "homepage": "https://github.com/webNeat/just-types#just-types",

"devDependencies": {
"@parcel/packager-ts": "^2.0.1",
"@parcel/transformer-typescript-types": "^2.0.1",
"parcel": "^2.0.1",
"typescript": "^4.5.2"
"@parcel/packager-ts": "2.7.0",
"@parcel/transformer-typescript-types": "2.7.0",
"parcel": "^2.7.0",
"typescript": "^4.8.2"
}
}

@@ -12,2 +12,3 @@ # Just types

- [Installation](#installation)
- [Testing Types](#)
- [List of Types](#list-of-types)

@@ -164,3 +165,29 @@ - [Decrement](#decrement)

# Testing Your Types with just-types
`just-types` allows you to test your own types using `Is`, `Equal` and other testing utils. These utils are used internally to test `just-types` types. For Example, here is the source file of the `Split` type:
```ts
import {Equal, Is} from './Test'
export type Split<
Text extends string,
Separator extends string
> = Text extends `${infer First}${Separator}${infer Rest}` ? [First, ...Split<Rest, Separator>] : [Text]
type Tests = [
Is<Equal<Split<'foo', '-'>, ['foo']>>,
Is<Equal<Split<'foo-bar-baz', '-'>, ['foo', 'bar', 'baz']>>,
Is<Equal<Split<'foo--', '-'>, ['foo', '', '']>>
]
```
As you see, we define the type, then we declare a `Tests` type (can be named anything) and assign a list of assertions types to it. These types are evaluated in realtime by Typescript, so we have instant feedback if something is wrong.
## List of assertions
- `Is<Equal<A, B>>`: asserts that types `A` and `B` are the same.
- `Is<Not<Equal<A, B>>>`: asserts that types `A` and `B` are different.
- `Is<StartsWith<A, B>>`, where `A` and `B` extend `string`: asserts that all elements of `A` start with with an element of `B`.
# Contributing

@@ -178,2 +205,6 @@

**1.5.0 (September 2nd 2022)**
- Export testing types: `Is`, `Not`, `Equal`, `StartsWith`
**1.4.2 (March 21th 2022)**

@@ -180,0 +211,0 @@

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