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

@kakasoo/proto-typescript

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kakasoo/proto-typescript

Utility types and implementations based on JavaScript prototypes.

  • 1.28.0
  • npm
  • Socket score

Version published
Weekly downloads
68
decreased by-11.69%
Maintainers
1
Weekly downloads
 
Created
Source

proto-typescript

Utility types and implementations based on JavaScript prototypes. I plan to share the features that are officially available from 2.0.0.

TypedClass

prototype methods

new TypedArray([1, 2, 3] as const).unshift(4 as const); // TypedArray<[4, 1, 2, 3]>
new TypedArray([1, 2, 3] as const).join(','); // TypedString<'1,2,3'>

The return result of 'TypeClass' returns one of the instances of TypeClass again. Therefore, those who know the grammar of JavaScript can use it immediately.

refined methods

/**
 * error case
 */
new TypedArray<'1-3'>([1, 2, 3]).refine([1, 2, 3] as const).join('-');
new TypedArray<'1-3'>([]).refine([1, 2, 3] as const).join('-');
new TypedArray<'1-3'>().refine([1, 2, 3, 4] as const).join('-');
new TypedArray<'1-3'>().refine([0, 1, 2, 3] as const).join('-');

/**
 * right case
 */
new TypedArray<'1-3'>().refine([2, 3] as const).join('-');

TypedArray, TypedNumber has the refine method, which serves to further narrow down the generic type received as a factor. This helps reduce developer mistakes, but it should be careful because it cannot guarantee actual runtime behavior.

In the future, improvements will be made at the type level.

toPrimitive method

new TypedString('abcdef').toPrimitive(); // 'abcdef'

You can change it to the primitive type of JavaScript.

const arr = [...new TypedArray([1, 2, 3, 4, 5] as const)]; // (1 | 2 | 3 | 4 | 5)[]

Iterable/Iterator is supported.

Keywords

FAQs

Package last updated on 10 Mar 2024

Did you know?

Socket

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.

Install

Related posts

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