neatjson 0.10 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2820b11ac77b92de38f28231d4826cd1e77ad0f9140da5b9e41eaf995dee5ce
4
- data.tar.gz: b5cdc8378b227f574f8de0d517e7964ca6cfe96e40ff30873d6a412cda5844f4
3
+ metadata.gz: 9896a4ef60379130606c3de3b7ce03ed65ce304ce7998470ecb74aaa95878f62
4
+ data.tar.gz: 7aa2196577ba6862be5bdf3811c6e2752157aa7b1520bae37697020a1d65d1cc
5
5
  SHA512:
6
- metadata.gz: 1681f5edb27ec6075e5bfd1d9c8a9e806b3ee4d2f76dea65d97a45d5b22fa4feefa20b2507ff060dd424cca346b4bee6ebdcd05735543dde71170f4ad2d55125
7
- data.tar.gz: 14a3138ab4eb40fce7f9052e250f7c1ca7394c460b3d3f4cc8ccd87d8b91bed870d395719c3c3a0343990284af37589ef5e3abc86bd0f58c2b40ed946197c8ba
6
+ metadata.gz: 867bb6fa6cd5af52f708ded86d50adaf1b938e5f114c05cb9801ec40cf7ff0f08e1547400bf98f42087db2b0520eb682e85f88da9a3176f8ad61b611c8bd4944
7
+ data.tar.gz: b6b3d72a566b76b50baa82a7fde278f0b0a0c954e698c67fab36d835cf12cae7b1f9a56b5a0fd081ee94501735b6bbea439934057e91ca8f2607d1212ca70574
data/lib/neatjson.rb CHANGED
@@ -118,7 +118,7 @@ module JSON
118
118
  when 3 then o.sort_by{ |k,v| sort[k,v,o] }
119
119
  end
120
120
  end
121
- keys = o.map{|x| x.first.to_s }
121
+ keys = o.map{ |x| x.first.to_s }
122
122
  keyvals = o.map.with_index{ |(k,v),i| [ k.to_s.inspect, build[v, '', opts[:force_floats] || opts[:force_floats_in].include?(keys[i])] ] }
123
123
  keyvals = keyvals.map{ |kv| kv.join(colon1) }.join(comma)
124
124
  one_line = "#{indent}{#{opad}#{keyvals}#{opad}}"
@@ -152,7 +152,8 @@ module JSON
152
152
  keyvals.map!{ |k,v| [ formatk % k,v] }
153
153
  end
154
154
  indent2 = "#{indent}#{opts[:indent]}"
155
- keyvals.map! do |k,v|
155
+ keyvals.map!.with_index do |(k,v),i|
156
+ floats_forced = opts[:force_floats] || opts[:force_floats_in].include?(keys[i])
156
157
  one_line = "#{k}#{colonn}#{build[v, '', floats_forced]}"
157
158
  if opts[:wrap] && (one_line.length > opts[:wrap]) && (v.is_a?(Array) || v.is_a?(Hash))
158
159
  "#{k}#{colonn}#{build[v, indent2, floats_forced].lstrip}"
data/neatjson.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'date'
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "neatjson"
5
- s.version = "0.10"
5
+ s.version = "0.10.1"
6
6
  s.date = Date.today.iso8601
7
7
  s.authors = ["Gavin Kistner"]
8
8
  s.email = "gavin@phrogz.net"
data/test/tests.js CHANGED
@@ -203,6 +203,14 @@ exports.tests = [
203
203
  { json:'[1,2,3,{"a":[4.0,5.0,{"a":6.0,"b":7}],"b":[8,9,{"a":10.0,"b":11}]}]', opts:{forceFloatsIn:['a'], wrap:false} },
204
204
  ]},
205
205
 
