Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

harakee

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

harakee - npm Package Compare versions

Comparing version 0.9.1 to 1.0.3

97

index.js

@@ -1,4 +0,95 @@

'use strict'
exports.decode = exports.parse = require('./decode')
exports.encode = exports.stringify = require('./encode')
module.exports = Harakee = {
toHex: (str) => {
let hex = ''
for (var i = 0; i < str.length; i++)
hex += ''+str.charCodeAt(i).toString(16)
return hex
},
fromHex: (hex) => {
hex = hex.toString(), str = ''
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16))
return str
},
encode: (obj, sep, eq, name) => {
sep = sep || '&'
eq = eq || '='
if (obj === null){ obj = undefined }
if (typeof obj === 'object'){
return Object.keys(obj).map((k) => {
let ks = encodeURIComponent(stringify(k)) + eq
if (Array.isArray(obj[k])){
return obj[k].map((v) => {
return ks + encodeURIComponent(stringify(v))
}).join(sep)
} else {
return ks + encodeURIComponent(stringify(obj[k]))
}
}).join(sep)
}
if (!name) return ''
return encodeURIComponent(stringify(name)) + eq + encodeURIComponent(stringify(obj))
},
decode: (qs, sep, eq, options) => {
sep = sep || '&'
eq = eq || '='
let obj = {}
if (typeof qs !== 'string' || qs.length === 0){
return obj
}
qs = qs.split(sep)
let maxKeys = 1000
if (options && typeof options.maxKeys === 'number'){
maxKeys = options.maxKeys
}
let len = qs.length
if (maxKeys > 0 && len > maxKeys){
len = maxKeys
}
for (let i = 0; i < len; ++i){
let x = qs[i].replace(regexp, '%20'),
idx = x.indexOf(eq),
kstr, vstr, k, v
if (idx >= 0){
kstr = x.substr(0, idx)
vstr = x.substr(idx + 1)
} else {
kstr = x
vstr = ''
}
k = decodeURIComponent(kstr)
v = decodeURIComponent(vstr)
if (!hasOwnProperty(obj, k)){
obj[k] = v
} else if (Array.isArray(obj[k])){
obj[k].push(v)
} else {
obj[k] = [obj[k], v]
}
}
return obj
}
}
let
stringify = (v) => {
switch (typeof v){
case 'string':
return v
case 'boolean':
return v ? 'true' : 'false'
case 'number':
return isFinite(v) ? v : ''
default:
return ''
}
},
hasOwnProperty = (obj, prop) => {
return Object.prototype.hasOwnProperty.call(obj, prop)
}

4

package.json
{
"name": "harakee",
"version": "0.9.1",
"version": "1.0.3",
"description": "Utilities for parsing and formatting query strings.",

@@ -11,2 +11,4 @@ "main": "switch.js",

"keywords": [
"string",
"hex",
"query",

@@ -13,0 +15,0 @@ "formatting",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc