@ggascoigne/namor

中文文档
2.0.4发布于 2022/02/27MITCommonJS零依赖近 30 天下载 7226

A domain-safe name generator

原始使用文档
文档目录7 节
  1. Getting Started
  2. Collision Stats
  3. API
  4. .generate (options:Object)
  5. .validate (name:String, options:Object)
  6. .rawData
  7. License




Build Status Coverage Status


A name generator for Node that generates random, url-friendly names. This comes in handy if you need to generate unique subdomains (like Heroku does), or unique names for anything else. It can check against a reserved word list to prevent malicious subdomains, and generate names of a rugged nature.

Please Note: Generated names are not always guaranteed to be unique. To reduce the chances of collision, you can increase the length of the trailing number (see here for collision stats). Always be sure to check your database before assuming a generated value is unique.

Getting Started

$ npm install namor --save
const namor = require("namor")

/* defaults to two words and 5 random characters */
const name = namor.generate()

/* generate 3 words and no random characters */
const name = namor.generate({ words: 3, saltLength: 0 })

/* enable manly mode */
const name = namor.generate({ subset: "manly" })

See it in action here or experience manly mode.

Collision Stats

The following stats give you the total number of permutations based on the word count (without a salt), and can help you make a decision on how long to make your salt. This data is based on the number of words we currently have in our dictionary files.

  • 1-word combinations: 1,319
  • 2-word combinations: 3,016,553
  • 3-word combinations: 1,720,200,230
  • 4-word combinations: 2,268,944,103,370
Subset: Manly
  • 1-word combinations: 282
  • 2-word combinations: 110,826
  • 3-word combinations: 9,487,044
  • 4-word combinations: 2,675,346,408

API

.generate (options:Object)

Generates a new name, in all its glory.

  • options

    • words default: 2 The number of words to include in the generated name. Must be a positive integer no higher than 4, or 0 to only generate a salt.

    • separator default: "-" The character to use between words when generating a name.

    • saltLength default: 5 The number of characters in the trailing salt. Must be a positive integer or 0 to exclude a trailing number.

    • saltType default: "mixed" The type of characters to use for the trailing salt. Can be number, string, or mixed.

    • subset Whether to use a subset dictionary rather than the default. Be aware this limits the number of dictionary words, creating a higher chance of collision. Only valid value at the moment is "manly".

.validate (name:String, options:Object)

Checks whether a string is valid for use as a subdomain, including length (max of 63 characters) and checking against a list of reserved subdomains to prevent shady stuff.

  • name - The name to check.

  • options

    • reserved default: false Whether to check the name against the reserved word list, which is a predefined set of subdomains that should remain private.

.rawData

Allows access to the raw dictionary data. You probably won't ever use this, but it's there if you need it.

License

MIT © Jason Maurer

版本与发布记录

@ggascoigne/namor 共发布 3 个版本,首次发布于 2020/06/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.4latest2022/02/274 年前
2.0.32022/02/274 年前
2.0.22020/06/106 年前

关于 @ggascoigne/namor 的常见问题

@ggascoigne/namor 是什么?

A domain-safe name generator

如何安装 @ggascoigne/namor?

在项目目录运行 npm install @ggascoigne/namor,或使用 pnpm add / yarn add / bun add。

@ggascoigne/namor 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ggascoigne__namor 是否存在。

@ggascoigne/namor 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ggascoigne/namor 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=6。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ggascoigne/namor 可以商用吗?

@ggascoigne/namor 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ggascoigne/namor 的下载量有多少?

根据 npm 官方下载统计,@ggascoigne/namor 在 2026/10/17 – 2026/11/15 这 30 天内被下载 7,226 次,日均约 241 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ggascoigne/namor 还在维护吗?

最新版本 2.0.4 发布于 2022/02/27(4 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/06/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。