sweetmesoft-js
v1.2.2
Published
A complete JavaScript/TypeScript library that provides utilities and components for modern web development, including AJAX functionality, charts, maps, tables, and user interface tools.
Readme
SweetMeSoft JS
A complete JavaScript/TypeScript library that provides utilities and components for modern web development, including AJAX functionality, charts, maps, tables, and user interface tools.
Description
SweetMeSoft JS is a library that simplifies web development by providing a collection of reusable tools and components. It is built in TypeScript and designed to work with jQuery and other popular libraries such as Bootstrap, Chart.js, Google Maps, and SweetAlert2.
Installation
NPM
npm install sweetmesoft-jsFrom repository
git clone https://github.com/SweetMeSoft/sweetmesoft-js.git
cd sweetmesoft-js
npm installFile Structure
Ajax.ts
Contains functions for simplified HTTP requests:
getOptions(): Populates select/dropdown elements with options fetched from a URLget(): Performs GET requests with automatic error handling and loadingpost(): Performs POST requests with automatic header configurationput(): Performs PUT requests with automatic header configurationdel(): Performs DELETE requests with automatic header configurationdownloadFile(): Downloads files from the serveruploadFile(): Uploads files to the server
Charts.ts
Provides functionality for generating charts using Chart.js:
generateChart(): Creates dynamic charts with data obtained from APIs- Support for daily and monthly charts
- Automatic configuration of datasets and labels
Classes.ts
Defines all TypeScript interfaces and types used in the library:
OptionsSelect: Configuration for select elementsOptionsCropper: Configuration for image croppingOptionsModal: Configuration for modalsOptionsTable: Configuration for DataTablesOptionsChart: Configuration for chartsOptionsMap: Configuration for Google MapsOptionsRequest: Configuration for AJAX requests
Common.ts
Contains constants and global variables used throughout the library:
- Arrays of abbreviated months and days
- State control variables
JQueryAddOns.ts
Extends jQuery with additional methods:
disable()/enable(): Enables/disables elementscheck()/uncheck(): Checks/unchecks checkboxesinitializeSelect(): Initializes Bootstrap SelecttoBlob(): Converts images to BlobisNullOrEmpty(): String extension that checks if it's empty
Maps.ts
Integration with Google Maps API:
generateMap(): Creates interactive maps with markers- Geolocation support
- Address autocomplete
- Maps in modals or specific containers
- Multiple marker handling
Tools.ts
General utilities for development:
on()/off(): Loading overlay controlcapitalizeFirstLetter(): Capitalizes the first letter of a stringgetFormatedDate(): Formats dates with custom patternsisValidDate(): Validates if an object is a valid dategetUrlParameter(): Gets URL parametersgenerateCropper(): Creates an image cropper with Cropper.js
Technologies Used
- TypeScript: Primary development language
- jQuery: DOM manipulation and AJAX
- Bootstrap: CSS framework and UI components
- Bootstrap Select: Enhanced select component
- Chart.js: Chart library
- Google Maps API: Map integration
- SweetAlert2: Elegant modals and alerts
- Cropper.js: Image cropping
- DataTables: Interactive tables
Basic Usage
AJAX Requests
// GET request
SweetMeSoft.get({
url: '/api/data',
jwt: 'your-jwt-token',
lang: 'en-US',
successCallback: (data) => {
console.log('Data received:', data);
}
});
// POST request
SweetMeSoft.post({
url: '/api/save',
data: {name: 'John', email: '[email protected]'},
jwt: 'your-jwt-token',
lang: 'en-US'
});
// PUT request
SweetMeSoft.put({
url: '/api/users/123',
data: {name: 'Updated Name'},
jwt: 'your-jwt-token'
});
// DELETE request
SweetMeSoft.del({
url: '/api/users/123',
jwt: 'your-jwt-token'
});
// Populate a select
SweetMeSoft.getOptions({
url: '/api/options',
dropDowns: [$('#mySelect')],
text: 'name',
internal: 'id',
jwt: 'your-jwt-token'
});Charts
SweetMeSoft.generateChart({
chart: $('#myChart'),
url: '/api/chart-data',
interval: 'monthly'
});Maps
SweetMeSoft.generateMap({
edtLatitude: $('#latitude'),
edtLongitude: $('#longitude'),
showCurrentLocation: true,
modal: true
});jQuery Extensions
// Initialize a select
$('#mySelect').initializeSelect();
// Check if a string is empty
if (myString.isNullOrEmpty()) {
console.log('String is empty');
}Configuration
The library uses TypeScript with the following configuration:
- Target: ES2019
- Module: ES6
- Declarations included
- Automatic compilation enabled
Deployment
Local Development
- Clone the repository
- Install dependencies:
npm install - Compile TypeScript:
tsc - Compiled files will be in the
src/folder
NPM Publication
The package is available on NPM as sweetmesoft-js and is updated regularly.
Project Integration
<!-- Include dependencies -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!-- Include SweetMeSoft JS -->
<script src="node_modules/sweetmesoft-js/src/Ajax.js"></script>
<script src="node_modules/sweetmesoft-js/src/Charts.js"></script>
<script src="node_modules/sweetmesoft-js/src/Maps.js"></script>
<script src="node_modules/sweetmesoft-js/src/Tools.js"></script>
<script src="node_modules/sweetmesoft-js/src/JQueryAddOns.js"></script>Contributing
Contributions are welcome. Please:
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is under the MIT License. See the LICENSE file for more details.
Author
Erick Velasco - [email protected]
Links
Developed with love by SweetMeSoft
