All Projects → whizkydee → type-reverse

whizkydee / type-reverse

Licence: MIT License
🦄 Lightweight reverse utility around strings, arrays, numbers and more.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to type-reverse

php-invert-color
Invert a given color.
Stars: ✭ 13 (-56.67%)
Mutual labels:  reverse, inverse, invert
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (+16.67%)
Mutual labels:  string, array
Android interviews
🚀Everything you need to know to find a android job. 算法 / 面试题 / Android 知识点 🔥🔥🔥 总结不易,你的 star 是我最大的动力!
Stars: ✭ 510 (+1600%)
Mutual labels:  string, array
Data-Structure-Algorithm-Programs
This Repo consists of Data structures and Algorithms
Stars: ✭ 464 (+1446.67%)
Mutual labels:  string, array
Golang Combinations
Golang library which provide an algorithm to generate all combinations out of a given string array.
Stars: ✭ 51 (+70%)
Mutual labels:  string, array
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (+970%)
Mutual labels:  string, array
Algo Tree
Algo-Tree is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as C++, Python and Java.
Stars: ✭ 166 (+453.33%)
Mutual labels:  string, array
Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (+793.33%)
Mutual labels:  string, array
php-helpers
An extensive set of PHP helper functions and classes.
Stars: ✭ 27 (-10%)
Mutual labels:  string, array
Competitive Programming
Programming👨‍💻 Questions on BinarySearch💻, LeetCode💻, CodeChef💻, Codeforces💻,DSA 450
Stars: ✭ 188 (+526.67%)
Mutual labels:  string, array
DS ALGO
Data Structures and algorithms
Stars: ✭ 20 (-33.33%)
Mutual labels:  string, array
utils.js
👷 🔧 zero dependencies vanilla JavaScript utils.
Stars: ✭ 14 (-53.33%)
Mutual labels:  string, array
prototyped.js
Some common Typescript prototypes
Stars: ✭ 22 (-26.67%)
Mutual labels:  string, array
rxjs-ninja
RxJS Operators for handling Observable strings, numbers, booleans and more
Stars: ✭ 68 (+126.67%)
Mutual labels:  string, array
tokenizr
String Tokenization Library for JavaScript
Stars: ✭ 70 (+133.33%)
Mutual labels:  string
total-serialism
Toolbox full of Algorithmic Composition methods
Stars: ✭ 74 (+146.67%)
Mutual labels:  array
array-access
PHP multi array access
Stars: ✭ 23 (-23.33%)
Mutual labels:  array
widestring-rs
A wide string Rust library for converting to and from wide Unicode strings.
Stars: ✭ 48 (+60%)
Mutual labels:  string
ReversePowerShell
Functions that can be used to gain Reverse Shells with PowerShell
Stars: ✭ 48 (+60%)
Mutual labels:  reverse
VBA-Arrays
😎 Array functions that are similar JavaScript functions. Example: Push, Pop, Shift, Unshift, Sort, length, toString.
Stars: ✭ 48 (+60%)
Mutual labels:  array

type-reverse

Build Status tested with jest Made in Nigeria

🦄 Lightweight reverse utility around strings, arrays, numbers and more.

Install

$ npm install --save type-reverse

Usage

const reverse = require('type-reverse')

or...

import reverse from 'type-reverse'

API

reverse( input[, options][, callback] )

Params

  • input {String|Number|Array|Set}
  • options {?Object}
  • callback {?Function}
  • returns {*}
reverse('pizza')
//=> azzip

Works with numbers too.

reverse(1234)
//=> 4321

Reversing arrays...

When 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.

native reverse...

const arr = [1, 2, 3]
arr.reverse() //=> [3, 2, 1]

Oops, we lost the indexes of elements in the initial array...

console.log(arr) //=> [3, 2, 1]

vs...

🦄 to the rescue...

const arr = [1, 2, 3]
reverse(arr) //=> [3, 2, 1]

Yay! arr is not mutated. The indexes of its elements are still maintained...

console.log(arr) //=> [1, 2, 3]

Sets

If 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...

const set = new Set([5, 4, 3, 4, 5])
reverse(set) //=> Set { 3, 4, 5 }

options

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.

invert: {String}

This property defaults to index and applies to strings and numbers only.

reverse(/*...*/, {
  invert: '[index|word|sign]'
})
  • index - interchanges the indexes of characters in the input...

    reverse(12345, { invert: 'index' }) //=> 54321
    reverse('of... unicorns', { invert: 'index' }) //=> snrocinu ...fo
  • sign - inverts the sign in a number...

    reverse(1234, { invert: 'sign' }) //=> -1234
  • word - swaps the location of words in a string...

    reverse('of... unicorns', { invert: 'word' }) //=> unicorns of...

preserveZeros: {Boolean}

This property defaults to true. It specifies whether to enforce preceding zeros in the result of a number that contains trailing zeros. See #3 for more info. Note that the result gets converted to a string. Disabling it would look like this...

reverse(240, { preserveZeros: false }) //=> 42

callback: {Function}

The callback takes in a function with two optional parameters that represent input and result respectively.

  • input - the initial input that was passed into the function
  • result - the output from reversing the input
const text = 'dog'

reverse(text, null, function(intitial, result) {
  return intitial + ' was changed to ' + result
}) //=> dog was changed to god

Limits

Did 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.

Author

Olaolu Olawuyi

License

MIT © Olaolu Olawuyi

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].