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

cdkey-js

v1.0.4

Published

Generator and parser for redemption codes for javascript

Downloads

44

Readme

cdk-js

English Version

为js准备的激活码生成器和解析器,支持 typescript

介绍

这个项目是一个激活码生成器和解析器。它可以根据自增id生成唯一的激活码,并将激活码解析回原始的自增id。这个项目适合需要在短时间内生成大量唯一码的应用。

入门指南

安装

你可以使用 npmpnpmyarn 命令来获取这个项目:

npm i cdkey-js

使用

在你的node.js项目,你可以这样使用这个项目:

import { Cdk, CdkI, GenerateRandomSecret } from "cdkey-js";
// 或者 
// const {Cdk, CdkI, GenerateRandomSecret} = require('cdkey-js/dist/cjs');

const ExampleCharTable: string[] = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'.split('');

// 实际使用中请提前生成一个秘钥表 不要在运行时生成
// GenerateRandomSecret(true); 会生成一个随机秘钥表并打印到控制台
// 然后你可以将秘钥表复制到你的代码中
const cdk: CdkI = new Cdk(GenerateRandomSecret(), ExampleCharTable);

export async function TestCdk() {
    const incrementID = 123456;
    try {
        const generatedCode = cdk.generate(incrementID);
        console.log('Generated Code:', generatedCode);

        const parsedID = cdk.parse(generatedCode);
        console.log('Parsed ID:', parsedID);

        const batchCodes = cdk.batchGenerate(incrementID, 5);
        console.log('Batch Generated Codes:', batchCodes);
    } catch (error) {
        console.error('Error:', error);
    }
}

在这个例子中,我们首先生成一个随机秘钥表,然后使用这个秘钥表和一个字符表创建一个新的 cdk 对象。 然后我们使用 generate 方法根据一个自增id生成一个激活码,并使用 parse 方法将激活码解析回原始的自增id。

性能

这个项目中的 Generater 是非常高效的。在基准测试中,它能够在大约 3 秒内生成 1,000,000 个激活码。这使得它适用于需要在短时间内生成大量唯一码的应用。

请注意,实际性能可能会因具体硬件和软件环境而异。