@qeepsake/rails-guid
Advanced tools
Comparing version
@@ -0,2 +1,6 @@ | ||
import { isExtractedRailsId } from './is-extracted-rails-id'; | ||
export function extractRailsId(gid, stripTimestamp = false) { | ||
// Checks if ID has already been extracted, if so, return it | ||
if (gid && isExtractedRailsId(gid)) | ||
return gid; | ||
if (typeof gid === 'string' && (gid === null || gid === void 0 ? void 0 : gid.indexOf('/')) != -1) { | ||
@@ -3,0 +7,0 @@ const gidComponents = gid.split('/'); |
export { extractRailsId } from './extract-rails-id'; | ||
export { createRailsId } from './create-rails-id'; | ||
export { isExtractedRailsId } from './is-extracted-rails-id'; |
@@ -0,1 +1,9 @@ | ||
function isExtractedRailsId(id) { | ||
if (typeof id === 'string') { | ||
return !id.startsWith('gid://') && id.indexOf(' ') == -1; | ||
} | ||
return false; | ||
} | ||
function extractRailsId(gid, stripTimestamp) { | ||
@@ -6,2 +14,4 @@ if (stripTimestamp === void 0) { | ||
if (gid && isExtractedRailsId(gid)) return gid; | ||
if (typeof gid === 'string' && (gid === null || gid === void 0 ? void 0 : gid.indexOf('/')) != -1) { | ||
@@ -31,2 +41,3 @@ var _extractedId; | ||
exports.extractRailsId = extractRailsId; | ||
exports.isExtractedRailsId = isExtractedRailsId; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,9 @@ | ||
function isExtractedRailsId(id) { | ||
if (typeof id === 'string') { | ||
return !id.startsWith('gid://') && id.indexOf(' ') == -1; | ||
} | ||
return false; | ||
} | ||
function extractRailsId(gid, stripTimestamp) { | ||
@@ -6,2 +14,4 @@ if (stripTimestamp === void 0) { | ||
if (gid && isExtractedRailsId(gid)) return gid; | ||
if (typeof gid === 'string' && (gid === null || gid === void 0 ? void 0 : gid.indexOf('/')) != -1) { | ||
@@ -29,3 +39,3 @@ var _extractedId; | ||
export { createRailsId, extractRailsId }; | ||
export { createRailsId, extractRailsId, isExtractedRailsId }; | ||
//# sourceMappingURL=index.modern.js.map |
{ | ||
"name": "@qeepsake/rails-guid", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Tiny (zero dependancy) utility to create and extract rails guid strings in JavaScript 🛤", | ||
@@ -5,0 +5,0 @@ "author": "lukebrandonfarrell", |
@@ -40,2 +40,11 @@ # Rails Guid for JavaScript | ||
### Tetsing for Extracted Rails ID | ||
```js | ||
import { isExtractedRailsId } from '@qeepsake/rails-guid'; | ||
isExtractedRailsId("55587") // => true | ||
isExtractedRailsId("gid://qeepsake-rails/Model/55587") // => false | ||
``` | ||
## License | ||
@@ -42,0 +51,0 @@ |
@@ -0,1 +1,3 @@ | ||
import { isExtractedRailsId } from './is-extracted-rails-id' | ||
/** | ||
@@ -21,2 +23,5 @@ * Extract rails ID | ||
): string | null { | ||
// Checks if ID has already been extracted, if so, return it | ||
if (gid && isExtractedRailsId(gid)) return gid | ||
if (typeof gid === 'string' && gid?.indexOf('/') != -1) { | ||
@@ -23,0 +28,0 @@ const gidComponents = gid.split('/') |
export { extractRailsId } from './extract-rails-id' | ||
export { createRailsId } from './create-rails-id' | ||
export { isExtractedRailsId } from './is-extracted-rails-id' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29059
18.71%32
14.29%403
19.58%70
14.75%