{"_id":"nodutils","_rev":"57-d6d6d1567802742b6c8dbd5cb0ef4167","name":"nodutils","description":"Node utilities to manage common operations over: string, numeric, array, date, file, url, cache, properties files, geocoding","dist-tags":{"latest":"0.1.5"},"versions":{"0.1.1":{"author":{"name":"davidayalas"},"name":"nodutils","description":"Node utilities to manage common operations over: string, numeric, array, date, file, url, cache, properties files","keywords":["utilities","cache","caching","properties","url","file","string","number","array","date"],"version":"0.1.1","repository":{"url":"git://github.com/davidayalas/nodutils.git","type":"git"},"main":"./index.js","bin":{},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"davidayalas","email":"davixyz@gmail.com"},"_id":"nodutils@0.1.1","_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"81d5184dbaefd3f081665718fb0f4f4a70a9fe84","tarball":"https://registry.npmjs.org/nodutils/-/nodutils-0.1.1.tgz","integrity":"sha512-qp0wrQOYmqJ+xe2zXZPVwh8Jj+lQQVGzvEANC8ydJGjiw2+hDbVKaldnFejfO8+jVexyNESmup+jmeypByz5jg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCEsTPvqoT6HKFVRL0FstJ58Ftr+BnAxmirlB95F8tMtgIhAN6RBDKoD7pxWuBSNdU79MAYkYUiK1AK0RB15/rxGZe1"}]},"maintainers":[{"name":"davidayalas","email":"davixyz@gmail.com"}],"directories":{}},"0.1.2":{"author":{"name":"davidayalas"},"name":"nodutils","description":"Node utilities to manage common operations over: string, numeric, array, date, file, url, cache, properties files, geocoding","keywords":["utilities","cache","caching","properties","url","file","string","number","array","date","geo","geocoding","reverse geocoding"],"version":"0.1.2","repository":{"url":"git://github.com/davidayalas/nodutils.git","type":"git"},"main":"./index.js","bin":{},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"davidayalas","email":"davixyz@gmail.com"},"_id":"nodutils@0.1.2","_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"5ae06d1be837b8246bc29b7fe3e12815be8fbb4a","tarball":"https://registry.npmjs.org/nodutils/-/nodutils-0.1.2.tgz","integrity":"sha512-4QRa/MxDZxYXkOvdP64pPjV3KoBpZYWWUBfUxdBoWU+/n7DTT82t/ZoiDzwe1BhNfBGm6PfZcP0ba931fc+HkA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBVt86XI6jzb/WUdwV4iXZk025M0BDqWio4K0U9SasaDAiEAmbYQUOefSmI08dqzrdr792V0k2jgf09ip88X8p+d6RI="}]},"maintainers":[{"name":"davidayalas","email":"davixyz@gmail.com"}],"directories":{}},"0.1.3":{"author":{"name":"davidayalas"},"name":"nodutils","description":"Node utilities to manage common operations over: string, numeric, array, date, file, url, cache, properties files, geocoding","keywords":["utilities","cache","caching","properties","url","file","string","number","array","date","geo","geocoding","reverse geocoding"],"version":"0.1.3","repository":{"url":"git://github.com/davidayalas/nodutils.git","type":"git"},"main":"./index.js","bin":{},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"davidayalas","email":"davixyz@gmail.com"},"_id":"nodutils@0.1.3","_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"72ccc71b589572106cb71f597d67bbcb6253c020","tarball":"https://registry.npmjs.org/nodutils/-/nodutils-0.1.3.tgz","integrity":"sha512-U0x7sa3bhGCYo/6DP7wtJbIxUcY+zwAWD1yvWNT9UsYa+1DJg4O8SPkcEn5Xo2B0AybWk7xJtgXIUNzlYBrbHA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDJI8pxiUqqsE7ugfnqUL23LAiA/Fm/gvb7J0+iFK8w4QIgOFADEMER6CSB+Yer9DNl40bXnAxWl8icCd/hVj93aYY="}]},"maintainers":[{"name":"davidayalas","email":"davixyz@gmail.com"}],"directories":{}},"0.1.4":{"author":{"name":"davidayalas"},"name":"nodutils","description":"Node utilities to manage common operations over: string, numeric, array, date, file, url, cache, properties files, geocoding","keywords":["utilities","cache","caching","properties","url","file","string","number","array","date","geo","geocoding","reverse geocoding"],"version":"0.1.4","repository":{"url":"https://github.com/davidayalas/nodutils/","type":"git"},"main":"./index.js","bin":{},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"Utilities for NodeJS\n====================\n\n- [Installation](#installation)\n- [Usage](#usage)\n- Packages:\n\t+ [String](#string)\n\t+ [Number](#number)\n\t+ [Array](#array)\n\t+ [Date](#date)\n\t+ [File](#file)\n\t+ [Url](#url)\n\t+ [Cache ](#cache-)\n\t+ [Properties](#properties)\n\t+ [Geo](#geo)\n- [Code samples](#samples)\n\nInstallation\n-------------\n\n\t\t\t\tnpm install nodutils\n\nUsage\n------\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\nString\n-------\n\n-\tutils.string.**trim**(str) or String.**trim**()\n\n-\tutils.string.**ltrim**(str) or String.**trim**()\n\n-\tutils.string.**rtrim**(str) or String.**trim**()\n\n-\tutils.string.**toi**(str) or String.**toi**()\n\n\t+\tConverts to integer<br />  \n\n-\tutils.string.**tof**(str[,decimals]) or String.**tof**([decimals])\n\n\t+\tConverts to float, with number of decimals<br />  \n\n-\tutils.string.**dropDiacritics**(str) or String.**dropDiacritics**()\n\n\t+\tConverts accents, diacritics into a plain letter<br />  \n\n-\tutils.string.**isNumber**(str) or String.**isNumber**()\n\n-\tutils.string.**stripHtml**(str) or String.**stripHtml**()\n\n\t+\tStrip all html tags and leaves only text<br />  \n\n-\tutils.string.**count**(str,substr[,flags]) or String.**count**(substr[,flags]). \n\n\t+\tIt counts the number of ocurrences of substr. Flags can be \"i\" (ignore case) and/or \"d\" (drop accents)<br />                                                                                  \n-\tutils.string.**reverse**(str) or String.**reverse**()\n\n-\tutils.string.**toHtml**(str) or String.**toHtml**() \n\n\t+\tConverts diacritics and almost all chars into html entities<br />  \n\n-\tutils.string.**fromHtml**(str) or String.**fromHtml**() \n\n\t+\tConverts into diacritics html encoded entities\n\nNumber\n--------\n\n-\tutils.number.**round**(num[,decimals]) or Number.**round**([decimals])\n\n\t+\tRounds number to the given number of decimals\n\nArray\n------\n\n- utils.array.**max**(array) or Array.**max**()\n\n\t+\tReturns the max value in an array of numbers<br />  \n\n- utils.array.**min**(array) or Array.**min**()\n\n\t+\tReturns the min value in an array of numbers<br />  \n\n- utils.array.**uniques**(array) or Array.**uniques**()\n\n\t+\tReturns an array of uniques values in the original array<br />  \n\n- utils.array.**aggregate**(array) or Array.**aggregate**()\n\n\t+\tReturns an array of uniques values and counts its occurrences, sorted descending [(sample code)](#sample2)\n\n\t\t\t\t[\"a\",\"b\",\"c\",\"d\",1,2,\"a\",\"b\",\"c\",\"a\",\"b\",\"a\",1,0,1].aggregate();\n\n\t\t\t\treturned array\n\t\t\t\t\n\t\t\t\t[ [ 'a', 4 ], [ '1', 3 ], [ 'b', 3 ], [ 'c', 2 ], [ '0', 1 ], [ '2', 1 ], [ 'd', 1 ] ]\n\n- utils.array.**contains**(array,value[,flags]) or Array.**contains**(value[,flags])\n\n\t+\tReturns true or false\n\n\t+\tFlags can be \"i\" (ignore case) and/or \"d\" (drop accents)<br />\n\t\t\t\t\n\nDate\n-----\n\n-\tutils.date.**diff**(date1,date2[,unit]) \n\n\t+\tUnit = \"d\": days,\"h\": hours,\"m\": minutes,\"s\": seconds. Default unit is millis<br />  \n\n-\tutils.date.**millis**([date]) \n\n\t+\tReturns a timestamp in millis from current date or date passed as param (string or date object)<br />  \n\n-\tutils.date.**frommillis**(millis) \n\n\t+\tReturns a date object from millis passed as parameter\n\n\nFile\n-----\n\n-\tutils.file.**write**(file,data[,options],function(err){}) \n\n\t+\toptions = \"w\" write or \"a\" append<br />  \n\n-\tutils.file.**read**(file[,encoding],function(err,data){})\n\t\n-\tutils.file.**exists**(file,function(exists){}) \n\n\t+ exists: true or false\n\n-\tutils.file.**getModTime**(file,function(date){})\n\n\t+\tDate object is given to the callback as an argument<br />  \n\n-\tutils.file.**remove**(file,callback)\n\n-\tutils.file.**createpath**(path,callback)\n\nUrl\n----\n\t\t\t\t//get sample\n\t\t\t\tutils.url.get(\"www.bbc.com\",function(html){\n\t\t\t\t\tif(html){\n\t\t\t\t\t\tconsole.log(html);\n\t\t\t\t\t}\n\t\t\t\t});\t\t\t\n\n\t\t\t\t//post sample\n\t\t\t\tutils.url.post('httpbin.org/post',{post_data:{data:'lorem ipsum dolor sit amet'}}, \n\t\t\t\t\tfunction(resp){\n\t\t\t\t\t\tif(resp){\n\t\t\t\t\t\t\tconsole.log(resp);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\t\n-\tutils.url.**get**(url[,options],function(content,statuscode,headers){}) \n\n-\tutils.url.**post**(url[,options],function(content,statuscode,headers){}) \n\n\t+\tSupport for **http** and **https**\n\t+\tSupport for **proxy requests** (in url. E.g: \"url\"=http://www.proxy.com:8080/www.urltobeproxied.com)\n\t+\tIt is possible to set only url or options, but options need to set host, path, ...\n\t+\tOptions is an object with some props:\n\n\t\t*\t\"encoding\" default is \"utf-8\"\n\t\t*\t\"post_data\" (for post()) is an object \n\n\t\t\twith the vars (post_data:{a:1,b:2})  \n\n\t\t\tor with the body in \"data\" key (post_data:{data:\"whatever\"})  \n\n\t\t*\t\"headers\" (object)\n\t\t*\t\"auth\" (string)\n\t\t*\t\"forceparse\": if the url is with proxy data is better to set to true\n\nCache \n------\n\n-\tutils.cache.**getPath**()  \n\n\t+\tGet the current cache dir (default is \"./cache\")<br />  \n\n-\tutils.cache.**setPath**(path,callback)\n\n\t+\tSet the cache dir (and create if it doesn't exists)\n\t\n\t+\tIt's recommended to use absolute paths (\"/apps/myapp/cache\")<br />  \n\n-\tutils.cache.**setOptions**({path : \"/mypath\", size : 1}},callback)\n\n\t+\tSet the cache dir (and create if it doesn't exists) and cache max size\n\t\n\t+\tCache size is in MB<br />  \n\n-\tutils.cache.**set**(key,data[,expiretime],callback) \n\n\t+\tExpiretime is in seconds. If not informed, then unlimited <br />  \n\n-\tutils.cache.**get**(key,function(value){})\n\n-\tutils.cache.**remove**(key,callback)\n\n[(sample code)](#sample1)\n\nProperties\n-----------\n\n- utils.props.**load**(path_to_file,function(props){})\n\n\t+ properties in the file are loaded into a JSON object passed in callback\n\t\n\t+ Format of the properties file is \n\n\t\t\t\tkey1=value1\n\t\t\t\tkey2=value2\n\t\t\t\tkey3=value3\n\t\t\t\tkey4=123456789\n\n- utils.props.**save**(path_to_file,properties,callback)\n\t\n\t+ properties param is a json object. You can save properties dynamically\n\n\nGeo\n----\n\nUtilities for basic geocoding and checking distance between points. Limited to Google and Yahoo API limits, but you could geocode 50.000 addresses/points for Yahoo and 2.500 for Google. Utils.geo will use one or other depending of availability of the service. [(sample code)](#sample3)\n\n- utils.geo.**getDistance**(point1,point2[,earthRadius])\n\n\t+ Calculates the distance between point1 and point2. Points are arrays: [latitude,longitude]\n\n\t+ Distance is in km.\n\n\t+ earthRadius default is 6371 km. <br />  \n\n- utils.geo.**isInside**(point,center,radius[,earthRadius])\n\t\n\t+ Checks if a point (array of two positions [latitude,longitude]) is inside a circle (center + radius). Center is an array of two positions.\n\n\t+ radius is in KM\n\n\t+ earthRadius default is 6371 km. <br />  \n\n- utils.geo.**geocode**(address,options,callback)\n\n\t+ Returns an array of two positions [latitude,longitude] for the given address. <br />  \n\n- utils.geo.**rgeocode**(latitude,longitude,options,callback)\n\n\t+ Reverse geocode. Returns an object for the given latitude and longitude. <br />  \n\nBoth, geocode and rgeocode return the same object\t\n\n\t\t\t\t{ \n\t\t\t\t\tnumber : 'xxxxxxxxxxxx',\n\t\t\t\t\tstreet: 'xxxxxxxxxxxx',\n\t\t\t\t\tpostal: 'xxxxxxxxxxxx',\n\t\t\t\t\tcity: 'xxxxxxxxxxxx',\n\t\t\t\t\tcounty: 'xxxxxxxxxxxx',\n\t\t\t\t\tstate: 'xxxxxxxxxxxx',\n\t\t\t\t\tcountry: 'xxxxxxxxxxxx',\n\t\t\t\t\tlat: 1.11,\n\t\t\t\t\tlon: 2.22 \n\t\t\t\t}\n\nYou can set the locale in the options object {\"locale\" : \"en_GB\"}\n\nSamples\n--------\n\n-\t<a id=\"sample1\" name=\"sample1\"> </a>Caching twitter request due to twitter api limits (it uses **url** and **cache** utilities)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\t\t\t\tvar twitterquery = \"davidayalas\";\n\t\t\t\tvar twitterurl = \"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=\";\n\n\t\t\t\tutils.cache.get(twitterquery, function(content){\n\t\t\t\t\tif(!content){\n\t\t\t\t\t\tutils.url.get(twitterurl+twitterquery,function(result){\n\t\t\t\t\t\t\tutils.cache.set(twitterquery,result,300);\n\t\t\t\t\t\t\tconsole.log(result);\n\t\t\t\t\t\t});\n\t\t\t\t\t}else{\n\t\t\t\t\t\tconsole.log(content);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\n- <a id=\"sample2\" name=\"sample2\"> </a>Easy \"tagcloud\" from url content (it uses **url**, **string** and **array** utilities)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\n\t\t\t\tutils.url.get(\"www.bbc.com\",function(content){\n\t\t\t\t\tvar topwords = [];\n\t\t\t\t\tif(content){\n\t\t\t\t\t\tvar topwords = content.stripHtml().split(\" \").aggregate().filter(function(i){\n\t\t\t\t\t\t\treturn i[0].length<=3 || i[0].indexOf(\"&\")>-1?false:true;\n\t\t\t\t\t\t}).slice(0,50);\n\t\t\t\t\t}\n\t\t\t\t\tconsole.log(topwords);\n\t\t\t\t});  \n\n- <a id=\"sample3\" name=\"sample3\"> </a>Calculate the distance between two unestructured addresses (it uses **geo**)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\n\t\t\t\tutils.geo.geocode(\"madrid,spain\", function(p1){\n\t\t\t\t\tutils.geo.geocode(\"barcelona,spain\", function(p2){\n\t\t\t\t\t\tconsole.log(\"distance between Madrid and Barcelona is: \");\n\t\t\t\t\t\tif(p1 && p2){\n\t\t\t\t\t\t\tconsole.log(utils.geo.getDistance([p1.lat, p1.lon],[p2.lat, p2.lon]) + \" km\");\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\n- Simple http server for [caching and serve only valid twitter users](https://github.com/davidayalas/nodutils/blob/master/samples/simple-twitter-cache-server.js) (stored in properties file)\n\n- [Bulk geocode](https://github.com/davidayalas/nodutils/blob/master/samples/bulk-geocode.js) from url content. Tested with more than 5000 addresses. (it uses **geo**, **url**, **string**, **file**)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\n\t\t\t\tutils.url.get(\"http://w20.bcn.cat/opendata/DonaRecurs.aspx?arbre=general&recurs=TAULA_CARRERS&fitxer=1121\",{\"encoding\":\"iso-8859-1\"}, function(content,code){\n\t\t\t\t\tif(content){\n\t\t\t\t\t\tcontent.split(\"\\r\\n\").forEach(\n\t\t\t\t\t\t\tfunction(element, index, array){\n\t\t\t\t\t\t\t\tvar add = element.slice(element.lastIndexOf(\";\")+1);\n\t\t\t\t\t\t\t\tif(add){\t\n\t\t\t\t\t\t\t\t\tutils.geo.geocode((add.count(\"carrer\",\"i\")>0?add:\"Carrer \"+add)+\",barcelona,spain\", function(p){\n\t\t\t\t\t\t\t\t\t\tif(p && typeof(p)==\"object\" && p.lat && p.lon){\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(element + \";\" + p.lat + \";\" + p.lon);\n\t\t\t\t\t\t\t\t\t\t\tutils.file.write(__dirname + \"/geocoded-addresses.txt\", element + \";\" + p.lat + \";\" + p.lon + \"\\r\\n\", \"a\");\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t});\n\n","_id":"nodutils@0.1.4","dist":{"shasum":"5721fd22563c8bffc1638eb04f1550396b45df09","tarball":"https://registry.npmjs.org/nodutils/-/nodutils-0.1.4.tgz","integrity":"sha512-6lrqLn8zYNZ4dPrOR2puVdkEdFgce9Da0lfPWaoKLiVcGeDvp5tcRHMbSYb+IVBye6fnvOuHO/bZ/ns6Jl9oOg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCTQ7hLUVdSCVo/nr7kEn5x5UrZVy2y9p7kEc5YBWT9dQIhAOuk/vLZ+bTMNp75t0mOl8Lo8aV5oxc/siE2VNWjEWCG"}]},"_npmVersion":"1.1.61","_npmUser":{"name":"davidayalas","email":"davixyz@gmail.com"},"maintainers":[{"name":"davidayalas","email":"davixyz@gmail.com"}]},"0.1.5":{"author":{"name":"davidayalas"},"name":"nodutils","description":"Node utilities to manage common operations over: string, numeric, array, date, file, url, cache, properties files, geocoding","keywords":["utilities","cache","caching","properties","url","file","string","number","array","date","geo","geocoding","reverse geocoding"],"version":"0.1.5","repository":{"url":"https://github.com/davidayalas/nodutils/","type":"git"},"main":"./index.js","bin":{},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"Utilities for NodeJS\n====================\n\n- [Installation](#installation)\n- [Usage](#usage)\n- Packages:\n\t+ [String](#string)\n\t+ [Number](#number)\n\t+ [Array](#array)\n\t+ [Date](#date)\n\t+ [File](#file)\n\t+ [Url](#url)\n\t+ [Cache ](#cache-)\n\t+ [Properties](#properties)\n\t+ [Geo](#geo)\n- [Code samples](#samples)\n\nInstallation\n-------------\n\n\t\t\t\tnpm install nodutils\n\nUsage\n------\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\nString\n-------\n\n-\tutils.string.**trim**(str) or String.**trim**()\n\n-\tutils.string.**ltrim**(str) or String.**trim**()\n\n-\tutils.string.**rtrim**(str) or String.**trim**()\n\n-\tutils.string.**toi**(str) or String.**toi**()\n\n\t+\tConverts to integer<br />  \n\n-\tutils.string.**tof**(str[,decimals]) or String.**tof**([decimals])\n\n\t+\tConverts to float, with number of decimals<br />  \n\n-\tutils.string.**dropDiacritics**(str) or String.**dropDiacritics**()\n\n\t+\tConverts accents, diacritics into a plain letter<br />  \n\n-\tutils.string.**isNumber**(str) or String.**isNumber**()\n\n-\tutils.string.**stripHtml**(str) or String.**stripHtml**()\n\n\t+\tStrip all html tags and leaves only text<br />  \n\n-\tutils.string.**count**(str,substr[,flags]) or String.**count**(substr[,flags]). \n\n\t+\tIt counts the number of ocurrences of substr. Flags can be \"i\" (ignore case) and/or \"d\" (drop accents)<br />                                                                                  \n-\tutils.string.**reverse**(str) or String.**reverse**()\n\n-\tutils.string.**toHtml**(str) or String.**toHtml**() \n\n\t+\tConverts diacritics and almost all chars into html entities<br />  \n\n-\tutils.string.**fromHtml**(str) or String.**fromHtml**() \n\n\t+\tConverts into diacritics html encoded entities\n\nNumber\n--------\n\n-\tutils.number.**round**(num[,decimals]) or Number.**round**([decimals])\n\n\t+\tRounds number to the given number of decimals\n\nArray\n------\n\n- utils.array.**max**(array) or Array.**max**()\n\n\t+\tReturns the max value in an array of numbers<br />  \n\n- utils.array.**min**(array) or Array.**min**()\n\n\t+\tReturns the min value in an array of numbers<br />  \n\n- utils.array.**uniques**(array) or Array.**uniques**()\n\n\t+\tReturns an array of uniques values in the original array<br />  \n\n- utils.array.**aggregate**(array) or Array.**aggregate**()\n\n\t+\tReturns an array of uniques values and counts its occurrences, sorted descending [(sample code)](#sample2)\n\n\t\t\t\t[\"a\",\"b\",\"c\",\"d\",1,2,\"a\",\"b\",\"c\",\"a\",\"b\",\"a\",1,0,1].aggregate();\n\n\t\t\t\treturned array\n\t\t\t\t\n\t\t\t\t[ [ 'a', 4 ], [ '1', 3 ], [ 'b', 3 ], [ 'c', 2 ], [ '0', 1 ], [ '2', 1 ], [ 'd', 1 ] ]\n\n- utils.array.**contains**(array,value[,flags]) or Array.**contains**(value[,flags])\n\n\t+\tReturns true or false\n\n\t+\tFlags can be \"i\" (ignore case) and/or \"d\" (drop accents)<br />\n\t\t\t\t\n\nDate\n-----\n\n-\tutils.date.**diff**(date1,date2[,unit]) \n\n\t+\tUnit = \"d\": days,\"h\": hours,\"m\": minutes,\"s\": seconds. Default unit is millis<br />  \n\n-\tutils.date.**millis**([date]) \n\n\t+\tReturns a timestamp in millis from current date or date passed as param (string or date object)<br />  \n\n-\tutils.date.**frommillis**(millis) \n\n\t+\tReturns a date object from millis passed as parameter\n\n\nFile\n-----\n\n-\tutils.file.**write**(file,data[,options],function(err){}) \n\n\t+\toptions = \"w\" write or \"a\" append<br />  \n\n-\tutils.file.**read**(file[,encoding],function(err,data){})\n\t\n-\tutils.file.**exists**(file,function(exists){}) \n\n\t+ exists: true or false\n\n-\tutils.file.**getModTime**(file,function(date){})\n\n\t+\tDate object is given to the callback as an argument<br />  \n\n-\tutils.file.**remove**(file,callback)\n\n-\tutils.file.**createpath**(path,callback)\n\nUrl\n----\n\t\t\t\t//get sample\n\t\t\t\tutils.url.get(\"www.bbc.com\",function(html){\n\t\t\t\t\tif(html){\n\t\t\t\t\t\tconsole.log(html);\n\t\t\t\t\t}\n\t\t\t\t});\t\t\t\n\n\t\t\t\t//post sample\n\t\t\t\tutils.url.post('httpbin.org/post',{post_data:{data:'lorem ipsum dolor sit amet'}}, \n\t\t\t\t\tfunction(resp){\n\t\t\t\t\t\tif(resp){\n\t\t\t\t\t\t\tconsole.log(resp);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\t\n-\tutils.url.**get**(url[,options],function(content,statuscode,headers){}) \n\n-\tutils.url.**post**(url[,options],function(content,statuscode,headers){}) \n\n\t+\tSupport for **http** and **https**\n\t+\tSupport for **proxy requests** (in url. E.g: \"url\"=http://www.proxy.com:8080/www.urltobeproxied.com)\n\t+\tIt is possible to set only url or options, but options need to set host, path, ...\n\t+\tOptions is an object with some props:\n\n\t\t*\t\"encoding\" default is \"utf-8\"\n\t\t*\t\"post_data\" (for post()) is an object \n\n\t\t\twith the vars (post_data:{a:1,b:2})  \n\n\t\t\tor with the body in \"data\" key (post_data:{data:\"whatever\"})  \n\n\t\t*\t\"headers\" (object)\n\t\t*\t\"auth\" (string)\n\t\t*\t\"forceparse\": if the url is with proxy data is better to set to true\n\nCache \n------\n\n-\tutils.cache.**getPath**()  \n\n\t+\tGet the current cache dir (default is \"./cache\")<br />  \n\n-\tutils.cache.**setPath**(path,callback)\n\n\t+\tSet the cache dir (and create if it doesn't exists)\n\t\n\t+\tIt's recommended to use absolute paths (\"/apps/myapp/cache\")<br />  \n\n-\tutils.cache.**setOptions**({path : \"/mypath\", size : 1}},callback)\n\n\t+\tSet the cache dir (and create if it doesn't exists) and cache max size\n\t\n\t+\tCache size is in MB<br />  \n\n-\tutils.cache.**set**(key,data[,expiretime],callback) \n\n\t+\tExpiretime is in seconds. If not informed, then unlimited <br />  \n\n-\tutils.cache.**get**(key,function(value){})\n\n-\tutils.cache.**remove**(key,callback)\n\n[(sample code)](#sample1)\n\nProperties\n-----------\n\n- utils.props.**load**(path_to_file,function(props){})\n\n\t+ properties in the file are loaded into a JSON object passed in callback\n\t\n\t+ Format of the properties file is \n\n\t\t\t\tkey1=value1\n\t\t\t\tkey2=value2\n\t\t\t\tkey3=value3\n\t\t\t\tkey4=123456789\n\n- utils.props.**save**(path_to_file,properties,callback)\n\t\n\t+ properties param is a json object. You can save properties dynamically\n\n\nGeo\n----\n\nUtilities for basic geocoding and checking distance between points. Limited to Google and Yahoo API limits, but you could geocode 50.000 addresses/points for Yahoo and 2.500 for Google. Utils.geo will use one or other depending of availability of the service. [(sample code)](#sample3)\n\n- utils.geo.**getDistance**(point1,point2[,earthRadius])\n\n\t+ Calculates the distance between point1 and point2. Points are arrays: [latitude,longitude]\n\n\t+ Distance is in km.\n\n\t+ earthRadius default is 6371 km. <br />  \n\n- utils.geo.**isInside**(point,center,radius[,earthRadius])\n\t\n\t+ Checks if a point (array of two positions [latitude,longitude]) is inside a circle (center + radius). Center is an array of two positions.\n\n\t+ radius is in KM\n\n\t+ earthRadius default is 6371 km. <br />  \n\n- utils.geo.**geocode**(address,options,callback)\n\n\t+ Returns an array of two positions [latitude,longitude] for the given address. <br />  \n\n- utils.geo.**rgeocode**(latitude,longitude,options,callback)\n\n\t+ Reverse geocode. Returns an object for the given latitude and longitude. <br />  \n\nBoth, geocode and rgeocode return the same object\t\n\n\t\t\t\t{ \n\t\t\t\t\tnumber : 'xxxxxxxxxxxx',\n\t\t\t\t\tstreet: 'xxxxxxxxxxxx',\n\t\t\t\t\tpostal: 'xxxxxxxxxxxx',\n\t\t\t\t\tcity: 'xxxxxxxxxxxx',\n\t\t\t\t\tcounty: 'xxxxxxxxxxxx',\n\t\t\t\t\tstate: 'xxxxxxxxxxxx',\n\t\t\t\t\tcountry: 'xxxxxxxxxxxx',\n\t\t\t\t\tlat: 1.11,\n\t\t\t\t\tlon: 2.22 \n\t\t\t\t}\n\nYou can set the locale in the options object {\"locale\" : \"en_GB\"}\n\nSamples\n--------\n\n-\t<a id=\"sample1\" name=\"sample1\"> </a>Caching twitter request due to twitter api limits (it uses **url** and **cache** utilities)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\t\t\t\tvar twitterquery = \"davidayalas\";\n\t\t\t\tvar twitterurl = \"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=\";\n\n\t\t\t\tutils.cache.get(twitterquery, function(content){\n\t\t\t\t\tif(!content){\n\t\t\t\t\t\tutils.url.get(twitterurl+twitterquery,function(result){\n\t\t\t\t\t\t\tutils.cache.set(twitterquery,result,300);\n\t\t\t\t\t\t\tconsole.log(result);\n\t\t\t\t\t\t});\n\t\t\t\t\t}else{\n\t\t\t\t\t\tconsole.log(content);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\n- <a id=\"sample2\" name=\"sample2\"> </a>Easy \"tagcloud\" from url content (it uses **url**, **string** and **array** utilities)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\n\t\t\t\tutils.url.get(\"www.bbc.com\",function(content){\n\t\t\t\t\tvar topwords = [];\n\t\t\t\t\tif(content){\n\t\t\t\t\t\tvar topwords = content.stripHtml().split(\" \").aggregate().filter(function(i){\n\t\t\t\t\t\t\treturn i[0].length<=3 || i[0].indexOf(\"&\")>-1?false:true;\n\t\t\t\t\t\t}).slice(0,50);\n\t\t\t\t\t}\n\t\t\t\t\tconsole.log(topwords);\n\t\t\t\t});  \n\n- <a id=\"sample3\" name=\"sample3\"> </a>Calculate the distance between two unestructured addresses (it uses **geo**)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\n\t\t\t\tutils.geo.geocode(\"madrid,spain\", function(p1){\n\t\t\t\t\tutils.geo.geocode(\"barcelona,spain\", function(p2){\n\t\t\t\t\t\tconsole.log(\"distance between Madrid and Barcelona is: \");\n\t\t\t\t\t\tif(p1 && p2){\n\t\t\t\t\t\t\tconsole.log(utils.geo.getDistance([p1.lat, p1.lon],[p2.lat, p2.lon]) + \" km\");\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t});\n\n- Simple http server for [caching and serve only valid twitter users](https://github.com/davidayalas/nodutils/blob/master/samples/simple-twitter-cache-server.js) (stored in properties file)\n\n- [Bulk geocode](https://github.com/davidayalas/nodutils/blob/master/samples/bulk-geocode.js) from url content. Tested with more than 5000 addresses. (it uses **geo**, **url**, **string**, **file**)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\n\t\t\t\tutils.url.get(\"http://w20.bcn.cat/opendata/DonaRecurs.aspx?arbre=general&recurs=TAULA_CARRERS&fitxer=1121\",{\"encoding\":\"iso-8859-1\"}, function(content,code){\n\t\t\t\t\tif(content){\n\t\t\t\t\t\tcontent.split(\"\\r\\n\").forEach(\n\t\t\t\t\t\t\tfunction(element, index, array){\n\t\t\t\t\t\t\t\tvar add = element.slice(element.lastIndexOf(\";\")+1);\n\t\t\t\t\t\t\t\tif(add){\t\n\t\t\t\t\t\t\t\t\tutils.geo.geocode((add.count(\"carrer\",\"i\")>0?add:\"Carrer \"+add)+\",barcelona,spain\", function(p){\n\t\t\t\t\t\t\t\t\t\tif(p && typeof(p)==\"object\" && p.lat && p.lon){\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(element + \";\" + p.lat + \";\" + p.lon);\n\t\t\t\t\t\t\t\t\t\t\tutils.file.write(__dirname + \"/geocoded-addresses.txt\", element + \";\" + p.lat + \";\" + p.lon + \"\\r\\n\", \"a\");\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t});\n\n","readmeFilename":"README.md","_id":"nodutils@0.1.5","dist":{"shasum":"fcd52c943ede810c1bbb30cebf7db51b3877c3af","tarball":"https://registry.npmjs.org/nodutils/-/nodutils-0.1.5.tgz","integrity":"sha512-pzahpZPCbsGD5J8RATMnv9dpJGSORUcPkoADykqmRPfD8rdmGSBKVtxny63zWxULbQEtORAX1Ces6dYqekuVdA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCemIS/xPJmVdnIWgRZjRJNOj5DeKA91cEEQ/FtnWo3kQIgMQdRr2YScyWHR6CjBgYXZoR1QSvPcI7agQ1ktlSxtoM="}]},"_from":"node-utils","_npmVersion":"1.2.11","_npmUser":{"name":"davidayalas","email":"davixyz@gmail.com"},"maintainers":[{"name":"davidayalas","email":"davixyz@gmail.com"}]}},"readme":"Utilities for NodeJS\n====================\n\nInstallation\n-------------\n\nnpm install nodutils\n\nUsage\n------\n\nvar utils = require(\"nodutils\");\n\nString\n-------\n\n-\tutils.string.**trim**(str) or String.**trim**()\n\n-\tutils.string.**ltrim**(str) or String.**trim**()\n\n-\tutils.string.**rtrim**(str) or String.**trim**()\n\n-\tutils.string.**toi**(str) or String.**toi**()\n\n\t+\tConverts to integer<br />  \n\n-\tutils.string.**tof**(str[,decimals]) or String.**tof**([decimals])\n\n\t+\tConverts to float, with number of decimals<br />  \n\n-\tutils.string.**dropDiacritics**(str) or String.**dropDiacritics**()\n\n\t+\tConverts accents, diacritics into a plain letter<br />  \n\n-\tutils.string.**isNumber**(str) or String.**isNumber**()\n\n-\tutils.string.**stripHtml**(str) or String.**stripHtml**()\n\n\t+\tStrip all html tags and leaves only text<br />  \n\n-\tutils.string.**contains**(str,substr[,flags]) or String.**contains**(substr[,flags]). \n\n\t+\tIt counts the number of ocurrences of substr. Flags can be \"i\" (ignore case) and/or \"d\" (drop accents)<br />                                                                                  \n-\tutils.string.**reverse**(str) or String.**reverse**()\n\n-\tutils.string.**toHtml**(str) or String.**toHtml**() \n\n\t+\tConverts diacritics and almost all chars into html entities<br />  \n\n-\tutils.string.**fromHtml**(str) or String.**fromHtml**() \n\n\t+\tConverts into diacritics html encoded entities\n\nNumeric\n--------\n\n-\tutils.number.**round**(num[,decimals]) or Number.**round**([decimals])\n\n\t+\tRounds number to the given number of decimals\n\nArray\n------\n\n- utils.array.**max**(array) or Array.**max**()\n\n\t+\tReturns the max value in an array of numbers<br />  \n\n- utils.array.**min**(array) or Array.**min**()\n\n\t+\tReturns the min value in an array of numbers<br />  \n\n- utils.array.**uniques**(array) or Array.**uniques**()\n\n\t+\tReturns an array of uniques values in the original array<br />  \n\n- utils.array.**aggregate**(array) or Array.**aggregate**()\n\n\t+\tReturns an array of uniques values and counts its occurrences, sorted descending [(sample code)](#sample2)\n\n\t\t\t\t//returned array\n\t\t\t\t[['itemX',15],['itemY',12],....]\n\n- utils.array.**contains**(array,value[,flags]) or Array.**contains**(value[,flags])\n\n\t+\tReturns the number of occurrences of \"value\"\n\n\t+\tFlags can be \"i\" (ignore case) and/or \"d\" (drop accents)<br />\n\t\t\t\t\n\nDate\n-----\n\n-\tutils.date.**diff**(date1,date2[,unit]) \n\n\t+\tUnit = \"d\": days,\"h\": hours,\"m\": minutes,\"s\": seconds. Default unit is millis<br />  \n\n-\tutils.date.**millis**([date]) \n\n\t+\tReturns a timestamp in millis from current date or date passed as param (string or date object)<br />  \n\n-\tutils.date.**frommillis**(millis) \n\n\t+\tReturns a date object from millis passed as parameter\n\n\nFile\n-----\n\n-\tutils.file.**write**(file,data[,options],callback) \n\n\t+\toptions = \"w\" write or \"a\" append<br />  \n\n-\tutils.file.**read**(file[,encoding],callback) \n\n-\tutils.file.**exists**(file,callback) \n\n-\tutils.file.**getModTime**(file,callback)\n\n\t+\tDate object is given to the callback as an argument<br />  \n\n-\tutils.file.**remove**(file,callback)\n\n-\tutils.file.**createpath**(path,callback)\n\nUrl\n----\n\t\t\t\t//get sample\n\t\t\t\tutils.url.get(\"www.bbc.com\",function(html){\n\t\t\t\t\tconsole.log(html);\n\t\t\t\t});\t\t\t\n\n\t\t\t\t//post sample\n\t\t\t\tutils.url.post('httpbin.org/post',{post_data:{data:'lorem ipsum dolor sit amet'}}, \n\t\t\t\t\tfunction(resp){\n\t\t\t\t\t\tconsole.log(resp);\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\t\n-\tutils.url.**get**(url[,options],callback) \n\n-\tutils.url.**post**(url[,options],callback) \n\n\t+\tSupport for **http** and **https**\n\t+\tSupport for **proxy requests** (in url. E.g: \"url\"=http://www.proxy.com:8080/www.urltobeproxied.com)\n\t+\tIt is possible to set only url or options, but options need to set host, path, ...\n\t+\tOptions is an object with some props:\n\n\t\t*\t\"encoding\" default is \"utf-8\"\n\t\t*\t\"post_data\" (for post()) is an object \n\n\t\t\twith the vars (post_data:{a:1,b:2})  \n\n\t\t\tor with the body in \"data\" key (post_data:{data:\"whatever\"})  \n\n\t\t*\t\"headers\" (object)\n\t\t*\t\"auth\" (string)\n\t\t*\t\"forceparse\": if the url is with proxy data is better to set to true\n\nCache \n------\n\n-\tutils.cache.**getPath**()  \n\n\t+\tGet the current cache dir (default is \"./cache\")<br />  \n\n-\tutils.cache.**setPath**(path,callback)\n\n\t+\tSet the cache dir (and create if it doesn't exists)\n\t\n\t+\tIt's recommended to use absolute paths (\"/apps/myapp/cache\")<br />  \n\n-\tutils.cache.**setOptions**({path : \"/mypath\", size : 1}},callback)\n\n\t+\tSet the cache dir (and create if it doesn't exists) and cache max size\n\t\n\t+\tCache size is in MB<br />  \n\n-\tutils.cache.**set**(key,data[,expiretime],callback) \n\n\t+\tExpiretime is in seconds. If not informed, then unlimited <br />  \n\n-\tutils.cache.**get**(key,callback)\n\n-\tutils.cache.**remove**(key,callback)\n\n[(sample code)](#sample1)\n\nProperties\n-----------\n\n- utils.props.**load**(path_to_file,callback)\n\n\t+ properties in the file are loaded into a JSON object passed in callback\n\t\n\t+ Format of the properties file is \n\n\t\t\t\tkey1=value1\n\t\t\t\tkey2=value2\n\t\t\t\tkey3=value3\n\t\t\t\tkey4=123456789\n\n- utils.props.**save**(path_to_file,properties,callback)\n\t\n\t+ properties param is a json object. You can save properties dynamically\n\n\nSamples\n--------\n\n-\t<a id=\"sample1\" name=\"sample1\"> </a>Caching twitter request due to twitter api limits (it uses **url** and **cache** utilities)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\t\t\t\tvar twitterquery = \"davidayalas\";\n\t\t\t\tvar twitterurl = \"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=\";\n\n\t\t\t\tutils.cache.get(twitterquery, function(content){\n\t\t\t\t\tif(!content){\n\t\t\t\t\t\tutils.url.get(twitterurl+twitterquery,function(result){\n\t\t\t\t\t\t\tutils.cache.set(twitterquery,result,300);\n\t\t\t\t\t\t\tconsole.log(result);\n\t\t\t\t\t\t});\n\t\t\t\t\t}else{\n\t\t\t\t\t\tconsole.log(content);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\n- <a id=\"sample2\" name=\"sample2\"> </a>Easy \"tagcloud\" from url content (it uses **url**, **string** and **array** utilities)\n\n\t\t\t\tvar utils = require(\"nodutils\");\n\n\t\t\t\tutils.url.get(\"www.bbc.com\",function(content){\n\t\t\t\t\tvar topwords = content.stripHtml().split(\" \").aggregate().filter(function(i){\n\t\t\t\t\t\treturn i[0].length<=3 || i[0].indexOf(\"&\")>-1?false:true;\n\t\t\t\t\t}).slice(0,50);\n\t\t\t\t\tconsole.log(topwords)\n\t\t\t\t});  \n","maintainers":[{"name":"davidayalas","email":"davixyz@gmail.com"}],"time":{"modified":"2022-06-22T04:15:25.585Z","created":"2012-09-03T16:56:00.196Z","0.1.1":"2012-09-03T16:56:01.914Z","0.1.2":"2012-09-05T17:21:36.267Z","0.1.3":"2012-09-07T09:18:33.592Z","0.1.4":"2012-09-18T13:00:36.931Z","0.1.5":"2013-03-01T19:32:27.755Z"},"author":{"name":"davidayalas"},"repository":{"url":"https://github.com/davidayalas/nodutils/","type":"git"}}