diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8c52ff9 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2a083b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bower_components +coverage +node_modules diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e05e1e7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +git: + depth: 1 +branches: + except: /^v\d/ +language: node_js +node_js: node +script: npm run-script pretest && npm run-script coverage +after_script: + - npm install istanbul-coveralls + - node node_modules/.bin/istanbul-coveralls diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1d6cf10 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2016 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5d0ab0 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# array-to-sentence-ja + +[![NPM version](https://img.shields.io/npm/v/array-to-sentence-ja.svg)](https://www.npmjs.com/package/array-to-sentence-ja) +[![Build Status](https://travis-ci.org/shinnn/array-to-sentence-ja.svg?branch=master)](https://travis-ci.org/shinnn/array-to-sentence-ja) +[![Coverage Status](https://img.shields.io/coveralls/shinnn/array-to-sentence-ja.svg)](https://coveralls.io/github/shinnn/array-to-sentence-ja?branch=master) +[![Dependency Status](https://david-dm.org/shinnn/array-to-sentence-ja.svg)](https://david-dm.org/shinnn/array-to-sentence-ja) +[![devDependency Status](https://david-dm.org/shinnn/array-to-sentence-ja/dev-status.svg)](https://david-dm.org/shinnn/array-to-sentence-ja#info=devDependencies) + +Japanese-friendly version of [array-to-sentence](https://github.com/shinnn/array-to-sentence): + +> Join all elements of an array and create a human-readable string + +```javascript +import arrayToSentenceJa from 'array-to-sentence-ja'; + +arrayToSentenceJa(['春', '夏', '秋', '冬']); //=> '春、夏、秋および冬' +``` + +## Installation + +#### [npm](https://www.npmjs.com/) + +``` +npm install array-to-sentence-ja +``` + +#### [Bower](http://bower.io/) + +``` +bower install array-to-sentence-ja +``` + +### Standalone + +[Download the script file directly.](https://raw.githubusercontent.com/shinnn/array-to-sentence-ja/master/browser.js) + +## API + +### arrayToSentenceJa(*array* [, *options*]) + +*array*: `Array` of any values +*options*: `Object` +Return: `String` + +Almost the same as [array-to-sentence](https://github.com/shinnn/array-to-sentence#arraytosentencearray--options), except that [`separator`](https://github.com/shinnn/array-to-sentence#optionsseparator) option defaults to `'、'`, and [`lastSeparator`](https://github.com/shinnn/array-to-sentence#optionslastseparator) option defaults to `'および'`. + +```javascript +arrayToSentenceJa(['春', '夏', '秋', '冬'], {lastSeparator: '、そして'}); //=> '春、夏、秋、そして冬' +``` +## License + +Copyright (c) 2016 [Shinnosuke Watanabe](https://github.com/shinnn) + +Licensed under [the MIT License](./LICENSE). diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..eb5d086 --- /dev/null +++ b/bower.json @@ -0,0 +1,41 @@ +{ + "name": "array-to-sentence-ja", + "description": "Japanese-friendly version of array-to-sentence", + "keywords": [ + "to-sentence", + "sentence", + "array", + "join", + "human", + "readable", + "string", + "separator", + "comma", + "and", + "natural-language", + "ja", + "japanese" + ], + "main": "browser.js", + "moduleType": "globals", + "homepage": "https://github.com/shinnn/array-to-sentence-ja", + "repository": { + "type": "git", + "url": "git://github.com/shinnn/array-to-sentence-ja.git" + }, + "authors": [ + "Shinnosuke Watanabe (https://github.com/shinnn)" + ], + "license": "MIT", + "dependencies": { + "array-to-sentence": "^1.1.0" + }, + "ignore": [ + "**/.*", + "*.js", + "*.json", + "*.yml", + "coverage", + "node_modules" + ] +} diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..330a81f --- /dev/null +++ b/browser.js @@ -0,0 +1,12 @@ +/*! + * array-to-sentence-ja | MIT (c) Shinnosuke Watanabe + * https://github.com/shinnn/array-to-sentence-ja +*/ +window.arrayToSentenceJa = function arrayToSentenceJa(arr, options) { + 'use strict'; + + return window.arrayToSentence(arr, Object.assign({ + separator: '、', + lastSeparator: 'および' + }, options)); +}; diff --git a/index.js b/index.js new file mode 100644 index 0000000..546d571 --- /dev/null +++ b/index.js @@ -0,0 +1,15 @@ +/*! + * array-to-sentence-ja | MIT (c) Shinnosuke Watanabe + * https://github.com/shinnn/array-to-sentence-ja +*/ +'use strict'; + +var arrayToSentence = require('array-to-sentence'); +var objectAssign = require('object-assign'); + +module.exports = function arrayToSentenceJa(arr, options) { + return arrayToSentence(arr, objectAssign({ + separator: '、', + lastSeparator: 'および' + }, options)); +}; diff --git a/index.jsnext.js b/index.jsnext.js new file mode 100644 index 0000000..17e6182 --- /dev/null +++ b/index.jsnext.js @@ -0,0 +1,12 @@ +/*! + * array-to-sentence-ja | MIT (c) Shinnosuke Watanabe + * https://github.com/shinnn/array-to-sentence-ja +*/ +import arrayToSentence from 'array-to-sentence'; + +export default function arrayToSentenceJa(arr, options) { + return arrayToSentence(arr, Object.assign({ + separator: '、', + lastSeparator: 'および' + }, options)); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..626a9e8 --- /dev/null +++ b/package.json @@ -0,0 +1,51 @@ +{ + "name": "array-to-sentence-ja", + "version": "0.0.0", + "description": "Japanese-friendly version of array-to-sentence", + "repository": "shinnn/array-to-sentence-ja", + "author": "Shinnosuke Watanabe (https://github.com/shinnn)", + "scripts": { + "pretest": "bower install --production && eslint --fix --config @shinnn --ignore-path .gitignore .", + "test": "node --strong_mode --throw-deprecation --track-heap-objects test.js | tap-spec", + "coverage": "istanbul cover -x=bower_components/array-to-sentence/* test.js" + }, + "license": "MIT", + "jsnext:main": "index.jsnext.js", + "files": [ + "index.js", + "index.jsnext.js" + ], + "keywords": [ + "to-sentence", + "sentence", + "array", + "join", + "human", + "readable", + "string", + "separator", + "comma", + "and", + "natural-language", + "ja", + "japanese", + "browser", + "client-side" + ], + "dependencies": { + "array-to-sentence": "^1.1.0", + "object-assign": "^4.1.0" + }, + "devDependencies": { + "@shinnn/eslint-config": "^2.3.0", + "bower": "^1.7.9", + "eslint": "^2.12.0", + "istanbul": "^0.4.3", + "require-bower-files": "^3.0.0", + "require-from-string": "^1.2.0", + "rollup": "^0.31.2", + "rollup-plugin-node-resolve": "^1.7.0", + "tap-spec": "^4.1.1", + "tape": "^4.5.1" + } +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..00b984c --- /dev/null +++ b/test.js @@ -0,0 +1,60 @@ +'use strong'; + +const requireBowerFiles = require('require-bower-files'); +const requireFromString = require('require-from-string'); +const {rollup} = require('rollup'); +const rollupNodeResolve = require('rollup-plugin-node-resolve'); +const test = require('tape'); + +global.window = {}; +requireBowerFiles({self: true}); + +function runTest(arrayToSentenceJa, description) { + test(description, t => { + t.strictEqual(arrayToSentenceJa.name, 'arrayToSentenceJa', 'should have a function name.'); + + t.strictEqual( + arrayToSentenceJa(['a', 'b', 'c']), + 'a、bおよびc', + 'should join all elements of an array and create a string.' + ); + + t.strictEqual( + arrayToSentenceJa(['右', '左', '上', '下'], { + separator: 'と', + lastSeparator: '、そして' + }), + '右と左と上、そして下', + 'should override separators via options.' + ); + + t.throws( + () => arrayToSentenceJa('foo', null), + /^TypeError.*foo is not an array\. Expected an array\./, + 'should throw a type error when the first argument is not an array.' + ); + + t.throws( + () => arrayToSentenceJa([], {separator: false}), + /^TypeError.*false is not a string\. `separator` option must be a string\./, + 'should throw a type error when `separator` option is not a string.' + ); + + t.throws( + () => arrayToSentenceJa([], {lastSeparator: true}), + /^TypeError.*true is not a string\. `lastSeparator` option must be a string\./, + 'should throw a type error when `lastSeparator` option is not a string.' + ); + + t.end(); + }); +} + +rollup({ + entry: require('./package.json')['jsnext:main'], + plugins: rollupNodeResolve({jsnext: true}) +}).then(bundle => { + runTest(require('.'), 'require(\'array-to-sentence-ja\')'); + runTest(global.window.arrayToSentenceJa, 'window.arrayToSentenceJa'); + runTest(requireFromString(bundle.generate({format: 'cjs'}).code), 'Module exports'); +});