Socket
Socket
Sign inDemoInstall

eden-hash

Package Overview
Dependencies
6
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eden-hash

Eden Node JS Hash Methods


Version published
Maintainers
1
Install size
379 kB
Created

Readme

Source

#Hash

DESCRIPTION

Build Status

General

Installation

npm install eden-hash

Usage

var hash = require('eden-hash');

Methods


concat

 object concat(fname, lname ...);

Concats objects into one

Parameters
  1. fname - first object (string | character | integer | date)
  2. lname - second object to be concat in first object (string | character | integer | date)
Returns

object

Example
Code
  var fname = 'Eliz';
  var mi = 'B';
  var lname = 'Bragais';
  var age = 22;

fname.concat(lname);
fname.concat(' '.concat(mi.concat('.'.concat(' '.concat(lname)))));
fname+' '.concat(mi+'.'+' '+lname);
'Name:'+' '+fname+' '.concat(mi+'.'+' '+lname+'.'+' '+'Age:'+' '+age);
Outputs
'ElizBragais'
'Eliz B. Bragais'
'Eliz B. Bragais'
'Name: Eliz B. Bragais. Age: 22'

each

 bool each(key, value);

Custom for each loop that handles scopes and extra arguments

Parameters
  1. key - object

  2. value - function

Returns

bool

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};
      
  hashed().each(hash, function(key, value);

hash.hasOwnProperty(key);
value;
Outputs
true
hash[key]

indexOf

 number|false indexOf(hash, 6, Boolis.has, Object, Mixed);

Returns true if the array has given value

Parameters
  1. hash - object

  2. 6 - mixed (if key value in object)

  3. boolis.has - = function(data, value) {Argument Testingis.argument()est(1, 'object')est(2, 'mixed');turn !this.each(data, function(key, test) {turn !(test === value);;*Returns the index of where in the array the value is found

  4. object

  5. mixed

Returns

number|false

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};

hash().indexOf(hash, 6);
hash().indexOf(hash, 8);
Outputs
'test1'
false

implode

 string implode({test1:4,test2:6}, '-');

Join array elements with a string

Parameters
  1. {test1:4,test2:6} - object

  2. '-' - string (object separator)

Returns

string

Example
Code
hash().implode({test1:4,test2:6}, '-');
hash().implode({test1:4,test2:6}, '/');
Outputs
'4-6'
'4/6'

isEmpty

 bool isEmpty(hash);

Returns true if empty

Parameters
  1. hash - object (check if empty)
Returns

bool

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};
  var test = {};

hashed().isEmpty(hash);
hashed().isEmpty(test);
Outputs
false
true

isHash

 bool isHash(item1);

Returns true if given is hash

Parameters
  1. item1 - object (chech if it is hsh)
Returns

bool

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};

    var item1 = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};
    var item2 = Date;
    var item3 = RegExp;
    var item4 = Math;
    var item5 = Array;
    var item6 = Function;
    var item7 = JSON;
    var item8 = String;
    var item9 = Boolean;
    var item10 = Number;
    var item11 = new Date();
    var item12 = /[a-z]/;
    var item13 = [1, 2, 3, 4]
    var item14 = 'test';
    var item15 = true;
    var item16 = 123;
    var item17 = function() {};
    var item18 = null;

hash().isHash(item1);
hash().isHash(item2);
hash().isHash(item3);
hash().isHash(item4);
hash().isHash(item5);
hash().isHash(item6);
hash().isHash(item7);
hash().isHash(item8);
hash().isHash(item9);
hash().isHash(item10);
hash().isHash(item11);
hash().isHash(item12);
hash().isHash(item13);
hash().isHash(item14);
hash().isHash(item15);
hash().isHash(item16);
hash().isHash(item17);
hash().isHash(item18);
Outputs
true
false
false
false
false
false
false
false
false
false
false
false
false
false
false
false
false
false

keys

 array keys(keys[0]);

Returns a list of keys

Parameters
  1. keys[0] - object (key list)
Returns

array

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};
  var keys = hashed().keys(hash);

