Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 14, 2014
0 parents commit cf9dcc2
Show file tree
Hide file tree
Showing 10 changed files with 361 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.DS_Store
coverage
144 changes: 144 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireMultipleVarDecl": true,
"requireBlocksOnNewline": true,
"disallowPaddingNewlinesInBlocks": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"requireSpacesInsideObjectBrackets": "all",
"disallowDanglingUnderscores": true,
"requireSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": [
"?",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"disallowLeftStickedOperators": [
"?",
"+",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireRightStickedOperators": ["!"],
"disallowRightStickedOperators": [
"?",
"+",
"/",
"*",
":",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireLeftStickedOperators": [","],
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforeBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterBinaryOperators": [
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!=="
],
"disallowImplicitTypeConversion": ["numeric", "boolean", "binary", "string"],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"disallowKeywords": ["with"],
"disallowMultipleLineStrings": true,
"disallowMultipleLineBreaks": true,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,
"maximumLineLength": 78,
"requireCapitalizedConstructors": true,
"safeContextKeyword": "self",
"requireDotNotation": true,
"disallowYodaConditions": true,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}
}
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
.travis.yml
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: "node_js"
before_install:
- "npm update -g npm"
script: "npm run-script test-travis"
node_js:
- "0.10"
- "0.11"
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2014 Titus Wormer <tituswormer@gmail.com>

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.
35 changes: 35 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# direction [![Build Status](https://travis-ci.org/wooorm/direction.svg?branch=master)](https://travis-ci.org/wooorm/direction) [![Coverage Status](https://img.shields.io/coveralls/wooorm/direction.svg)](https://coveralls.io/r/wooorm/direction?branch=master)

---

Detect direction: left-to-right, right-to-left, or neutral.

* Similar to [component/directionality](https://github.com/component/directionality) — which does not support 'neutral';
* Based on [Google Closure Library](https://github.com/google/closure-library/blob/master/closure/goog/i18n/bidi.js) — the methodology.

## Installation

NPM:
```sh
$ npm install direction
```

Component.js:
```sh
$ component install wooorm/direction
```

## Usage

```js
var direction = require('direction');

direction("A"); // "ltr"
direction("anglais"); // "ltr"
direction("بسيطة"); // "rtl"
direction("@"); // "neutral"
```

## License

MIT
18 changes: 18 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "direction",
"repository": "wooorm/direction",
"description": "Detect directionality: left-to-right, right-to-left, or neutral",
"version": "0.0.1",
"keywords": [
"writing",
"system",
"direction",
"directionality",
"rtl",
"ltr"
],
"scripts" : [
"index.js"
],
"license": "MIT"
}
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

var GROUP_LEFT_TO_RIGHT, GROUP_RIGHT_TO_LEFT,
EXPRESSION_LEFT_TO_RIGHT, EXPRESSION_RIGHT_TO_LEFT;

GROUP_LEFT_TO_RIGHT = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6' +
'\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u200E\u2C00-\uFB1C' +
'\uFE00-\uFE6F\uFEFD-\uFFFF';

GROUP_RIGHT_TO_LEFT = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC';

EXPRESSION_LEFT_TO_RIGHT = new RegExp(
'^[^' + GROUP_RIGHT_TO_LEFT + ']*[' + GROUP_LEFT_TO_RIGHT + ']'
);

EXPRESSION_RIGHT_TO_LEFT = new RegExp(
'^[^' + GROUP_LEFT_TO_RIGHT + ']*[' + GROUP_RIGHT_TO_LEFT + ']'
);

function direction(value) {
value = value.toString();

if (EXPRESSION_RIGHT_TO_LEFT.test(value)) {
return 'rtl';
}

if (EXPRESSION_LEFT_TO_RIGHT.test(value)) {
return 'ltr';
}

return 'neutral';
}

module.exports = direction;
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "direction",
"version": "0.0.1",
"description": "Detect directionality: left-to-right, right-to-left, or neutral",
"keywords": [
"writing",
"system",
"direction",
"directionality",
"rtl",
"ltr"
],
"author": "Titus Wormer <tituswormer@gmail.com>",
"license": "MIT",
"devDependencies": {
"istanbul": "~0.2.11",
"jscs": "^1.4.5",
"eslint": "^0.6.2",
"mocha": "~1.20.1"
},
"repository": {
"type": "git",
"url": "https://github.com/wooorm/direction.git"
},
"scripts": {
"test": "node_modules/.bin/_mocha --reporter spec --check-leaks -u exports spec/direction.spec.js",
"test-travis": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --check-leaks -u exports spec/direction.spec.js",
"lint": "node_modules/.bin/eslint index.js --env node --env browser --rule 'quotes: [2, single], no-cond-assign: false' && node_modules/.bin/eslint spec/direction.spec.js --env node --env mocha --rule 'quotes: [2, single], no-loop-func: false' && node_modules/.bin/jscs index.js spec/direction.spec.js --reporter=inline",
"coverage": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -- spec spec/direction.spec.js",
"make": "npm run-script lint && npm run-script coverage"
},
"testling": {
"files": "spec/direction.spec.js",
"harness": "mocha",
"browsers": [
"iexplore/latest",
"chrome/latest",
"chrome/canary",
"firefox/latest",
"firefox/nightly",
"opera/latest",
"opera/next",
"safari/latest",
"iphone/latest",
"android-browser/latest"
]
}
}
47 changes: 47 additions & 0 deletions spec/direction.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

var direction, assert, data;

direction = require('..');
assert = require('assert');

data = {
'a' : 'ltr',
'\u05e0' : 'rtl',
'\u0000' : 'neutral',
'\u0020' : 'neutral',
'!' : 'neutral',
'@' : 'neutral',
'[' : 'neutral',
'`' : 'neutral',
'0' : 'neutral',
'123' : 'neutral',
'A' : 'ltr',
'english' : 'ltr',
'sentence' : 'ltr',
'Un' : 'ltr',
'simple' : 'ltr',
'anglais' : 'ltr',
'phrase' : 'ltr',
'أ' : 'rtl',
'الجملة' : 'rtl',
'الانجليزية' : 'rtl',
'بسيطة' : 'rtl'
};

function classifyDirection(input, output) {
it('should classify `' + input + '` as `' + output + '` ', function () {
assert(direction(input) === output);
});
}

describe('direction()', function () {
it('should be of type `function`', function () {
assert(typeof direction === 'function');
});

var value;
for (value in data) {
classifyDirection(value, data[value]);
}
});

0 comments on commit cf9dcc2

Please sign in to comment.