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

@rksan/random-string

v0.1.0

Published

Generate random string

Downloads

1

Readme

Coverage Status

random-string

overview

UTF-8の範囲内でランダムな文字列を生成

Usage

import { randomString } from "@rksan/random-string";

const str = randomString(16);

console.log(`randam string is "${str}"`);

Requirement

  • Node.js - v18.x

Install

npm i -D @rksan/random-string

syntax

const str: string = randomString(
  length: number,
  options?: {
    src?: string
     | {start: string, end: string}
     | [{ start: string, end: string }],
    exclude?: string
     | { start: string, end: string }
     | [ { start: string, end: string } ]
  }
)

arguments

length

生成する文字列の長さ

@type number

options?

生成する文字列のオプション

@type { src?: object, exclude?: object }

options?.src?

生成される文字列のソース

UTF8コードの範囲で、必ず src.start <= src.end にする必要がある

@type string | { start: string, end: string } | Array<{ start: string, end: string }>

  • string : 指定された文字列のみを使用する
  • { start, end } : startからendまでのUTF8コード範囲内にある文字の全てを使用する
  • Array<{start, end}> : 1文字を出力する都度、渡されたArrayからランダムに{start, end}を取得し、取得したstartからendまでのUTF8コード範囲内にある文字の全てを使用する

@default { start: "!", end: "~" }

exp.

// Not specified
const str = randomString(8);

// Specified by String
const str = randomString(8, {
  src: "0123456789",
});

// Specified by Object
const str = randomString(8, {
  src: {
    start: "a",
    end: "z",
  },
});

// Specified by Object array
const str = randomString(8, {
  src: [
    {
      start: "0",
      end: "9",
    },
    {
      start: "A",
      end: "Z",
    },
    {
      start: "a",
      end: "z",
    },
  ],
});
options?.exclude

生成される文字列から除外する文字

UTF8コードの範囲で、必ず exclude.start <= exclude.end にする必要がある

@type {string | {start: string, end: string} | [{start: string, end: string}]}

  • string : 指定された文字列は除外される
  • {start, end} : 指定されたstartからendまでのUTF8文字は全て除外される
  • Array<{start, end}> : 配列として指定された全てのstartからendまでのUTF8文字は全て除外される

@default undefined

exp.

// Not specified
const str = randomString(8, {
  src: {
    start: "0",
    end: "z",
  },
});

// Specified by String
const str = randomString(8, {
  src: {
    start: "0",
    end: "z",
  },
  exclude: ":;<=>?@[\\]^_`",
});

// Specified by Object
const str = randomString(8, {
  src: {
    start: "0",
    end: "Z",
  },
  exclude: {
    start: ":",
    end: "@",
  },
});

// Specified by Object array
const str = randomString(8, {
  src: {
    start: "0",
    end: "z",
  },
  exclude: [
    {
      start: ":",
      end: "@",
    },
    {
      start: "[",
      end: "`",
    },
  ],
});

return

str

ランダムな文字列

@type {string}

Reference

Author

@rksan https://github.com/rksan | github

Licence

MIT