pax_global_header00006660000000000000000000000064130671463200014514gustar00rootroot0000000000000052 comment=0e6e4a2752aa013b8e9477145c7b8132c95a82ef camelcase-4.1.0/000077500000000000000000000000001306714632000134335ustar00rootroot00000000000000camelcase-4.1.0/.editorconfig000066400000000000000000000002761306714632000161150ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 camelcase-4.1.0/.gitattributes000066400000000000000000000000351306714632000163240ustar00rootroot00000000000000* text=auto *.js text eol=lf camelcase-4.1.0/.gitignore000066400000000000000000000000151306714632000154170ustar00rootroot00000000000000node_modules camelcase-4.1.0/.travis.yml000066400000000000000000000000671306714632000155470ustar00rootroot00000000000000sudo: false language: node_js node_js: - '6' - '4' camelcase-4.1.0/index.js000066400000000000000000000026131306714632000151020ustar00rootroot00000000000000'use strict'; function preserveCamelCase(str) { let isLastCharLower = false; let isLastCharUpper = false; let isLastLastCharUpper = false; for (let i = 0; i < str.length; i++) { const c = str[i]; if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) { str = str.substr(0, i) + '-' + str.substr(i); isLastCharLower = false; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = true; i++; } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) { str = str.substr(0, i - 1) + '-' + str.substr(i - 1); isLastLastCharUpper = isLastCharUpper; isLastCharUpper = false; isLastCharLower = true; } else { isLastCharLower = c.toLowerCase() === c; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = c.toUpperCase() === c; } } return str; } module.exports = function (str) { if (arguments.length > 1) { str = Array.from(arguments) .map(x => x.trim()) .filter(x => x.length) .join('-'); } else { str = str.trim(); } if (str.length === 0) { return ''; } if (str.length === 1) { return str.toLowerCase(); } if (/^[a-z0-9]+$/.test(str)) { return str; } const hasUpperCase = str !== str.toLowerCase(); if (hasUpperCase) { str = preserveCamelCase(str); } return str .replace(/^[_.\- ]+/, '') .toLowerCase() .replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase()); }; camelcase-4.1.0/license000066400000000000000000000021371306714632000150030ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.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. camelcase-4.1.0/package.json000066400000000000000000000013351306714632000157230ustar00rootroot00000000000000{ "name": "camelcase", "version": "4.1.0", "description": "Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar", "license": "MIT", "repository": "sindresorhus/camelcase", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "camelcase", "camel-case", "camel", "case", "dash", "hyphen", "dot", "underscore", "separator", "string", "text", "convert" ], "devDependencies": { "ava": "*", "xo": "*" }, "xo": { "esnext": true } } camelcase-4.1.0/readme.md000066400000000000000000000020261306714632000152120ustar00rootroot00000000000000# camelcase [![Build Status](https://travis-ci.org/sindresorhus/camelcase.svg?branch=master)](https://travis-ci.org/sindresorhus/camelcase) > Convert a dash/dot/underscore/space separated string to camelCase: `foo-bar` → `fooBar` ## Install ``` $ npm install --save camelcase ``` ## Usage ```js const camelCase = require('camelcase'); camelCase('foo-bar'); //=> 'fooBar' camelCase('foo_bar'); //=> 'fooBar' camelCase('Foo-Bar'); //=> 'fooBar' camelCase('--foo.bar'); //=> 'fooBar' camelCase('__foo__bar__'); //=> 'fooBar' camelCase('foo bar'); //=> 'fooBar' console.log(process.argv[3]); //=> '--foo-bar' camelCase(process.argv[3]); //=> 'fooBar' camelCase('foo', 'bar'); //=> 'fooBar' camelCase('__foo__', '--bar'); //=> 'fooBar' ``` ## Related - [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module - [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase ## License MIT © [Sindre Sorhus](https://sindresorhus.com) camelcase-4.1.0/test.js000066400000000000000000000027621306714632000147570ustar00rootroot00000000000000import test from 'ava'; import m from './'; test('camelCase', t => { t.is(m('foo'), 'foo'); t.is(m('foo-bar'), 'fooBar'); t.is(m('foo-bar-baz'), 'fooBarBaz'); t.is(m('foo--bar'), 'fooBar'); t.is(m('--foo-bar'), 'fooBar'); t.is(m('--foo--bar'), 'fooBar'); t.is(m('FOO-BAR'), 'fooBar'); t.is(m('FOÈ-BAR'), 'foèBar'); t.is(m('-foo-bar-'), 'fooBar'); t.is(m('--foo--bar--'), 'fooBar'); t.is(m('foo.bar'), 'fooBar'); t.is(m('foo..bar'), 'fooBar'); t.is(m('..foo..bar..'), 'fooBar'); t.is(m('foo_bar'), 'fooBar'); t.is(m('__foo__bar__'), 'fooBar'); t.is(m('__foo__bar__'), 'fooBar'); t.is(m('foo bar'), 'fooBar'); t.is(m(' foo bar '), 'fooBar'); t.is(m('-'), '-'); t.is(m(' - '), '-'); t.is(m('fooBar'), 'fooBar'); t.is(m('fooBar-baz'), 'fooBarBaz'); t.is(m('foìBar-baz'), 'foìBarBaz'); t.is(m('fooBarBaz-bazzy'), 'fooBarBazBazzy'); t.is(m('FBBazzy'), 'fbBazzy'); t.is(m('F'), 'f'); t.is(m('FooBar'), 'fooBar'); t.is(m('Foo'), 'foo'); t.is(m('FOO'), 'foo'); t.is(m('foo', 'bar'), 'fooBar'); t.is(m('foo', '-bar'), 'fooBar'); t.is(m('foo', '-bar', 'baz'), 'fooBarBaz'); t.is(m('', ''), ''); t.is(m('--'), ''); t.is(m(''), ''); t.is(m('--__--_--_'), ''); t.is(m('---_', '--', '', '-_- '), ''); t.is(m('foo bar?'), 'fooBar?'); t.is(m('foo bar!'), 'fooBar!'); t.is(m('foo bar$'), 'fooBar$'); t.is(m('foo-bar#'), 'fooBar#'); t.is(m('XMLHttpRequest'), 'xmlHttpRequest'); t.is(m('AjaxXMLHttpRequest'), 'ajaxXmlHttpRequest'); t.is(m('Ajax-XMLHttpRequest'), 'ajaxXmlHttpRequest'); });