Folks,
I am just revisiting a solution I developed in the past to automatically locate $:/config tiddlers and provide a selection option. For many the config tiddler contains a simple value such as yes/no and it is easy to pair these up and provide a selection.
- However it would be nice to be able to detect if the config tiddler contains only a number, only text or alphanumerics, a date stamp or color value to name a few.
- In some cases where there are a few values I can configure a config-values-filter in the config tiddler or even provide a more advanced selection tool.
Question
Is there a method by which we could give a string and have a classification of the content returned?
Not only would this help with this solution but also for cleaning data, or testing user input.
- I am aware we can limit the input using the edit-text widget but in this case I want to act on existing string values.
I imagine there are JavaScript functions or regular expressions capable of doing this already but a filter operator that returns one of a number of classifications would be good including those known by tiddlywiki.
- Along with those below
- Date stamp - tiddlywiki serial numeric plus correct length
- unixtime
- Color value - named or prefixed # etc…
- perhaps even filter if it contains
[
or transclusion if it starts with {{ - even an existing missing tiddler or title.
The following JS is suggested by ChatGPT
function classifyString() {
var inputText = document.getElementById('textInput').value;
var result = document.getElementById('result');
if (/^[A-Za-z]+$/.test(inputText)) {
result.textContent = 'The string contains only alphabetical characters.';
} else if (/^[0-9]+$/.test(inputText)) {
result.textContent = 'The string contains only numeric characters.';
} else if (/^[A-Za-z0-9]+$/.test(inputText)) {
result.textContent = 'The string is alphanumeric.';
} else {
result.textContent = 'The string contains characters other than just letters and numbers.';
}
}
What do you think?