From e213df268586de3238f8bfec95663e5f8f5c16d3 Mon Sep 17 00:00:00 2001 From: Brian Seymour Date: Wed, 25 Sep 2024 10:39:39 -0500 Subject: [PATCH] new types, new library methods, fix docs, version bump --- index.d.ts | 4 ++-- lib/core/config.js | 2 +- lib/util/index.js | 6 +++++- lib/util/string.js | 40 ++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- var/template/.env.sample | 1 + 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 lib/util/string.js diff --git a/index.d.ts b/index.d.ts index bbf7dd8..5c4c8f4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -27,6 +27,6 @@ declare module '@exajs/core/system/sequelize' { declare module '@exajs/core/util' { import json from '#exa/util/json.js'; - - export { json }; + import string from '#exa/util/string.js'; + export { json, string }; } diff --git a/lib/core/config.js b/lib/core/config.js index 76669b0..36ea2ed 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -3,7 +3,7 @@ let config = { /** * internal config */ - version: '0.0.13', + version: '0.0.14', paths: { root: '', diff --git a/lib/util/index.js b/lib/util/index.js index 43efb12..521d388 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -1,3 +1,7 @@ import json from '#exa/util/json.js'; +import string from '#exa/util/string.js'; -export { json }; +export { + json, + string, +}; diff --git a/lib/util/string.js b/lib/util/string.js new file mode 100644 index 0000000..a0b3f60 --- /dev/null +++ b/lib/util/string.js @@ -0,0 +1,40 @@ +export default new class { + + ucwords(string) { + return (string + '') + .toLowerCase() + .replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, result => { + return result.toUpperCase(); + }); + } + + to_slug(string) { + return (string + '') + .toLowerCase() + .trim() + .replace(/[^a-z0-9 ]+/g, '') + .replace(/ +/g, '-'); + } + + to_currency(amount) { + if (!amount || isNaN(amount)) { + return '$0.00'; + } + + let formatter = new Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD' + }); + + return formatter.format(amount); + } + + strip_html(str) { + if (typeof str !== 'string') { + return str; + } + + return str.replace(/<(?:.|\n)*?>/gm, ''); + } + +}; diff --git a/package.json b/package.json index ed55bf0..f97c9e0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@exajs/core", "type": "module", "author": "Brian Seymour <@realtux>", - "version": "0.0.13", + "version": "0.0.14", "description": "modern opinionated node.js framework", "license": "MIT", "homepage": "https://github.com/realtux/exa", diff --git a/var/template/.env.sample b/var/template/.env.sample index 733c601..800be28 100644 --- a/var/template/.env.sample +++ b/var/template/.env.sample @@ -1,5 +1,6 @@ EXAENV=development +# optionally add values here and overwrite values in config/master.js DATABASE_HOST=mysql DATABASE_PORT=3306 DATABASE_USERNAME=root