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

typeid-js

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeid-js - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

42

dist/index.js

@@ -714,5 +714,10 @@ "use strict";

code = str.charCodeAt(i);
if (!(code > 96 && code < 123)) {
const isLowerAtoZ = code > 96 && code < 123;
const isUnderscore = code === 95;
if ((i === 0 || i === len - 1) && !isLowerAtoZ) {
return false;
}
if (!(isLowerAtoZ || isUnderscore)) {
return false;
}
}

@@ -725,3 +730,3 @@ return true;

if (!isValidPrefix(prefix)) {
throw new Error("Invalid prefix. Must be at most 63 ascii letters [a-z]");
throw new Error("Invalid prefix. Must be at most 63 ascii letters [a-z_]");
}

@@ -753,7 +758,12 @@ let finalSuffix;

function fromString(typeId, prefix) {
const parts = typeId.split("_");
if (parts.length === 1) {
return typeidUnboxed("", parts[0]);
} else if (parts.length === 2) {
if (parts[0] === "") {
let p;
let s;
const underscoreIndex = typeId.lastIndexOf("_");
if (underscoreIndex === -1) {
p = "";
s = typeId;
} else {
p = typeId.substring(0, underscoreIndex);
s = typeId.substring(underscoreIndex + 1);
if (!p) {
throw new Error(

@@ -763,11 +773,9 @@ `Invalid TypeId. Prefix cannot be empty when there's a separator: ${typeId}`

}
if (prefix && parts[0] !== prefix) {
throw new Error(
`Invalid TypeId. Prefix mismatch. Expected ${prefix}, got ${parts[0]}`
);
}
return typeidUnboxed(parts[0], parts[1]);
} else {
throw new Error(`Invalid TypeId format: ${typeId}`);
}
if (prefix && p !== prefix) {
throw new Error(
`Invalid TypeId. Prefix mismatch. Expected ${prefix}, got ${p}`
);
}
return typeidUnboxed(p, s);
}

@@ -778,3 +786,3 @@ function parseTypeId(typeId) {

function getType(typeId) {
const underscoreIndex = typeId.indexOf("_");
const underscoreIndex = typeId.lastIndexOf("_");
if (underscoreIndex === -1) {

@@ -786,3 +794,3 @@ return "";

function getSuffix(typeId) {
const underscoreIndex = typeId.indexOf("_");
const underscoreIndex = typeId.lastIndexOf("_");
if (underscoreIndex === -1) {

@@ -789,0 +797,0 @@ return typeId;

{
"name": "typeid-js",
"version": "0.6.0",
"version": "0.7.0",
"description": "Official implementation of the TypeID specification in TypeScript. TypeIDs are type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs",

@@ -38,3 +38,3 @@ "keywords": [

"fmt": "pnpm lint --fix",
"lint": "prettier --write .",
"lint": "prettier '(src|test)/**/*.ts' --write",
"test": "jest"

@@ -41,0 +41,0 @@ },

@@ -36,2 +36,4 @@ # Official TypeID-JS Package

Note: this package requires Typescript > 5.0.0
# Usage

@@ -38,0 +40,0 @@

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