206
+ {value:[1,2,3, {bar:[4,5,6], foo:[7,8,9]}], tests:[
207
+ { json:'[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7,8,9]\n\t}\n]', opts:{wrap:20, indent:"\t"} },
208
+ { json:'[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7,8,9]\n\t}\n]', opts:{wrap:20, indent:"\t", forceFloatsIn:['bar']} },
209
+ { json:'[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts:{wrap:20, indent:"\t", forceFloatsIn:['foo']} },
210
+ { json:'[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts:{wrap:20, indent:"\t", forceFloatsIn:['foo', 'bar']} },
211
+ { json:'[\n\t1.0,\n\t2.0,\n\t3.0,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts:{wrap:20, indent:"\t", forceFloats:true} },
212
+ ]},
213
+
206
214
  // {value:Class.new{ def to_json(*a); {a:1}.to_json(*a); end }.new, tests:[
207
215
  // { json:'{ "a":1}' },
208
216
  // { json:'{ "a":1}', opts:{wrap:true} },
data/test/tests.lua CHANGED
@@ -208,9 +208,18 @@ return {
208
208
  { json='{"floats":[0.0,1.0,0.1,1.556],"raw":[0,1,0.1,1.556]}', opts={forceFloatsIn={'floats'}, decimals=3, trimTrailingZeros=true, sort=true} },
209
209
  }},
210
210
 
211
- -- {value={1,2,3,{a={4,5,{a=6, b=7}}, b={8,9,{a=10, b=11}}}}, tests={
212
- -- { json='[1,2,3,{"a":[4,5,{"a":6,"b":7}],"b":[8,9,{"a":10,"b":11}]}]', opts={} },
213
- -- { json='[1.0,2.0,3.0,{"a":[4.0,5.0,{"a":6.0,"b":7.0}],"b":[8.0,9.0,{"a":10.0,"b":11.0}]}]', opts={forceFloats=true, wrap=false} },
214
- -- { json='[1,2,3,{"a":[4.0,5.0,{"a":6.0,"b":7}],"b":[8,9,{"a":10.0,"b":11}]}]', opts={forceFloatsIn={'a'}, wrap=false} },
215
- -- }},
211
+ {value={1,2,3,{a={4,5,{a=6, b=7}}, b={8,9,{a=10, b=11}}}}, tests={
212
+ { json='[1,2,3,{"a":[4,5,{"a":6,"b":7}],"b":[8,9,{"a":10,"b":11}]}]', opts={sort=true} },
213
+ { json='[1.0,2.0,3.0,{"a":[4.0,5.0,{"a":6.0,"b":7.0}],"b":[8.0,9.0,{"a":10.0,"b":11.0}]}]', opts={forceFloats=true, wrap=false, sort=true} },
214
+ { json='[1,2,3,{"a":[4.0,5.0,{"a":6.0,"b":7}],"b":[8,9,{"a":10.0,"b":11}]}]', opts={forceFloatsIn={'a'}, wrap=false, sort=true} },
215
+ }},
216
+
217
+ {value={1,2,3, {bar={4,5,6}, foo={7,8,9}}}, tests={
218
+ { json='[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7,8,9]\n\t}\n]', opts={wrap=30, sort=true, indent="\t"} },
219
+ { json='[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7,8,9]\n\t}\n]', opts={wrap=30, sort=true, indent="\t", forceFloatsIn={'bar'}} },
220
+ { json='[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts={wrap=30, sort=true, indent="\t", forceFloatsIn={'foo'}} },
221
+ { json='[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts={wrap=30, sort=true, indent="\t", forceFloatsIn={'foo', 'bar'}} },
222
+ { json='[\n\t1.0,\n\t2.0,\n\t3.0,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]', opts={wrap=30, sort=true, indent="\t", forceFloats=true} },
223
+ }},
224
+
216
225
  }
data/test/tests.rb CHANGED
@@ -218,5 +218,13 @@ TESTS = [
218
218
  { json:'[1.0,2.0,3.0,{"a":[4.0,5.0,{"a":6.0,"b":7.0}],"b":[8.0,9.0,{"a":10.0,"b":11.0}]}]', opts:{force_floats:true, wrap:false} },
219
219
  { json:'[1,2,3,{"a":[4.0,5.0,{"a":6.0,"b":7}],"b":[8,9,{"a":10.0,"b":11}]}]', opts:{force_floats_in:['a'], wrap:false} },
220
220
  ]},
221
+
222
+ {value:[1,2,3, {bar:[4,5,6], foo:[7,8,9]}], tests:[
223
+ { json:%Q{[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7,8,9]\n\t}\n]}, opts:{wrap:20, indent:"\t"} },
224
+ { json:%Q{[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7,8,9]\n\t}\n]}, opts:{wrap:20, indent:"\t", force_floats_in:["bar"]} },
225
+ { json:%Q{[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4,5,6],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]}, opts:{wrap:20, indent:"\t", force_floats_in:["foo"]} },
226
+ { json:%Q{[\n\t1,\n\t2,\n\t3,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]}, opts:{wrap:20, indent:"\t", force_floats_in:["foo", "bar"]} },
227
+ { json:%Q{[\n\t1.0,\n\t2.0,\n\t3.0,\n\t{\n\t\t"bar":[4.0,5.0,6.0],\n\t\t"foo":[7.0,8.0,9.0]\n\t}\n]}, opts:{wrap:20, indent:"\t", force_floats:true} },
228
+ ]},
221
229
  ]
222
230
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neatjson
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.10'
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Kistner