1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-30 17:23:16 +00:00
TiddlyWiki5/core/modules/tiddler.js

39 lines
796 B
JavaScript
Raw Normal View History

/*\
title: $:/core/modules/tiddler.js
type: application/javascript
module-type: tiddlermethod
Extension methods for the $tw.Tiddler object
\*/
(function(){
2012-05-04 17:49:04 +00:00
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.hasTag = function(tag) {
return this.fields.tags && this.fields.tags.indexOf(tag) !== -1;
};
exports.hasField = function(field) {
return $tw.utils.hop(this.fields,field);
};
exports.getFieldString = function(field) {
var value = this.fields[field];
// Check for a missing field
if(value === undefined) {
return "";
}
// Parse the field with the associated module (if any)
var fieldModule = $tw.Tiddler.fieldModules[field];
if(fieldModule) {
return fieldModule.stringify.call(this,value);
} else {
return value.toString();
}
};
})();