2.0.0 • Published 7 months ago
nodejs-shared v2.0.0
Essential Node.js utilities, shared and ready to use.
A comprehensive list of changes in each version may be found in the CHANGELOG.
github.com/takuya-motoshima/nodejs-shared
Requirements:
Node.js version: 18 or higher.
- ImageMagick: Required for
ImageUtils
class methods that retrieve the first frame of a GIF and count GIF frames.
Table of contents:
Quickstart
See the nodejs-shared Documentation for details on all features.
Installing the library
npm install --save nodejs-shared
Using the library
import {ProcessUtils, FileUtils} from 'nodejs-shared';
// Get the UID for the user 'ec2-user'. Example: Returns 1000.
const uid = ProcessUtils.getUid('ec2-user');
// Get the GID for the user 'ec2-user'. Example: Returns 1000.
const gid = ProcessUtils.getGid('ec2-user');
// Print the UID and GID.
console.log(`UID: ${uid}, GID: ${gid}`);
// Write a string to a file.
FileUtils.write('path/to/another-file.txt', 'Hello, world!');
// Write a Buffer to a file.
const buffer = Buffer.from('Hello, world!');
FileUtils.write('path/to/file.txt', buffer);
// Write with file system options.
FileUtils.write('path/to/file.txt', buffer, {mode: 0o644, owner: {username: 'nginx', groupName: 'nginx'}});
// Parse a data URL to extract its MIME type, base64 encoded data, file extension, and size.
const dataUrlParts = MediaUtils.parseDataUrl('data:image/jpeg;base64,AA==...');
console.log(dataUrlParts);
// {
// mimeType: 'image/jpeg',
// base64: '/9j/4AAQSk...',
// extension: 'jpg',
// bytesize: 45056
// }
// Write a JPEG image using a data URL.
MediaUtils.writeImage('path/to/image.jpg', 'data:image/jpeg;base64,AA==...');
// Write a PNG image using a Buffer.
MediaUtils.writeImage('path/to/image.png', Buffer.from([...]));
// Write an SVG image using a string.
writeImage('path/to/image.svg', '<svg>...</svg>');
// Write with file system options.
MediaUtils.writeImage('path/to/image.png', Buffer.from([...]), {mode: 0o644, owner: {username: 'nginx', groupName: 'nginx'}});
Testing
With npm do:
npm test
Release Notes
All changes can be found here.
Author
Takuya Motoshima
License
2.0.0
7 months ago
1.0.30
12 months ago
1.0.29
1 year ago
1.0.28
1 year ago
1.0.27
1 year ago
1.0.26
2 years ago
1.0.25
2 years ago
1.0.23
2 years ago
1.0.19
2 years ago
1.0.18
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.22
2 years ago
1.0.21
2 years ago
1.0.20
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.11
2 years ago
1.0.10
3 years ago
1.0.12
2 years ago
1.0.3
3 years ago
1.0.2
4 years ago
1.0.1
5 years ago
1.0.0
5 years ago