mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-10-31 23:53:00 +00:00
Add format:json operator
I've been finding this useful for debugging, and it kind of goes with the JSON operators
This commit is contained in:
28
core/modules/filters/format/json.js
Normal file
28
core/modules/filters/format/json.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/format/json.js
|
||||
type: application/javascript
|
||||
module-type: formatfilteroperator
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.json = function(source,operand,options) {
|
||||
var results = [],
|
||||
spaces = null;
|
||||
if(operand) {
|
||||
spaces = /^\d+$/.test(operand) ? parseInt(operand,10) : operand;
|
||||
}
|
||||
source(function(tiddler,title) {
|
||||
var data = $tw.utils.parseJSONSafe(title);
|
||||
results.push(JSON.stringify(data,null,spaces));
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user