Skip to content

Encode TheBrain uuids to 22 characters slugs and decode slugs to uuids

Notifications You must be signed in to change notification settings

wmakeev/thebrain-uuid-slug

Repository files navigation

thebrain-uuid-slug

npm

Encode TheBrain uuids to 22 characters slugs and decode slugs to uuids

This is useful to decode slugs from local thought url and create same url from BrainId and ThoughtId.

Install

npm install thebrain-uuid-slug

Usage

Create TheBrain local url

const { uuidToSlug } = require('thebrain-uuid-slug')

const brainId = 'fd7bebf7-0ea0-40c9-b8c7-969e54c86136'
const thoughtId = 'd527957d-d57b-4af5-bb68-d527fd7d7b3b'

const localUrl = `brain://api.thebrain.com/${uuidToSlug(brainId)}/${uuidToSlug(thoughtId)}`

assert.equal(
  localUrl,
  'brain://api.thebrain.com/9-t7_aMOyUC4x5aeVMhhNg/fZUn1XvV9Uq3aNUn_X17Ow'
)

Decode TheBrain local url slug to uuid

const { slugToUuid } = require('thebrain-uuid-slug')

const slug = '9-t7_aMOyUC4x5aeVMhhNg'

assert.equal(slugToUuid(slug), 'fd7bebf7-0ea3-40c9-b8c7-969e54c86136')

About

Encode TheBrain uuids to 22 characters slugs and decode slugs to uuids

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published