/shopify-gid

Universal encoder/decoder for ID values returned from the Shopify Storefront GraphQL API.

Primary LanguageJavaScript

shopify-gid

Universal encoder/decoder for ID values returned from the Shopify Storefront GraphQL API. 400 bytes gzipped.

✅ Added Support for Non-encoded object IDs in the GraphQL Storefront API

Install

npm i shopify-gid --save

Usage

import { encode, decode } from 'shopify-gid'

decode(base64hash) OR decode(globalID)

decode('Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzEyMzQ1...')
        //OR
decode('gid://shopify/Product/12345')
  // => { type: 'Product', id: '12345', params: { accessToken: 'abcde123' }, raw: 'Z2lkOi8...' }

encode(type, id[, params])

encode('Product', 12345, { accessToken: 'abcde123' })
  // => Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzEyMzQ1...

License

MIT License © Eric Bailey