https://github.com/qeepsake/rails-guid
Tiny utility to create and extract rails guid strings in JavaScript 🛤
https://github.com/qeepsake/rails-guid
Last synced: 2 months ago
JSON representation
Tiny utility to create and extract rails guid strings in JavaScript 🛤
- Host: GitHub
- URL: https://github.com/qeepsake/rails-guid
- Owner: Qeepsake
- Created: 2022-04-06T14:22:26.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T10:44:39.000Z (almost 3 years ago)
- Last Synced: 2025-02-10T00:46:32.541Z (over 1 year ago)
- Language: TypeScript
- Size: 754 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rails Guid for JavaScript
[](#contributors-)
> Zero dependancy utility for creating and extracting rails GUIDs from a string.
[](https://www.npmjs.com/package/@qeepsake/rails-guid) [](https://standardjs.com)
## Install
```bash
npm install --save @qeepsake/rails-guid
```
## Usage
### Extracting Rails GUID
You can use `extractRailsId` to extract a Rails GUID from a string:
```js
import { extractRailsId } from '@qeepsake/rails-guid';
const guid = "gid://qeepsake-rails/Model/55587";
extractRailsId(guid) // -> 55587
```
### Creating Rails GUID
You can use the `createRailsId` to create Rails GUID:
```js
import { createRailsId } from '@qeepsake/rails-guid';
const id = 55587 || "55587";
createRailsId(id, "Model") // -> gid://qeepsake-rails/Model/55587
```
### Tetsing for Extracted Rails ID
```js
import { isExtractedRailsId } from '@qeepsake/rails-guid';
isExtractedRailsId("55587") // => true
isExtractedRailsId("gid://qeepsake-rails/Model/55587") // => false
```
### Testing for Rails Global ID
You can use `isRailsId`` to test if a string is a valid Rails Global ID:
```js
import { isRailsId } from '@qeepsake/rails-guid';
isRailsId("gid://qeepsake-rails/User/1") // => true
isRailsId("gid://someotherapp/User/1") // => true
isRailsId("User/1") // => false
```
This function tests if the string conforms to the general Rails gid structure: `gid:////`.
## License
MIT © [lukebrandonfarrell](https://github.com/lukebrandonfarrell)
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!