Git Product home page Git Product logo

chinese-random-name's Introduction

Chinese Random Name

Generate Chinese name by using Node.js with ❤️.

Installation

$ npm --save install chinese-random-name

Usage

First you need to require this package:

const randomName = require('chinese-random-name');

If you're using it from Browser environment, do require chinese-random-name/random.min.

Generate a Full Name Automatically

Use generate() function:

console.log(randomName.generate());

Only Surname

Use getOne function in surnames.

console.log(randomName.surnames.getOne());

getOne has an optional parameter opt. You may pass a field named useSurnamesCountAtTheTop to specify only get surname from most top useSurnamesCountAtTheTop surnames. e.g.

randomName.surnames.getOne({ useSurnamesCountAtTheTop: 100 });

It means the function only select a random surname from the most top 100 surnames.

Name

Use get / get1 / get2 / get3 function in names.

  • get: returns a random name and its length between 1 and 3.
  • get1: returns a random name with length 1. (you can pass a parameter which may be "金" / "木" / "水" / "火" / "土" or leave it blank)
  • get2: returns a random name with length 2. (you can pass "金金" / "金木" / ... or leave it blank)
  • get3: returns a random name with length 3. (you can pass "金金金" / "水火土" / ... or leave it blank)
  • dict: the dictionary object.

Examples:

randomName.names.get();
randomName.names.get1();
randomName.names.get2();
randomName.names.get3();
randomName.names.get1("金");
randomName.names.get2("木水");
randomName.names.get3("火火火");

Related Article

http://xcoder.in/2014/09/01/how-i-made-chinese-random-x/

Contribute

You're welcome to fork and make pull requests!

chinese-random-name's People

Contributors

cubemoon avatar haio avatar renovate[bot] avatar xadillax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chinese-random-name's Issues

无法通过terser 导致构建失败!

项目使用vue-cli 构建,添加本项目后导致 build 失败!追其原因,webpack 构建时使用了terser ,/dict/n.js的文件导致 terser 报错,最终导致构建失败!

image

npx terser --compress --mangle -- ./dict/n.js
image

randomName.generate(2)会生成三个字的名字

//random.js
else if(len === 2) {
do { surname = surnames.getOne(); } while(surname.length !== 1);
name = names.get();

==>
else if(len === 2) {
do { surname = surnames.getOne(); } while(surname.length !== 1);
name = names.get1(); //保证只有一个字

按照说明,npm install后,项目无法找到模块

Could not find a declaration file for module 'chinese-random-name'. 'E:/DevelopHeiit/heiit_front_dm/node_modules/chinese-random-name/random.js' implicitly has an 'any' type.
Try npm install @types/chinese-random-name if it exists or add a new declaration (.d.ts) file containing declare module 'chinese-random-name'; TS7016

 | import randomName from 'chinese-random-name';
      |                        ^
    2 | import { province, nodePropertiesSchema } from './Mock/nodePropertiesSchema';
    3 | import { NodeData } from '../types';
    4 | 

556 warn [email protected] No repository field. 557 verbose stack Error: ENOENT: no such file or directory, access '/data/wwwroot/Live22/node_modules/after' 558 verbose cwd /data/wwwroot/Live22 559 verbose Linux 4.9.0-6-amd64 560 verbose argv "/root/.nvm/versions/node/v9.2.0/bin/node" "/root/.nvm/versions/node/v9.2.0/bin/npm" "remove" "chinese-random-name" 561 verbose node v9.2.0 562 verbose npm v6.0.1 563 error path /data/wwwroot/Live22/node_modules/after 564 error code ENOENT 565 error errno -2 566 error syscall access 567 error enoent ENOENT: no such file or directory, access '/data/wwwroot/Live22/node_modules/after' 568 error enoent This is related to npm not being able to find a file. 569 verbose exit [ -2, true ]

556 warn [email protected] No repository field.
557 verbose stack Error: ENOENT: no such file or directory, access '/data/wwwroot/Live22/node_modules/after'
558 verbose cwd /data/wwwroot/Live22
559 verbose Linux 4.9.0-6-amd64
560 verbose argv "/root/.nvm/versions/node/v9.2.0/bin/node" "/root/.nvm/versions/node/v9.2.0/bin/npm" "remove" "chinese-random-name"
561 verbose node v9.2.0
562 verbose npm v6.0.1
563 error path /data/wwwroot/Live22/node_modules/after
564 error code ENOENT
565 error errno -2
566 error syscall access
567 error enoent ENOENT: no such file or directory, access '/data/wwwroot/Live22/node_modules/after'
568 error enoent This is related to npm not being able to find a file.
569 verbose exit [ -2, true ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.