You should know the Node. js extension module-Hashish

Source: Internet
Author: User

BKJIA recommended topics: Node. js Zone

This article introduces the Node. js extension module Hashish. Hashish is a JavaScript Hash combination sub-database. In other words, it contains a series of data structure operation functions.

For example:

 
 
  1. var Hash = require('hashish');    
  2.    
  3. Hash({ a : 1, b : 2, c : 3, d : 4 })    
  4. .map(function (x) { return x * 10 })    
  5. .filter(function (x) { return x < 30 })    
  6. .forEach(function (x, key) {    
  7. console.log(key + ' => ' + x);    
  8. })    
  9. ;   

Here, the Hash structure is {a: 1, B: 2, c: 3, d: 4}. Next, map a function, and multiply each Hash value by 10, at this time, Hash is transformed into {a: 10, B: 20, c: 30, d: 40}. Then, filter out the values lower than 30. At this time, Hash is {: 10, B: 20}. Finally, forEach will operate on each practical value, and the output value is:

 
 
  1. a => 10    
  2. b => 20 

Note that Hash can manipulate each node and all the combinations can be combined to keep your code perfect.

If you cannot or do not want to use the connection function, hashish can also attach each link to the Hash. In this form:

 
 
  1. var Hash = require('hashish');    
  2. var obj = { a : 1, b : 2, c : 3, d : 4 };    
  3.    
  4. var mapped = Hash.map(obj, function (x) {    
  5.     return x * 10    
  6. });    
  7.    
  8. console.dir(mapped);  

Note that the Code on obj hash is called Hash. map. Multiply the Hash output value by 10:

{A: 10, B: 20, c: 30, d: 40}

In the Hash. xxx link, Hashish also provides various attributes of interfaces and functions. For example:

 
 
  1. $ node    
  2. > var Hash = require('hashish');    
  3. > var obj = { a : 1, b : 2, c : 3, d : 4 };    
  4. >   
  5. > Hash(obj).keys    
  6. [ 'a', 'b', 'c', 'd' ]    
  7. > Hash(obj).values    
  8. [ 1, 2, 3, 4 ]    
  9. > Hash(obj).length    
  10. 4   

Of course, you can install hashish through npm:

 
 
  1. npm install hashish  

This article introduces Hashish, the Node. js extension module. Do you understand?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.