-
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
0 parents
commit 6327ca1
Showing
11 changed files
with
353 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = 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 @@ | ||
* text=auto |
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,2 @@ | ||
coverage | ||
node_modules |
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,12 @@ | ||
git: | ||
depth: 1 | ||
branches: | ||
except: /^v\d/ | ||
language: node_js | ||
node_js: stable | ||
after_script: | ||
- npm install istanbul-coveralls | ||
- npm run-script coverage | ||
- node node_modules/.bin/istanbul-coveralls | ||
notifications: | ||
email: 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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Shinnosuke Watanabe | ||
|
||
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. |
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,59 @@ | ||
# is-vfile-message | ||
|
||
[![NPM version](https://img.shields.io/npm/v/is-vfile-message.svg)](https://www.npmjs.com/package/is-vfile-message) | ||
[![Bower version](https://img.shields.io/bower/v/is-vfile-message.svg)](https://github.com/shinnn/is-vfile-message/releases) | ||
[![Build Status](https://travis-ci.org/shinnn/is-vfile-message.svg?branch=master)](https://travis-ci.org/shinnn/is-vfile-message) | ||
[![Coverage Status](https://img.shields.io/coveralls/shinnn/is-vfile-message.svg)](https://coveralls.io/github/shinnn/is-vfile-message) | ||
[![devDependency Status](https://david-dm.org/shinnn/is-vfile-message/dev-status.svg)](https://david-dm.org/shinnn/is-vfile-message#info=devDependencies) | ||
|
||
Check if a value is a [VFileMessage](https://github.com/wooorm/vfile#vfilemessage) object | ||
|
||
```javascript | ||
const VFile = require('vfile'); | ||
const isVFileMessage = require('is-vfile-message'); | ||
|
||
const file = new VFile(); | ||
|
||
isVFileMessage(file.warn('error!')); //=> true | ||
``` | ||
|
||
## Installation | ||
|
||
### Package managers | ||
|
||
#### [npm](https://www.npmjs.com/) | ||
|
||
``` | ||
npm install is-vfile-message | ||
``` | ||
|
||
#### [bower](http://bower.io/) | ||
|
||
``` | ||
bower install is-vfile-message | ||
``` | ||
|
||
### Standalone | ||
|
||
[Download the script file directly.](https://raw.githubusercontent.com/shinnn/is-vfile-message/master/browser.js) | ||
|
||
## API | ||
|
||
### isVFileMessage(*value*) | ||
|
||
*value*: any value | ||
Return: `Boolean` | ||
|
||
It returns `true` if the argument is a valid [VFileMessage](https://github.com/wooorm/vfile/blob/500c69c2faa29cc837d6859009ff6b0788690aa9/index.js#L45-L71) object, otherwise `false`. | ||
|
||
```javascript | ||
isVFileMessage(new Error()); //=> false | ||
isVFileMessage({name: 'error!'}); //=> false | ||
isVFileMessage(); //=> false | ||
``` | ||
|
||
## License | ||
|
||
Copyright (c) 2015 [Shinnosuke Watanabe](https://github.com/shinnn) | ||
|
||
Licensed under [the MIT License](./LICENSE). |
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,37 @@ | ||
{ | ||
"name": "is-vfile-message", | ||
"description": "Check if a value is a VFileMessage object", | ||
"keywords": [ | ||
"vfile", | ||
"virtual", | ||
"file", | ||
"message", | ||
"check", | ||
"checker", | ||
"if", | ||
"bool", | ||
"boolean", | ||
"error", | ||
"type", | ||
"typecheck", | ||
"type-check" | ||
], | ||
"main": "browser.js", | ||
"moduleType": "globals", | ||
"homepage": "https://github.com/shinnn/is-vfile-message", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/shinnn/is-vfile-message.git" | ||
}, | ||
"authors": [ | ||
"Shinnosuke Watanabe (https://github.com/shinnn)" | ||
], | ||
"license": "MIT", | ||
"ignore": [ | ||
"**/.*", | ||
"*.js", | ||
"*.json", | ||
"coverage", | ||
"node_modules" | ||
] | ||
} |
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,56 @@ | ||
/*! | ||
* is-vfile-message | MIT (c) Shinnosuke Watanabe | ||
* https://github.com/shinnn/is-vfile-message | ||
*/ | ||
(function() { | ||
'use strict'; | ||
|
||
var locationPropNames = ['start', 'end']; | ||
var rangePropNames = ['line', 'column']; | ||
var i; | ||
var ii; | ||
var p; | ||
var pp; | ||
var loc; | ||
|
||
window.isVFileMessage = function isVFileMessage(obj) { | ||
if (!( | ||
obj instanceof Error && | ||
typeof obj.name === 'string' && | ||
typeof obj.file === 'string' && | ||
typeof obj.reason === 'string' && | ||
(obj.line === null || typeof obj.line === 'number') && | ||
(obj.column === null || typeof obj.column === 'number') && | ||
obj.location !== null && | ||
typeof obj.location === 'object' && | ||
typeof obj.fatal === 'boolean' | ||
)) { | ||
return false; | ||
} | ||
|
||
loc = obj.location; | ||
i = 2; | ||
|
||
while (i--) { | ||
p = locationPropNames[i]; | ||
|
||
if (!( | ||
loc[p] !== null && | ||
typeof loc[p] === 'object' | ||
)) { | ||
return false; | ||
} | ||
|
||
ii = 2; | ||
|
||
while (ii--) { | ||
pp = rangePropNames[ii]; | ||
if (!(loc[p][pp] === null || typeof loc[p][pp] === 'number')) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
})(); |
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,54 @@ | ||
/*! | ||
* is-vfile-message | MIT (c) Shinnosuke Watanabe | ||
* https://github.com/shinnn/is-vfile-message | ||
*/ | ||
'use strict'; | ||
|
||
var locationPropNames = ['start', 'end']; | ||
var rangePropNames = ['line', 'column']; | ||
var i; | ||
var ii; | ||
var p; | ||
var pp; | ||
var loc; | ||
|
||
module.exports = function isVFileMessage(obj) { | ||
if (!( | ||
obj instanceof Error && | ||
typeof obj.name === 'string' && | ||
typeof obj.file === 'string' && | ||
typeof obj.reason === 'string' && | ||
(obj.line === null || typeof obj.line === 'number') && | ||
(obj.column === null || typeof obj.column === 'number') && | ||
obj.location !== null && | ||
typeof obj.location === 'object' && | ||
typeof obj.fatal === 'boolean' | ||
)) { | ||
return false; | ||
} | ||
|
||
loc = obj.location; | ||
i = 2; | ||
|
||
while (i--) { | ||
p = locationPropNames[i]; | ||
|
||
if (!( | ||
loc[p] !== null && | ||
typeof loc[p] === 'object' | ||
)) { | ||
return false; | ||
} | ||
|
||
ii = 2; | ||
|
||
while (ii--) { | ||
pp = rangePropNames[ii]; | ||
if (!(loc[p][pp] === null || typeof loc[p][pp] === 'number')) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
}; |
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,40 @@ | ||
{ | ||
"name": "is-vfile-message", | ||
"version": "1.0.0", | ||
"description": "Check if a value is a VFileMessage object", | ||
"repository": "shinnn/is-vfile-message", | ||
"author": "Shinnosuke Watanabe (https://github.com/shinnn)", | ||
"scripts": { | ||
"pretest": "eslint --fix --config @shinnn browser.js index.js test.js", | ||
"test": "node --strong_mode --throw-deprecation --track-heap-objects test.js | tap-spec", | ||
"coverage": "node --strong_mode node_modules/.bin/istanbul cover test.js" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"vfile", | ||
"virtual", | ||
"file", | ||
"message", | ||
"check", | ||
"checker", | ||
"if", | ||
"bool", | ||
"boolean", | ||
"error", | ||
"type", | ||
"typecheck", | ||
"type-check", | ||
"client-side", | ||
"browser" | ||
], | ||
"devDependencies": { | ||
"@shinnn/eslint-config": "^1.4.0", | ||
"eslint": "^1.10.2", | ||
"istanbul": "^0.4.1", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.2.2" | ||
} | ||
} |
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,60 @@ | ||
'use strong'; | ||
|
||
const alex = require('alex'); | ||
const test = require('tape'); | ||
const VFile = require('vfile'); | ||
|
||
function runTest(description, isVFileMessage) { | ||
test(description, t => { | ||
t.plan(7); | ||
|
||
t.strictEqual(isVFileMessage.name, 'isVFileMessage', 'should have a function name.'); | ||
|
||
t.strictEqual( | ||
isVFileMessage(alex('maniac').messages[0]), | ||
true, | ||
'should return true when it takes a VFileMessage.' | ||
); | ||
|
||
t.strictEqual( | ||
isVFileMessage((new VFile()).warn('')), | ||
true, | ||
'should return true even if it takes an almost empty VFileMessage.' | ||
); | ||
|
||
const fakeMessage = new Error(); | ||
fakeMessage.name = ''; | ||
fakeMessage.file = ''; | ||
fakeMessage.reason = ''; | ||
fakeMessage.line = 1; | ||
fakeMessage.column = 1; | ||
fakeMessage.location = {}; | ||
fakeMessage.fatal = false; | ||
|
||
t.strictEqual( | ||
isVFileMessage(fakeMessage), | ||
false, | ||
'should return false when it doesn\'t match the spec.' | ||
); | ||
|
||
fakeMessage.location.start = {}; | ||
fakeMessage.location.end = {}; | ||
|
||
t.strictEqual( | ||
isVFileMessage(fakeMessage), | ||
false, | ||
'should return false when the properties don\'t match the spec.' | ||
); | ||
|
||
t.strictEqual(isVFileMessage(1), false, 'should return false when it takes non-object value.'); | ||
|
||
t.strictEqual(isVFileMessage(), false, 'should return false when it takes no arguments.'); | ||
}); | ||
} | ||
|
||
runTest('require(\'is-vfile-message\')', require('.')); | ||
|
||
global.window = {}; | ||
require('./' + require('./bower.json').main); | ||
|
||
runTest('window.isVFileMessage', global.window.isVFileMessage); |