npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yaupon/id

v0.0.0-dev.1

Published

🆔 Unique Identifiers with focus on type-safety with nominal typings. Meta-package for various ID libraries.

Downloads

1

Readme

@yaupon/id

  • @yaupon/id is a library that provides a simple way to generate unique identifiers.
  • Application provides two exports @yaupon/id/safe and @yaupon/id/fast, with @yaupon/id/safe being the default export.
    • @yaupon/id/safe is a safe implementation of unique identifier generation, which is type-safe by default ( prefixing id with safe generation algorithm) and the fast export is using nanoid to provide a 32-character ID which is there to be used on infrastructure level.
  • There are ready-to-use presets of IDs and aliases to Node.js functions which ensures compatibility with the generic ID type from @yaupon/id library, to avoid type-casting everytime ID is generated outside library.

@yaupon/id are unique to the place used and are not compatible one with another.

class User {
    id: ID
}

class Post {
    id: ID
}

const user = new User()
const post = new Post()

console.log(user.id === post.id) // compilation error

I come down to this idea just because some retarded coworker was trolling me on codebase with functions that take userId which is later used at ORM as productId - no such things possible with this approach.

function updatePost(postId: Post['id']) {
    // ...
}

"But Jay, Post["id"] makes me import Post everywhere where I just want to use ID type!", you say?

Overall recommendation is to use import type { Post } from "post.ts" and use Post["id"] where needed, send approach is creating a new type alias for ID type in your project.

import type { ID } from '@yaupon/id'

type PostID = ID // Or PostID = Post['id']
function updatePost(postId: PostID) {
    // ...
}

However, I find it more readable to use Post["id"] in this case.

"Why I would use this library instead of nanoid or uuid?"'

  • We did not write this library to compete with nanoid or uuid, but to provide a type-safe way to generate unique identifiers.
  • nanoid and uuid are great libraries, but they do not protect against ID misuse.
  • @yaupon/id is a library that provides a simple way to generate unique identifiers, which are unique to the place used and are not compatible one with another.

"But xyz library does the same thing!"

They had bad marketing, tags, description or something else—at the time I was building library there was only typeid from Jetpack which would provide similar functionality, container this package as fork of typeid.

Integrations

  • [TODO] Ahead-of-time compilation/validation with typia and helper function such as isID to ensure that ID is valid.
  • [TODO] Integration with ORM libraries to ensure that ID is always valid and is not used in wrong context.