Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fajarbc/anagram-words
Return anagram words if existed from the given string
https://github.com/fajarbc/anagram-words
anagram javascript palindrome
Last synced: 4 days ago
JSON representation
Return anagram words if existed from the given string
- Host: GitHub
- URL: https://github.com/fajarbc/anagram-words
- Owner: fajarbc
- Created: 2022-03-18T08:54:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-01T15:20:43.000Z (about 2 years ago)
- Last Synced: 2024-11-01T11:37:36.331Z (19 days ago)
- Topics: anagram, javascript, palindrome
- Language: JavaScript
- Homepage: https://fajarbc.github.io/anagram-words/
- Size: 90.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# anagram-words
Return anagram words if existed from the given pattern. Check if two strings are anagram. Check if the given word is palindrome.
It has npm package here called [anagram-words](https://www.npmjs.com/package/anagram-words)
## Install
```sh
npm i anagram-words
```## Usage
```javascript
const anagramWords = require("anagram-words")// findPattern
console.log(anagramWords.findPattern("car", "race car care")) // output: [ 'rac', 'car', 'arc', 'rca', 'car' ]
console.log(anagramWords.findPattern("car", "race car care", {unique: true})) // output: [ 'rac', 'car', 'arc', 'rca' ]
console.log(anagramWords.findPattern("car", "race car care", {space: true})) // output: [ 'rac', 'car', 'car' ]
console.log(anagramWords.findPattern("car", "race car care", {space: true, unique: true})) // output: [ 'rac', 'car' ]
console.log(anagramWords.findPattern("cAr", "race car cAre", {caseSensitive: true})) // output: [ 'rcA', 'cAr' ]// areAnagram
console.log(anagramWords.areAnagram("mything", "My night")) // output: true
console.log(anagramWords.areAnagram("mything", "My night", {space: true})) // output: false
console.log(anagramWords.areAnagram("Thing", "Night", {caseSensitive: true})) // output: false
console.log(anagramWords.areAnagram("My thing", "My night", {caseSensitive: true, space: true})) // output: true
console.log(anagramWords.areAnagram("Mything", "My Night", {caseSensitive: true, space: true})) // output: false// isPalindrome
console.log(anagramWords.isPalindrome("Race car")) // output: true
console.log(anagramWords.isPalindrome("Racecar", {caseSensitive: true})) // output: false
console.log(anagramWords.isPalindrome("race car", {space: true})) // output: false
console.log(anagramWords.isPalindrome("Rac e caR", {caseSensitive: true, space: true})) // output: true
console.log(anagramWords.isPalindrome("Race car", {caseSensitive: true, space: true})) // output: false
```## Function
### findPattern
```findPattern(pattern, text, options)```
- Description: return anagram words/sequences from the given string (text) if any
- Return type `array`
- `pattern` (string) is the sequence string you look for in in the string `text`
- `text` (string) is the whole string you want to look for the `pattern`
- `options` (object) is an object to customize the options desribed bellow:
| Parameter | Type | Deafult | Description |
| --------- | :----: | :-------: | ----------- |
| space | boolean | false | `true` means space counted as a character.
`false` means space is not counted as character and will be ignored |
| caseSensitive | boolean | false | `true` means case sensitive character.
`false` means case insensitive |
| unique | boolean | false | `true` only return unique sequence result.
`false` will return all sequence result |
- Example use :
```javascript
const anagramWords = require("anagram-words")
console.log(anagramWords.findPattern("car", "race car care", {space: true, unique: true})) // output: [ 'rac', 'car' ]
```### areAnagram
```areAnagram(word1, word2, options)```
- Description: Check if two strings are anagram
- Return type `boolean`. `true` if they are anagram, `false` if it is not anagram
- `word1` and `word2` is the text/string you you want to check wether if they are anagram or not
- `options` (object) is an object to customize the options desribed bellow:
| Parameter | Type | Deafult | Description |
| --------- | :----: | :-------: | ----------- |
| space | boolean | false | `true` means space counted as a character.
`false` means space is not counted as character and will be ignored |
| caseSensitive | boolean | false | `true` means case sensitive character.
`false` means case insensitive |
- Example use :
```javascript
const anagramWords = require("anagram-words")
console.log(anagramWords.areAnagram("Thing", "Night", {caseSensitive: true})) // output: false
console.log(anagramWords.areAnagram("Thing", "Night")) // output: true
```### isPalindrome
```isPalindrome(word, options)```
- Description: Check if the word is palindrome
- Return type `boolean`. `true` if the word palindrome, `false` if it is not palindrome
- `word` is the text/string you you want to check if it is palindrome or not
- `options` (object) is an object to customize the options desribed bellow:
| Parameter | Type | Deafult | Description |
| --------- | :----: | :-------: | ----------- |
| space | boolean | false | `true` means space counted as a character.
`false` means space is not counted as character and will be ignored |
| caseSensitive | boolean | false | `true` means case sensitive character.
`false` means case insensitive |
- Example use :
```javascript
const anagramWords = require("anagram-words")
console.log(anagramWords.isPalindrome("Race car")) // output: true
console.log(anagramWords.isPalindrome("Racecar", {caseSensitive: true})) // output: false
console.log(anagramWords.isPalindrome("race car", {space: true})) // output: false
```