Skip to content

Commit

Permalink
Publish to npm (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuong Duy Nguyen authored Nov 27, 2019
1 parent 8ede94f commit 9332acb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 100 deletions.
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

21 changes: 0 additions & 21 deletions __tests__/index.test.ts

This file was deleted.

12 changes: 0 additions & 12 deletions examples/index.ts

This file was deleted.

19 changes: 6 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
{
"name": "@cuongw/giin",
"version": "0.1.1",
"name": "giin",
"version": "0.5.5",
"description": "🦄 Simple and lightweight GraphQL client.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"repository": "https://github.com/cuongw/giin.git",
"author": "Cuong Duy Nguyen",
"keywords": [
"unique-id",
"uid",
"thinid",
"id",
"code",
"number-code",
"number"
"giin",
"graphql-client",
"graphql-request",
"graphql"
],
"license": "MIT",
"files": [
"lib/**/*"
],
"publishConfig": {
"registry": "https://npm.pkg.github.com/@cuongw"
},
"scripts": {
"start": "node ./lib/index.js",
"start:dev": "ts-node ./src/index.ts",
Expand Down
55 changes: 2 additions & 53 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
/**
* Create a random string with length equals 4.
*/
function s4(): string {
return Math.round(new Date().getTime() * Math.random())
.toString(16)
.substr(0, 4);
}

/**
* Create a random number between 0 and (length - 1).
* @param length Length of chaining numbers.
*/
function ramdomNumber(length: number): number {
return Math.floor(Math.random() * length);
}

/**
* Create a default Id with length equals 24.
*/
function defaultId(): string {
const charCodes = ['-', '_', '@', '#', '$', '%', '^', '&', '*'];
const { length } = charCodes;
return (
s4() +
charCodes[ramdomNumber(length)] +
s4() +
charCodes[ramdomNumber(length)] +
s4() +
charCodes[ramdomNumber(length)] +
s4() +
charCodes[ramdomNumber(length)] +
s4()
);
}

/**
* Create a lovely Id with thinid.
* @param length Length of Id.
*/
export function thinid(length?: number): string {
if (!length || length <= 0) {
return defaultId();
}

const defaultLength = defaultId().length;
const x = length % defaultLength;
const y = Math.floor(length / defaultLength);
let result = defaultId().substr(0, x);
for (let i = 0; i < y; i++) {
result += defaultId();
}
return result;
export function giin(): string {
return 'giin';
}

0 comments on commit 9332acb

Please sign in to comment.