Skip to content

Commit

Permalink
binary-uuid first commit version v^1.7.8
Browse files Browse the repository at this point in the history
  • Loading branch information
kovarike committed Jun 24, 2024
0 parents commit 8f69851
Show file tree
Hide file tree
Showing 19 changed files with 3,080 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
./test
test
test/test.ts
dist
./dist
dist
.npmrc
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
./test
test
test/test.ts
src
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Danilo Silva

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# @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](https://img.shields.io/npm/v/@kovarike/cocc.svg?logo=npm)](https://www.npmjs.com/package/@kovarike/cocc)
![Uses TypeScript](https://img.shields.io/badge/Uses-Typescript-294E80.svg)

## Installing

```shell
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:

```typescript
import {cocc} from '@kovarike/cocc'

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

```


```javascript
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.


```typescript
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.

```typescript
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);
}
}

```

```typescript
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](https://github.com/kovarike) and [project](https://github.com/kovarike/cocc).

MIT License, see the included [MIT](https://github.com/kovarike/cocc/blob/master/LICENSE) file.
Loading

0 comments on commit 8f69851

Please sign in to comment.