Code Monkey home page Code Monkey logo

cocc's Introduction

@kovarike/cocc

The system uses a combination of binary, bytes and hexadecimals to generate the sequence that gives the base. using RegEx to define patterns when generating the Id and Token.

NPM Uses TypeScript

Installing

npm i binary-uuid

# If you're using NPM:
# npm install binary-uuid

Basic Usage

Just call one of the {Token, Id} functions after importing them:

import {cocc} from '@kovarike/cocc'

console.log(cocc.Token()) // Xpyci2fycXsbfNhVvSY9IwLejSuKqQZpbt1b 
console.log(cocc.Id()) // 008a0326-b64f-427a-a654-82628fc3e033
 
const {cocc} = require("@kovarike/cocc")

console.log(cocc.Token()) // Xpyci2fycXsbfNhVvSY9IwLejSuKqQZpbt1b
console.log(cocc.Id()) // 008a0326-b64f-427a-a654-82628fc3e033
 

API

@kovarike/cocc

Token — With each call, the function returns a Token. which follows the Token standard.

Id — With each call, the function returns an ID that follows the uuid pattern.

export function Token(){
  const set: Set<string> = new Set();
  const token = IsToken({set}) 
  return token; // Xpyci2fycXsbfNhVvSY9IwLejSuKqQZpbt1b
}

export function Id(): string {
  const set: Set<string> = new Set();
  const id  = IsId({set})
  return id; // 008a0326-b64f-427a-a654-82628fc3e033
}

IsValid — The IsValid function receives the Id as its first parameter and the Token as its optional second parameter. The function returns a boolean (true or false) to indicate whether it is following the pattern established in the RegEx.

export function IsValid(params: string, value?:string): boolean {
  if (value) {
    return (regex.v4.test(params) || regex.v5.test(params)) && regex.token.test(value);
  } else {
    return regex.v4.test(params) || regex.v5.test(params) || regex.token.test(params);
  }
}
import {cocc} from '@kovarike/cocc'

const uuid = cocc.Id();
cocc.IsValid(uuid);

const token = cocc.Token();
cocc.IsValid(token);

cocc.IsValid(uuid, token); 

Authors and License

kovarike and project.

MIT License, see the included MIT file.

cocc's People

Contributors

kovarike avatar

Stargazers

 avatar

Watchers

 avatar

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.