arli
v0.0.1
Published
Tools for an Arabic development
Downloads
2
Maintainers
Readme
Arli - Tools for an Arabic development
Usage
node
$ npm install arli
bower
$ bower install arli
browser
<script src="arli.min.js"></script>
API
.arabize(str, [options])
Convert some characters to make the text more Arabian.
Arguments
str
(string): The string to convert.[options=['date', 'number', 'dash', 'char']]
(array): Decide which features to use in the output.
You can use those features: char
, dash
or dash-extra
, date
or date-reverse
, number
.
char
: Arabic characters.dash
: Remove Arabic dashes.dash-extra
: Remove the extra Arabic dashes.date
: Arabic date format.date-reverse
: Reversed Arabic date format.number
: Arabic numbers.
Returns
(string) an Arabian string.
Example
arli.arabize('0123456789%(,;*)?');
// => '۰۱۲۳۴۵۶۷۸۹٪﴾،؛٭﴿؟''
arli.arabize('0123456789%(,;*)?', ['char']);
// => '0123456789٪﴾،؛٭﴿؟''
.count(str, [type])
Count the matched characters in the string.
Arguments
str
(string): The string to count in.[type]
(string): A regular expression pattern to be used.
You can use other patterns: all
, digit
, every
, letter
, strict
, punct
.
See pattern options for more information.
Returns
(number) the number of the matched characters in the string.
Example
arli.count('Hello!');
// => 0
arli.count('Hello! مرحبا');
// => 5
arli.count('Hello! مرحبا ۱۲۳', 'digit');
// => 3
.countRest(str, [type])
Count the non matched characters in the string.
Arguments
str
(String): The string to count in.[type]
(String): A regular expression pattern to be used.
You can use other patterns: all
, digit
, every
, letter
, strict
, punct
.
See pattern options for more information.
Returns
(Number) the number of the non matched characters in the string.
Example
arli.countRest('Hello!');
=> 6
arli.countRest('Hello! مرحبا');
=> 7
arli.countRest('Hello! مرحبا ۱۲۳', 'digit');
=> 13
.dateize(str, [reverse])
Convert a date string to an Arabic format.
Arguments
str
(String): The string to convert.[reverse]
(Boolean): Reverse the month and day in the output if set to true.
Returns
(String) an Arabic date format
Example
arli.dateize('20,11,2015 20/11/2015 20-11-2015 20.11.2015 20 11 2015');
=> '20؍11؍2015 20؍11؍2015 20؍11؍2015 20؍11؍2015 20؍11؍2015'
arli.dateize('20/11/2015', true);
=> '11؍20؍2015' Past it to an RTL env to see it right
.extract(str, [type])
Output the matched characters from the string.
Arguments
str
(String): The string to output from.[type]
(String): A regular expression pattern to be used.
You can use other patterns: all
, digit
, every
, letter
, strict
, punct
.
See pattern options for more information.
Returns
(String) the matched characters.
Example
arli.extract('Hello مرحبا');
=> 'مرحبا'
arli.extract('Hello مرحبا ۱۲۳', 'digit');
=> '۱۲۳'
.has(str, [type])
Checks if the string has the matched pattern.
Arguments
str
(String): The string to check.[type]
(String): A regular expression pattern to be used.
You can use other patterns: all
, digit
, every
, letter
, strict
, punct
.
See pattern options for more information.
Returns
(Boolean) true
if the pattern match, else
otherwise.
Example
arli.has('Hello مرحبا');
=> true
arli.has('Hello مرحبا ۱۲۳', 'digit');
=> true
arli.has('Hello مرحبا', 'digit');
=> false
.how(str, [type])
Calculate the percentage of the matched pattern in the string.
Arguments
str
(String): The string to calculate in.[type]
(String): A regular expression pattern to be used.
You can use other patterns: all
, digit
, every
, letter
, strict
, punct
.
See pattern options for more information.
Returns
(Number) the percentage of the matched pattern.
Example
arli.how('Hello مرحبا');
=> 45.45454545454545
arli.how('Hello مرحبا،،،، ۱۲۳', 'char');
=> 26.31578947368421
.howRest(str, [type])
Calculate the percentage of the non matched pattern in the string.
Arguments
str
(String): The string to calculate in.[type]
(String): A regular expression pattern to be used.
You can use other patterns: all
, digit
, every
, letter
, strict
, punct
.
See pattern options for more information.
Returns
(Number) the percentage of the non matched pattern.
Example
arli.howRest('Hello مرحبا');
=> 54.54545454545455
arli.howRest('Hello مرحبا،،،، ۱۲۳', 'char');
=> 73.6842105263158
.numerize(str)
Convert a number string to an Arabic format.
Arguments
str
(String): The string to convert.
Returns
(String) an Arabic date format
Example
arli.numerize('0123456789');
=> '۰۱۲۳۴۵۶۷۸۹'
.remove(str, [type])
Output the non matched characters from the string.
Arguments
str
(String): The string to output from.[type]
(String): A regular expression pattern to be used.
You can use other patterns: all
, digit
, every
, letter
, strict
, punct
.
See pattern options for more information.
Returns
(String) the non matched characters.
Example
arli.remove('Hello مرحبا');
=> 'Hello '
arli.remove('Hello مرحبا ۱۲۳', 'digit');
=> 'Hello مرحبا'
.removeDash(str, [extra])
Remove the dash or Tatweel character from the string.
Arguments
str
(String): The string to remove from.[extra]
(Boolean): Leave a single dash if set to true
Returns
(String) the new prepared string.
Example
arli.removeDash('مرحبــــــــــا');
=> 'مرحبا'
arli.removeDash('مرحبــــــــــا', true);
=> 'مرحبـا'
Pattern options
all
: All Arabic standard characters.digit
: Arabic numbers.every
: Every Arabic characters.letter
: Arabic letters.strict
: Strict Arabic characters.punct
: Arabic punctuation.
LICENCE
Copyright (c) 2015 Mohamed Elkebir [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.