generated from dev-ahmadbilal/npm-pkg-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fea5736
commit 456ad85
Showing
21 changed files
with
1,552 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { CasingMaster } from '../src/case-master'; | ||
|
||
describe('CasingMaster', () => { | ||
test('should convert to camelCase', () => { | ||
expect(CasingMaster.toCamelCase('hello world')).toBe('helloWorld'); | ||
expect(CasingMaster.toCamelCase('Hello world')).toBe('helloWorld'); | ||
}); | ||
|
||
test('should convert to snake_case', () => { | ||
expect(CasingMaster.toSnakeCase('hello world')).toBe('hello_world'); | ||
expect(CasingMaster.toSnakeCase('Hello world')).toBe('hello_world'); | ||
}); | ||
|
||
test('should convert to PascalCase', () => { | ||
expect(CasingMaster.toPascalCase('hello world')).toBe('HelloWorld'); | ||
expect(CasingMaster.toPascalCase('Hello world')).toBe('HelloWorld'); | ||
}); | ||
|
||
test('should convert to kebab-case', () => { | ||
expect(CasingMaster.toKebabCase('hello world')).toBe('hello-world'); | ||
expect(CasingMaster.toKebabCase('Hello world')).toBe('hello-world'); | ||
}); | ||
|
||
test('should convert to SCREAMING_SNAKE_CASE', () => { | ||
expect(CasingMaster.toScreamingSnakeCase('hello world')).toBe('HELLO_WORLD'); | ||
expect(CasingMaster.toScreamingSnakeCase('Hello world')).toBe('HELLO_WORLD'); | ||
}); | ||
|
||
test('should convert to Sentence case', () => { | ||
expect(CasingMaster.toSentenceCase('hello world')).toBe('Hello world'); | ||
expect(CasingMaster.toSentenceCase('HELLO WORLD')).toBe('Hello world'); | ||
}); | ||
|
||
test('should convert to Title Case', () => { | ||
expect(CasingMaster.toTitleCase('hello world')).toBe('Hello World'); | ||
expect(CasingMaster.toTitleCase('HELLO WORLD')).toBe('Hello World'); | ||
}); | ||
|
||
test('should smartly convert case formats', () => { | ||
expect(CasingMaster.smartCaseConvert('hello world', 'camel')).toBe('helloWorld'); | ||
expect(CasingMaster.smartCaseConvert('hello world', 'snake')).toBe('hello_world'); | ||
expect(CasingMaster.smartCaseConvert('hello world', 'pascal')).toBe('HelloWorld'); | ||
expect(CasingMaster.smartCaseConvert('hello world', 'kebab')).toBe('hello-world'); | ||
expect(CasingMaster.smartCaseConvert('hello world', 'screaming-snake')).toBe('HELLO_WORLD'); | ||
expect(CasingMaster.smartCaseConvert('hello world', 'sentence')).toBe('Hello world'); | ||
expect(CasingMaster.smartCaseConvert('hello world', 'title')).toBe('Hello World'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CompressionMaster } from '../src/compression-master'; | ||
|
||
describe('CompressionMaster', () => { | ||
test('should compress and decompress strings correctly', () => { | ||
const originalString = 'Hello, world!'; | ||
const compressed = CompressionMaster.compress(originalString); | ||
const decompressed = CompressionMaster.decompress(compressed); | ||
|
||
expect(decompressed).toBe(originalString); | ||
}); | ||
|
||
test('should handle empty strings', () => { | ||
const originalString = ''; | ||
const compressed = CompressionMaster.compress(originalString); | ||
const decompressed = CompressionMaster.decompress(compressed); | ||
|
||
expect(decompressed).toBe(originalString); | ||
}); | ||
|
||
test('should handle strings with special characters', () => { | ||
const originalString = 'Special characters: !@#$%^&*()_+[]{}|;:",.<>?/'; | ||
const compressed = CompressionMaster.compress(originalString); | ||
const decompressed = CompressionMaster.decompress(compressed); | ||
|
||
expect(decompressed).toBe(originalString); | ||
}); | ||
|
||
test('should handle large strings', () => { | ||
const originalString = 'A'.repeat(10000); // Large string of 10,000 characters | ||
const compressed = CompressionMaster.compress(originalString); | ||
const decompressed = CompressionMaster.decompress(compressed); | ||
|
||
expect(decompressed).toBe(originalString); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { ConversionMaster } from '../src/conversion-master'; | ||
|
||
describe('ConversionMaster', () => { | ||
describe('toBoolean', () => { | ||
it('should convert "yes" to true', () => { | ||
expect(ConversionMaster.toBoolean('yes')).toBe(true); | ||
}); | ||
|
||
it('should convert "no" to false', () => { | ||
expect(ConversionMaster.toBoolean('no')).toBe(false); | ||
}); | ||
|
||
it('should convert "on" to true', () => { | ||
expect(ConversionMaster.toBoolean('on')).toBe(true); | ||
}); | ||
|
||
it('should convert "off" to false', () => { | ||
expect(ConversionMaster.toBoolean('off')).toBe(false); | ||
}); | ||
|
||
it('should convert "1" to true', () => { | ||
expect(ConversionMaster.toBoolean('1')).toBe(true); | ||
}); | ||
|
||
it('should convert "0" to false', () => { | ||
expect(ConversionMaster.toBoolean('0')).toBe(false); | ||
}); | ||
|
||
it('should convert "true" to true', () => { | ||
expect(ConversionMaster.toBoolean('true')).toBe(true); | ||
}); | ||
|
||
it('should convert "false" to false', () => { | ||
expect(ConversionMaster.toBoolean('false')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('toFloat', () => { | ||
it('should convert string to float with precision', () => { | ||
expect(ConversionMaster.toFloat('123.456', 2)).toBe(123.46); | ||
}); | ||
|
||
it('should convert string to float without precision', () => { | ||
expect(ConversionMaster.toFloat('123.456')).toBe(123.456); | ||
}); | ||
|
||
it('should handle non-numeric strings gracefully', () => { | ||
expect(ConversionMaster.toFloat('abc')).toBeNaN(); | ||
}); | ||
}); | ||
|
||
describe('toInt', () => { | ||
it('should convert decimal string to integer', () => { | ||
expect(ConversionMaster.toInt('42')).toBe(42); | ||
}); | ||
|
||
it('should convert hexadecimal string to integer', () => { | ||
expect(ConversionMaster.toInt('0x1A')).toBe(26); | ||
}); | ||
|
||
it('should handle non-numeric strings gracefully', () => { | ||
expect(ConversionMaster.toInt('abc')).toBeNaN(); | ||
}); | ||
}); | ||
|
||
describe('toJson', () => { | ||
it('should convert a JSON string to an object', () => { | ||
expect(ConversionMaster.toJson('{"name": "John"}')).toEqual({ name: 'John' }); | ||
}); | ||
|
||
it('should throw an error for invalid JSON', () => { | ||
expect(() => ConversionMaster.toJson('{name: John}')).toThrow(SyntaxError); | ||
}); | ||
}); | ||
|
||
describe('fromJson', () => { | ||
it('should convert a JSON object to a string', () => { | ||
expect(ConversionMaster.fromJson({ name: 'John' })).toBe('{"name":"John"}'); | ||
}); | ||
|
||
it('should handle nested objects', () => { | ||
const nestedObj = { user: { name: 'John', age: 30 }, active: true }; | ||
expect(ConversionMaster.fromJson(nestedObj)).toBe('{"user":{"name":"John","age":30},"active":true}'); | ||
}); | ||
|
||
it('should convert an empty object to an empty JSON string', () => { | ||
expect(ConversionMaster.fromJson({})).toBe('{}'); | ||
}); | ||
|
||
it('should handle arrays in JSON objects', () => { | ||
const objWithArray = { name: 'John', hobbies: ['reading', 'gaming'] }; | ||
expect(ConversionMaster.fromJson(objWithArray)).toBe('{"name":"John","hobbies":["reading","gaming"]}'); | ||
}); | ||
}); | ||
|
||
describe('toBase64', () => { | ||
it('should convert a string to Base64', () => { | ||
expect(ConversionMaster.toBase64('Hello World!')).toBe('SGVsbG8gV29ybGQh'); | ||
}); | ||
}); | ||
|
||
describe('fromBase64', () => { | ||
it('should convert Base64 to a string', () => { | ||
expect(ConversionMaster.fromBase64('SGVsbG8gV29ybGQh')).toBe('Hello World!'); | ||
}); | ||
}); | ||
|
||
describe('toHex', () => { | ||
it('should convert a string to hexadecimal', () => { | ||
expect(ConversionMaster.toHex('Hello')).toBe('48656c6c6f'); | ||
}); | ||
}); | ||
|
||
describe('fromHex', () => { | ||
it('should convert hexadecimal to a string', () => { | ||
expect(ConversionMaster.fromHex('48656c6c6f')).toBe('Hello'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { EmojiMaster } from '../src/emoji-master'; | ||
|
||
describe('EmojiMaster', () => { | ||
describe('findEmojis', () => { | ||
it('should find all emojis in a text', () => { | ||
const result = EmojiMaster.findEmojis('Hello 👋 World 🌍!'); | ||
expect(result).toEqual(['👋', '🌍']); | ||
}); | ||
|
||
it('should return an empty array when no emojis are found', () => { | ||
const result = EmojiMaster.findEmojis('Hello World!'); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should handle a text with no emojis gracefully', () => { | ||
const result = EmojiMaster.findEmojis(''); | ||
expect(result).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('countEmojis', () => { | ||
it('should count the number of emojis in a text', () => { | ||
const result = EmojiMaster.countEmojis('Hello 👋 World 🌍!'); | ||
expect(result).toBe(2); | ||
}); | ||
|
||
it('should return 0 when no emojis are found', () => { | ||
const result = EmojiMaster.countEmojis('Hello World!'); | ||
expect(result).toBe(0); | ||
}); | ||
|
||
it('should handle a text with no emojis gracefully', () => { | ||
const result = EmojiMaster.countEmojis(''); | ||
expect(result).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('replaceEmojis', () => { | ||
it('should replace all emojis with the specified placeholder', () => { | ||
const result = EmojiMaster.replaceEmojis('Hello 👋 World 🌍!', '[emoji]'); | ||
expect(result).toBe('Hello [emoji] World [emoji]!'); | ||
}); | ||
|
||
it('should replace all emojis with the default placeholder', () => { | ||
const result = EmojiMaster.replaceEmojis('Hello 👋 World 🌍!'); | ||
expect(result).toBe('Hello [emoji] World [emoji]!'); | ||
}); | ||
|
||
it('should handle a text with no emojis gracefully', () => { | ||
const result = EmojiMaster.replaceEmojis('Hello World!'); | ||
expect(result).toBe('Hello World!'); | ||
}); | ||
}); | ||
|
||
describe('replaceWordsWithEmojis', () => { | ||
it('should replace specified words with emojis', () => { | ||
const replacements = { happy: '😊', sad: '😢' }; | ||
const result = EmojiMaster.replaceWordsWithEmojis('I am very happy and a bit sad.', replacements); | ||
expect(result).toBe('I am very 😊 and a bit 😢.'); | ||
}); | ||
|
||
it('should handle text with no replacements', () => { | ||
const replacements = { happy: '😊' }; | ||
const result = EmojiMaster.replaceWordsWithEmojis('I am neutral.', replacements); | ||
expect(result).toBe('I am neutral.'); | ||
}); | ||
|
||
it('should handle empty text gracefully', () => { | ||
const replacements = { happy: '😊' }; | ||
const result = EmojiMaster.replaceWordsWithEmojis('', replacements); | ||
expect(result).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('extractEmojiSequences', () => { | ||
it('should extract all emoji sequences from a text', () => { | ||
const result = EmojiMaster.extractEmojiSequences('Hello 👋 World 🌍! 🎉'); | ||
expect(result).toEqual(['👋', '🌍', '🎉']); | ||
}); | ||
|
||
it('should return an empty array when no emojis are found', () => { | ||
const result = EmojiMaster.extractEmojiSequences('Hello World!'); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should handle a text with no emojis gracefully', () => { | ||
const result = EmojiMaster.extractEmojiSequences(''); | ||
expect(result).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('containsEmojis', () => { | ||
it('should return true if the text contains emojis', () => { | ||
const result = EmojiMaster.containsEmojis('Hello 👋 World!'); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false if the text does not contain emojis', () => { | ||
const result = EmojiMaster.containsEmojis('Hello World!'); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should handle a text with no emojis gracefully', () => { | ||
const result = EmojiMaster.containsEmojis(''); | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { EntropyMaster } from '../src/entropy-master'; | ||
|
||
describe('EntropyMaster', () => { | ||
describe('calculateEntropy', () => { | ||
it('should calculate the entropy of a string', () => { | ||
const entropy = EntropyMaster.calculateEntropy('password123'); | ||
expect(entropy).toBeCloseTo(3.2776, 4); | ||
}); | ||
|
||
it('should handle an empty string', () => { | ||
const entropy = EntropyMaster.calculateEntropy(''); | ||
expect(entropy).toBe(0); // Entropy of an empty string should be zero | ||
}); | ||
|
||
it('should handle a single character string', () => { | ||
const entropy = EntropyMaster.calculateEntropy('a'); | ||
expect(entropy).toBe(0); // Entropy of a single character string should be zero | ||
}); | ||
|
||
it('should handle a string with repeating characters', () => { | ||
const entropy = EntropyMaster.calculateEntropy('aaaaaa'); | ||
expect(entropy).toBe(0); // Entropy of a string with repeating characters should be 0 | ||
}); | ||
}); | ||
|
||
describe('getStrength', () => { | ||
it('should return "Strong" for a string with high entropy', () => { | ||
const strength = EntropyMaster.getStrength('A1b2C3d4E5'); | ||
expect(strength).toBe('Strong'); | ||
}); | ||
|
||
it('should return "Moderate" for a string with moderate entropy', () => { | ||
const strength = EntropyMaster.getStrength('password123'); | ||
expect(strength).toBe('Moderate'); | ||
}); | ||
|
||
it('should return "Weak" for a string with low entropy', () => { | ||
const strength = EntropyMaster.getStrength('aaaaaa'); | ||
expect(strength).toBe('Weak'); | ||
}); | ||
|
||
it('should handle an empty string and return "Weak"', () => { | ||
const strength = EntropyMaster.getStrength(''); | ||
expect(strength).toBe('Weak'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.