keys[0];
keys[1];
keys[3];
keys.length;
Outputs
'test1'
'test2'
'test4'
4

ksort

 object ksort({test3:9,test2:7,test1:6});

sorts hash by key

Parameters
  1. {test3:9,test2:7,test1:6} - object (ascending order by key)
Returns

object

Example
Code
  var result = hashed().ksort({test3:9,test2:7,test1:6});
  result = hashed().implode(result, '-');

hash().ksort(result);
Outputs
'6-7-9'

krsort

 object krsort({test2:7,test3:9,test1:6});

reverse sorts hash by key

Parameters
  1. {test2:7,test3:9,test1:6} - object (descending order by key)
Returns

object

Example
Code
  var result = hashed().krsort({test2:7,test3:9,test1:6});test1:6});
  result = hashed().implode(result, '-');

hash().krsort(result);

Outputs
'9-7-6'

map

 object map(hash, (key, value), hash.test2);

Custom map loop that handles scopes and extra arguments

Parameters
  1. hash - object (locate the key value)

  2. key, value - function

  3. hash.test2 - [mixed[,mixed..]]

Returns

object

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};
  hashed().map(hash, function(key, value) {
        if(typeof value != 'number') {
          return value;
        }
        return value + 1;
      });


hash.test2;
hash.test3;
Outputs
8
10

natksort

 object natksort({test2:9,test1:7});

Rearranges objects where keys are natural sorted

Parameters
  1. {test2:9,test1:7} - object (ascending order by key)
Returns

object

Example
Code
  var result = hashed().natksort({test2:9,test1:7});
  result = hashed().implode(result, '-');

hash().natksort(result);
Outputs
'7-9'

natsort

 object natsort({test2:9,test1:7});

Sorts array by natural sort

Parameters
  1. {test2:9,test1:7} - object (ascending order array by key)
Returns

object

Example
Code
  var result = hashed().natsort({test2:9,test1:7});
  result = hashed().implode(result, '-');

hash().natsort(result);
Outputs
'7-9'

reverse

 object reverse({test2:7,test3:9,test1:6});

Reverse sorts a hash with respect to its keys

Parameters
  1. {test2:7,test3:9,test1:6} - object (descending order by value)
Returns

object

Example
Code
  var result = hashed().reverse({test2:7,test3:9,test1:6});test1:6});
  result = hashed().implode(result, '-');

hash().reverse(result);

Outputs
'9-7-6'

size

 number size({test1:1,test:2});

Returns the size of the object

Parameters
  1. {test1:1,test:2} - object (count the given items)
Returns

number

Example
Code
hash().size({test1:1,test2:2});
Outputs
2

sort

 object sort({test3:4,test2:5,test1:1}, [callback]);

Sorts a hash with respect to its keys

Parameters
  1. {test3:4,test2:5,test1:1} - object (ascending order by values)

  2. [callback]

Returns

object

Example
Code
  var result = hashed().sort({test3:3,test2:2,test1:1});
  result = hashed().implode(result, '-');

hash().sort(result);
Outputs
'1-2-3'

toQuery

 string toQuery({test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]});

Converts array to query string

Parameters
  1. {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]} - object
Returns

string

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};

hash().toQuery(hash);
Outputs
'test1=6&test2=7&test3=9&test4[0]=1&test4[1]=2&test4[2]=3&test4[3]=4&test4[4]=5'

toString

 string toString({test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]});

Converts array to string

Parameters
  1. {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]} - object
Returns

string

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};

hash().toString(hash);
Outputs
'{"test1":6,"test2":7,"test3":9,"test4":[1,2,3,4,5]}'

values

 array values({test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]});

Returns a list of values

Parameters
  1. {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]} - object
Returns

array

Example
Code
  var hash = {test1: 6, test2: 7, test3: 9, test4: [1,2,3,4,5]};
  var values = hashed().values(hash);

values[0];
values[1];
values[2];
values[4];
values.length;
Outputs
6
7
9
undefined
4

Keywords

FAQs

Last updated on 01 Jun 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc