Initial commit

This commit is contained in:
2025-04-01 08:37:41 +02:00
commit 39c1b6ff0a
59 changed files with 14076 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
/**
* SmartyPants - Smart typography for web content
* Converts straight quotes to curly quotes, dashes to em-dashes, etc.
* Based on the original SmartyPants by John Gruber
*/
const SmartyPants = (function() {
// Regular expressions for matching
const quotes = {
double: {
opening: /(\s|^)"(\w)/g,
closing: /(\w)"/g,
openingNested: /(\s|^)'(\w)/g,
closingNested: /(\w)'/g
},
single: {
opening: /(\s|^)'(\w)/g,
closing: /(\w)'/g
}
};
const dashes = {
emDash: /--/g,
enDash: / - /g
};
const ellipses = /\.\.\./g;
/**
* Process text with SmartyPants transformations
*/
function process(text) {
if (!text) return text;
let result = text;
// Transform double quotes
result = result.replace(quotes.double.opening, '$1"$2');
result = result.replace(quotes.double.closing, '$1"');
// Transform single quotes
result = result.replace(quotes.single.opening, '$1\u2018$2');
result = result.replace(quotes.single.closing, '$1\u2019');
// Transform apostrophes (same as closing single quotes)
result = result.replace(/(\w)'(\w)/g, '$1\u2019$2');
// Transform dashes
result = result.replace(dashes.emDash, '—');
result = result.replace(dashes.enDash, ' ');
// Transform ellipses
result = result.replace(ellipses, '…');
return result;
}
return {
process: process
};
})();
// Make available in browser and Node.js environments
if (typeof module !== 'undefined' && module.exports) {
module.exports = SmartyPants;
}