Sails helper issue #135
-
Hi @neonexus, I have the below helper: /**
* Parse person's name in a standard format
*
* @function sails.helpers.parsePersonName.
* @param {String} name - The input string representing a person's name.
*
* @returns {String} The function `parsePersonName` returns the name in the format <LastName, FirstName MiddleName>.
*/
module.exports = {
sync: true,
friendlyName: 'Parse DICOM person name',
description: 'Parse DICOM person name as a readable string',
inputs: {
name: {
type: 'string',
required: false,
},
},
exits: {
success: {},
},
fn: (inputs, exits) => {
if (inputs.name.length === 0) {
return null;
}
const ignoredWords = new Set([
'ms',
'mr',
'mrs',
'dr',
'prof',
'rev',
'fr',
'miss',
'col',
'capt',
'gen',
'maj',
]);
const capitalizeWord = (word) => {
return word.charAt(0).toUpperCase() + word.slice(1);
};
const capitalizeHyphenatedWord = (word) => {
return word.replace(/-(.)/g, (match, letter) => `-${letter.toUpperCase()}`);
};
const nameComponents = inputs.name
.toLowerCase()
.split(/\s+|\^+/)
.map((s) => s.trim())
.filter((s) => s.length > 0 && !ignoredWords.has(s))
.map((s, index) => {
if (index === 0) {
return s;
} else {
return capitalizeWord(capitalizeHyphenatedWord(s));
}
});
if (nameComponents.length < 2) {
return nameComponents[0].toUpperCase();
}
return exits.success(`${nameComponents[0].toUpperCase()}, ${nameComponents.slice(1, 3).join(' ')}`);
},
}; Sails give me the error: ImplementationError: Failed to call this function ("parsePersonName") synchronously, because it is not actually synchronous. Instead, its implementation is asynchronous which is inconsistent with its declared interface (`sync: true`). How to make this Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Answered by
MaheshkumarSundaram
May 31, 2024
Replies: 1 comment
-
Sorry @neonexus. That was my stupid mistake of not using |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
MaheshkumarSundaram
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry @neonexus. That was my stupid mistake of not using
exits
during my early return 😖.