{"id":16591075,"url":"https://github.com/whizkydee/type-reverse","last_synced_at":"2025-03-21T13:31:23.069Z","repository":{"id":98591322,"uuid":"114677597","full_name":"whizkydee/type-reverse","owner":"whizkydee","description":"🦄 Lightweight reverse utility around strings, arrays, numbers and more.","archived":false,"fork":false,"pushed_at":"2023-03-13T01:24:42.000Z","size":28,"stargazers_count":33,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-16T07:04:51.834Z","etag":null,"topics":["array","inverse","invert","inverted-index","reverse","string"],"latest_commit_sha":null,"homepage":"https://npm.im/type-reverse","language":"JavaScript","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/whizkydee.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.md","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}},"created_at":"2017-12-18T19:04:24.000Z","updated_at":"2024-04-13T23:22:06.000Z","dependencies_parsed_at":"2023-07-11T14:35:46.053Z","dependency_job_id":null,"html_url":"https://github.com/whizkydee/type-reverse","commit_stats":{"total_commits":32,"total_committers":2,"mean_commits":16.0,"dds":0.3125,"last_synced_commit":"c5502a388561009b4d9aa3643f98d1f3f7052f17"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whizkydee%2Ftype-reverse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whizkydee%2Ftype-reverse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whizkydee%2Ftype-reverse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whizkydee%2Ftype-reverse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whizkydee","download_url":"https://codeload.github.com/whizkydee/type-reverse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221456215,"owners_count":16824954,"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":["array","inverse","invert","inverted-index","reverse","string"],"created_at":"2024-10-11T23:15:17.412Z","updated_at":"2024-10-28T10:12:09.657Z","avatar_url":"https://github.com/whizkydee.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# type-reverse\n\n[![Build Status](https://api.travis-ci.com/whizkydee/type-reverse.svg?token=zXdJsUqADmau83i9KNqF\u0026branch=master)](https://travis-ci.org/whizkydee/type-reverse) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) [![Made in Nigeria](https://img.shields.io/badge/made%20in-nigeria-008751.svg)](https://github.com/acekyd/made-in-nigeria)\n\n\u003e 🦄 Lightweight reverse utility around strings, arrays, numbers and more.\n\n## Install\n\n```sh\n$ npm install --save type-reverse\n```\n\n## Usage\n\n```js\nconst reverse = require('type-reverse')\n```\n\nor...\n\n```js\nimport reverse from 'type-reverse'\n```\n\n### API\n\n#### reverse( input[, options][, callback] )\n\n**Params**\n\n- `input` **{String|Number|Array|Set}**\n- `options` **{?Object}**\n- `callback` **{?Function}**\n- `returns` **{\\*}**\n\n```js\nreverse('pizza')\n//=\u003e azzip\n```\n\nWorks with numbers too.\n\n```js\nreverse(1234)\n//=\u003e 4321\n```\n\n## Reversing arrays...\n\nWhen JavaScript's _Array#reverse_ method is used, the original array is mutated, as in, the indexes of the elements are changed. On the other hand, this utility adopts the **non-destructive array reversal** method, which means the `reverse()` function doesn't mutate the array; it just returns the reversed array and still maintains the indexes of the elements in the original array.\n\n#### native reverse...\n\n```js\nconst arr = [1, 2, 3]\narr.reverse() //=\u003e [3, 2, 1]\n```\n\nOops, we lost the indexes of elements in the initial array...\n\n```js\nconsole.log(arr) //=\u003e [3, 2, 1]\n```\n\nvs...\n\n#### 🦄 to the rescue...\n\n```js\nconst arr = [1, 2, 3]\nreverse(arr) //=\u003e [3, 2, 1]\n```\n\nYay! `arr` is not mutated. The indexes of its elements are still maintained...\n\n```js\nconsole.log(arr) //=\u003e [1, 2, 3]\n```\n\n### Sets\n\nIf you've been wondering how to reverse Sets in JavaScript, here's it! The core `reverse` function can take in a `Set` as the input and then return the reversed `Set`...\n\n```js\nconst set = new Set([5, 4, 3, 4, 5])\nreverse(set) //=\u003e Set { 3, 4, 5 }\n```\n\n## options\n\n`options` is the second parameter to the function call and it is an object with two available properties. It can also take in a falsy value which would implicity get converted to an empty object.\n\n### `invert: {String}`\n\nThis property defaults to `index` and applies to strings and numbers only.\n\n```js\nreverse(/*...*/, {\n  invert: '[index|word|sign]'\n})\n```\n\n- `index` - interchanges the indexes of characters in the input...\n\n  ```js\n  reverse(12345, { invert: 'index' }) //=\u003e 54321\n  reverse('of... unicorns', { invert: 'index' }) //=\u003e snrocinu ...fo\n  ```\n\n- `sign` - inverts the sign in a number...\n\n  ```js\n  reverse(1234, { invert: 'sign' }) //=\u003e -1234\n  ```\n\n- `word` - swaps the location of words in a string...\n  ```js\n  reverse('of... unicorns', { invert: 'word' }) //=\u003e unicorns of...\n  ```\n\n### `preserveZeros: {Boolean}`\n\nThis property defaults to `true`. It specifies whether to enforce preceding zeros in the result of a number that contains trailing zeros. See [#3](https://github.com/whizkydee/type-reverse/issues/4) for more info. Note that the result gets converted to a string. Disabling it would look like this...\n\n```js\nreverse(240, { preserveZeros: false }) //=\u003e 42\n```\n\n## `callback: {Function}`\n\nThe callback takes in a function with two optional parameters that represent `input` and `result` respectively.\n\n- `input` - the initial input that was passed into the function\n- `result` - the output from reversing the input\n\n```js\nconst text = 'dog'\n\nreverse(text, null, function(intitial, result) {\n  return intitial + ' was changed to ' + result\n}) //=\u003e dog was changed to god\n```\n\n## Limits\n\nDid you just try to reverse a reaally huge number? Unfortunately, this utility doesn't support very large numbers. Trying to do so with this utility would throw a **TypeError**.\n\n## Author\n\n**Olaolu Olawuyi**\n\n- [github/whizkydee](https://github.com/whizkydee)\n- [twitter/mrolaolu](https://twitter.com/mrolaolu)\n\n## License\n\nMIT © [Olaolu Olawuyi](https://olaolu.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhizkydee%2Ftype-reverse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhizkydee%2Ftype-reverse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhizkydee%2Ftype-reverse/lists"}