This module provides a class for checking if a string starts with a specified prefix.
To use this module, you should have the "node-string-methods" npm package installed. You can install it using npm or yarn:
npm install node-string-methodsconst StartsWith = require('node-string-methods/startsWith');
// Create an instance of the StartsWith class with a string and prefix
const str = 'Hello, world!';
const prefix = 'Hello';
const starter = new StartsWith(str, prefix);
// Execute the starts-with operation
const result = starter.execute();
console.log(result); // Output: truestr(String): The input string that you want to check.prefix(String): The prefix string to check for at the beginning ofstr.
Creates a new instance of the StartsWith class with the provided input string and prefix.
Checks if the input string starts with the specified prefix.
- Returns:
trueif the string starts with the prefix; otherwise,false.
const StartsWith = require('node-string-methods/startsWith');
const str = 'Hello, world!';
const prefix = 'Hello';
const starter = new StartsWith(str, prefix);
const result = starter.execute();
console.log(result); // Output: true