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

jsoun

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsoun - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

11

index.js

@@ -25,3 +25,3 @@ const links = [

function jsoun(json) {
function swap(json) {
for (let i = 0; i < links.length; i++) {

@@ -39,2 +39,9 @@ let r0 = createRegex(links[i][0])

module.exports = jsoun
module.exports = {
encode: function(obj) {
return encodeURI(swap(JSON.stringify(obj)))
},
decode: function(jsoun) {
return JSON.stringify(swap(encodeURI(obj)))
}
}

2

package.json
{
"name": "jsoun",
"version": "0.0.2",
"version": "0.1.0",
"description": "Ever wanted to put json in a url and thought it was ugly? JSOUN (Javascript Object URL Notation) makes it slightly better",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,66 +8,44 @@ Ever wanted to put JSON in a url? It's ugly, right?

```js
const jsoun = require('jsoun')
var JSOUN = require('./index.js')
var obj = {
"store":{
"book":[
{
"category":"reference",
"author":"Nigel Rees",
"title":"Sayings of the Century",
"price":8.95
},
{
"category":"fiction",
"author":"Evelyn Waugh",
"title":"Sword of Honour",
"price":12.99
},
{
"category":"fiction",
"author":"J. R. R. Tolkien",
"title":"The Lord of the Rings",
"isbn":"0-395-19395-8",
"price":22.99
}
],
"bicycle":{
"color":"red",
"price":19.95
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
}
var compact = JSON.stringify(obj)
var jsoun = jsoun(compact)
var url1 = encodeURI(compact)
var url2 = encodeURI(jsoun)
console.log('Compact JSON:')
console.log(compact)
console.log(compact.length+' chars')
console.log('\nAfter URL Encode:')
console.log(url1)
console.log(url1.length+' chars')
console.log('\nJSOUN:')
console.log(jsoun)
console.log(jsoun.length+' chars')
console.log('\nAfter URL Encode:')
console.log(url2)
console.log(url2.length+' chars')
var ugly = encodeURI(JSON.stringify(obj))
var pretty = JSOUN.encode(obj)
// Compact JSON:
// {"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}],"bicycle":{"color":"red","price":19.95}}}
// 360 chars
console.log(ugly)
console.log('\n\n')
console.log(pretty)
```
// After URL Encode:
// %7B%22store%22:%7B%22book%22:%5B%7B%22category%22:%22reference%22,%22author%22:%22Nigel%20Rees%22,%22title%22:%22Sayings%20of%20the%20Century%22,%22price%22:8.95%7D,%7B%22category%22:%22fiction%22,%22author%22:%22Evelyn%20Waugh%22,%22title%22:%22Sword%20of%20Honour%22,%22price%22:12.99%7D,%7B%22category%22:%22fiction%22,%22author%22:%22J.%20R.%20R.%20Tolkien%22,%22title%22:%22The%20Lord%20of%20the%20Rings%22,%22isbn%22:%220-395-19395-8%22,%22price%22:22.99%7D%5D,%22bicycle%22:%7B%22color%22:%22red%22,%22price%22:19.95%7D%7D%7D
// 532 chars
## Without JSOUN
```
%7B%22glossary%22:%7B%22title%22:%22example%20glossary%22,%22GlossDiv%22:%7B%22title%22:%22S%22,%22GlossList%22:%7B%22GlossEntry%22:%7B%22ID%22:%22SGML%22,%22SortAs%22:%22SGML%22,%22GlossTerm%22:%22Standard%20Generalized%20Markup%20Language%22,%22Acronym%22:%22SGML%22,%22Abbrev%22:%22ISO%208879:1986%22,%22GlossDef%22:%7B%22para%22:%22A%20meta-markup%20language,%20used%20to%20create%20markup%20languages%20such%20as%20DocBook.%22,%22GlossSeeAlso%22:%5B%22GML%22,%22XML%22%5D%7D,%22GlossSee%22:%22markup%22%7D%7D%7D%7D%7D
```
// Magic JSON:
// ('store':('book':~('category':'reference','author':'Nigel_Rees','title':'Sayings_of_the_Century','price':8.95),('category':'fiction','author':'Evelyn_Waugh','title':'Sword_of_Honour','price':12.99),('category':'fiction','author':'J._R._R._Tolkien','title':'The_Lord_of_the_Rings','isbn':'0-395-19395-8','price':22.99);,'bicycle':('color':'red','price':19.95)))
// 360 chars
// After URL Encode:
// ('store':('book':~('category':'reference','author':'Nigel_Rees','title':'Sayings_of_the_Century','price':8.95),('category':'fiction','author':'Evelyn_Waugh','title':'Sword_of_Honour','price':12.99),('category':'fiction','author':'J._R._R._Tolkien','title':'The_Lord_of_the_Rings','isbn':'0-395-19395-8','price':22.99);,'bicycle':('color':'red','price':19.95)))
// 360 chars
## With JSOUN
```
('glossary':('title':'example_glossary','GlossDiv':('title':'S','GlossList':('GlossEntry':('ID':'SGML','SortAs':'SGML','GlossTerm':'Standard_Generalized_Markup_Language','Acronym':'SGML','Abbrev':'ISO_8879:1986','GlossDef':('para':'A_meta-markup_language,_used_to_create_markup_languages_such_as_DocBook.','GlossSeeAlso':~'GML','XML';),'GlossSee':'markup')))))
```

@@ -74,0 +52,0 @@ ## Note

@@ -1,19 +0,31 @@

var jsoun = require('./index.js')
var JSOUN = require('./index.js')
var compact = '{"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}],"bicycle":{"color":"red","price":19.95}}}'
var jsoun = jsoun(compact)
var url1 = encodeURI(compact)
var url2 = encodeURI(jsoun)
var obj = {
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
console.log('Compact JSON:')
console.log(compact)
console.log(compact.length+' chars')
console.log('\nAfter URL Encode:')
console.log(url1)
console.log(url1.length+' chars')
console.log('\nJSOUN:')
console.log(jsoun)
console.log(jsoun.length+' chars')
console.log('\nAfter URL Encode:')
console.log(url2)
console.log(url2.length+' chars')
var ugly = encodeURI(JSON.stringify(obj))
var pretty = JSOUN.encode(obj)
console.log(ugly)
console.log('\n\n')
console.log(pretty)
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