{"id":15649339,"url":"https://github.com/cartant/firebase-key","last_synced_at":"2025-04-14T19:23:46.446Z","repository":{"id":20229453,"uuid":"89179280","full_name":"cartant/firebase-key","owner":"cartant","description":"Firebase key utility and encoding/decoding functions","archived":false,"fork":false,"pushed_at":"2023-04-18T10:40:06.000Z","size":846,"stargazers_count":39,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T02:01:54.940Z","etag":null,"topics":["firebase","key","utilities"],"latest_commit_sha":null,"homepage":"https://cartant.github.io/firebase-key/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cartant.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["cartant"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-04-23T23:30:03.000Z","updated_at":"2024-09-20T15:46:51.000Z","dependencies_parsed_at":"2024-06-18T18:56:11.976Z","dependency_job_id":"07191f2a-7705-4b5d-819d-955b310d5475","html_url":"https://github.com/cartant/firebase-key","commit_stats":{"total_commits":151,"total_committers":3,"mean_commits":"50.333333333333336","dds":0.07284768211920534,"last_synced_commit":"17b7d1e86db715857410b43dca5b46dac70e1c15"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cartant%2Ffirebase-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cartant%2Ffirebase-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cartant%2Ffirebase-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cartant%2Ffirebase-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cartant","download_url":"https://codeload.github.com/cartant/firebase-key/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248943590,"owners_count":21186993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebase","key","utilities"],"created_at":"2024-10-03T12:29:19.093Z","updated_at":"2025-04-14T19:23:46.427Z","avatar_url":"https://github.com/cartant.png","language":"TypeScript","funding_links":["https://github.com/sponsors/cartant"],"categories":[],"sub_categories":[],"readme":"# firebase-key\n\n[![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/cartant/firebase-key/blob/master/LICENSE)\n[![NPM version](https://img.shields.io/npm/v/firebase-key.svg)](https://www.npmjs.com/package/firebase-key)\n[![Downloads](http://img.shields.io/npm/dm/firebase-key.svg)](https://npmjs.org/package/firebase-key)\n[![Build status](https://img.shields.io/circleci/build/github/cartant/firebase-key?token=f7c37e6c6718f5c33e961b4aca2fb4eb4442b1b4)](https://app.circleci.com/pipelines/github/cartant)\n[![dependency status](https://img.shields.io/david/cartant/firebase-key.svg)](https://david-dm.org/cartant/firebase-key)\n[![devDependency Status](https://img.shields.io/david/dev/cartant/firebase-key.svg)](https://david-dm.org/cartant/firebase-key#info=devDependencies)\n[![peerDependency Status](https://img.shields.io/david/peer/cartant/firebase-key.svg)](https://david-dm.org/cartant/firebase-key#info=peerDependencies)\n[![Greenkeeper badge](https://badges.greenkeeper.io/cartant/firebase-key.svg)](https://greenkeeper.io/)\n\n### What is it?\n\n`firebase-key` is a library of utility functions for manipulating, encoding and decoding Firebase keys.\n\n### Why might you need it?\n\nYou might find `firebase-key` useful if you need to do any of the following:\n\n* Convert a Firebase push key/ID to a time.\n* Query push keys/IDs based on time.\n* Page through push keys/IDs as efficiently as possible.\n* Store illegal characters in Firebase keys.\n* Encode integers as strings that sort numerically.\n\n## Install\n\nInstall the package using NPM:\n\n```\nnpm install firebase-key --save\n```\n\nAnd import the functions for use with TypeScript or ES2015:\n\n```js\nimport { key } from \"firebase-key\";\nconsole.log(key());\n```\n\nOr `require` the module for use with Node or a CommonJS bundler:\n\n```js\nconst firebaseKey = require(\"firebase-key\");\nconsole.log(firebaseKey.key());\n```\n\nOr include the UMD bundle for use as a `script`:\n\n```html\n\u003cscript src=\"https://unpkg.com/firebase-key\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nconsole.log(firebaseKey.key());\n\u003c/script\u003e\n```\n\n## API\n\n* [key](#key)\n* [date](#date-milliseconds)\n* [milliseconds](#date-milliseconds)\n* [increment](#increment-decrement)\n* [decrement](#increment-decrement)\n* [encode](#encode-decode)\n* [decode](#encode-decode)\n* [encodeLexicographic](#encode-decode-lexicographic)\n* [decodeLexicographic](#encode-decode-lexicographic)\n\n\u003ca name=\"key\"\u003e\u003c/a\u003e\n\n### key\n\n```ts\nfunction key(\n  timestamp: number | Date = Date.now(),\n  as: \"max\" | \"min\" | \"random\" = \"random\"\n): string\n```\n\nThis function is based on the Firebase push key/ID generator implemented in [this gist][gist].\n\nIf called with no arguments, it generates a Firebase push key/ID using the current time. If a timestamp is specified, it is used in the generation of the key.\n\nBy default, the timestamp is combined with random data. If `as` is specified as either `max` or `min`, random data is not used and the generated key will sort either after (for `max`) or before (for `min`) any other keys that that have the same timestamp, but have random data.\n\n\u003ca name=\"date-milliseconds\"\u003e\u003c/a\u003e\n\n### date/milliseconds\n\n```ts\nfunction date(key: string): Date\nfunction milliseconds(key: string): number\n```\n\nThese functions return the timestamp of a push key/ID, either as a `Date` or as the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.\n\n\u003ca name=\"increment-decrement\"\u003e\u003c/a\u003e\n\n### increment/decrement\n\n```ts\nfunction increment(key: string): string\nfunction decrement(key: string): string\n```\n\nThese functions return a push key/ID that has been incremented or decremented to the next consecutive push key/ID and can be useful when paging through the Firebase database.\n\n\u003ca name=\"encode-decode\"\u003e\u003c/a\u003e\n\n### encode/decode\n\n```ts\nfunction encode(text: string): string\nfunction decode(key: string): string\n```\n\nThese functions encode and decode keys, replacing illegal characters with safe, encoded characters.\n\n`!` is used as an escape character - rather than `%` - for compatibility with the REST API and with the Firebase management console.\n\n\u003ca name=\"encode-decode-lexicographic\"\u003e\u003c/a\u003e\n\n### encodeLexicographic/decodeLexicographic\n\n```ts\nfunction encodeLexicographic(value: number): string\nfunction decodeLexicographic(key: string): number\n```\n\nThese functions encode and decode integer values (both positive and negative) as strings that have a lexicographic ordering that is identical to the numeric ordering. They are based upon an implementation used in [Firepad][firepad].\n\n[gist]: https://gist.github.com/mikelehen/3596a30bd69384624c11\n[firepad]: https://github.com/firebase/firepad/blob/v1.4.0/lib/firebase-adapter.js#L375-L403","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcartant%2Ffirebase-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcartant%2Ffirebase-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcartant%2Ffirebase-key/lists"}