@jdeighan/coffee-utils 4.1.5 → 4.1.6

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "4.1.5",
4
+ "version": "4.1.6",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -215,13 +215,23 @@ export warn = (message) ->
215
215
 
216
216
  log "WARNING: #{message}"
217
217
 
218
+ # ---------------------------------------------------------------------------
219
+ # hashToStr - stringify a hash
220
+
221
+ export hashToStr = (h) ->
222
+
223
+ return JSON.stringify(h, Object.keys(h).sort(), 3)
224
+
218
225
  # ---------------------------------------------------------------------------
219
226
  # say - print to the console (for now)
220
227
  # later, on a web page, call alert(str)
221
228
 
222
- export say = (str) ->
229
+ export say = (x) ->
223
230
 
224
- console.log str
231
+ if isHash(x)
232
+ console.log hashToStr(x)
233
+ else
234
+ console.log x
225
235
  return
226
236
 
227
237
  # ---------------------------------------------------------------------------
@@ -221,11 +221,21 @@ export var warn = function(message) {
221
221
  return log(`WARNING: ${message}`);
222
222
  };
223
223
 
224
+ // ---------------------------------------------------------------------------
225
+ // hashToStr - stringify a hash
226
+ export var hashToStr = function(h) {
227
+ return JSON.stringify(h, Object.keys(h).sort(), 3);
228
+ };
229
+
224
230
  // ---------------------------------------------------------------------------
225
231
  // say - print to the console (for now)
226
232
  // later, on a web page, call alert(str)
227
- export var say = function(str) {
228
- console.log(str);
233
+ export var say = function(x) {
234
+ if (isHash(x)) {
235
+ console.log(hashToStr(x));
236
+ } else {
237
+ console.log(x);
238
+ }
229
239
  };
230
240
 
231
241
  // ---------------------------------------------------------------------------
package/temp.js ADDED
@@ -0,0 +1,16 @@
1
+ // Generated by CoffeeScript 2.6.1
2
+ // temp.coffee
3
+ var str;
4
+
5
+ import {
6
+ hashToStr
7
+ } from '@jdeighan/coffee-utils';
8
+
9
+ // ---------------------------------------------------------------------------
10
+ str = hashToStr({
11
+ c: 3,
12
+ b: 2,
13
+ a: 1
14
+ });
15
+
16
+ console.log(str);