From 2d836b2b2649ac23cd06fe2dd15e4d98b283b7c3 Mon Sep 17 00:00:00 2001 From: ZHAO Jinxiang Date: Sat, 20 Jun 2020 01:20:38 +0800 Subject: [PATCH] feat: add rollup and esm, remove toCase --- dist/Case.js | 372 +++++++++++++++++++++++++----------------- dist/Case.js.map | 1 + dist/Case.min.js | 7 +- dist/Case.min.js.map | 2 +- dist/Case.min.mjs | 2 + dist/Case.min.mjs.map | 1 + dist/Case.mjs | 233 ++++++++++++++++++++++++++ dist/Case.mjs.map | 1 + package-lock.json | 148 +++++++++++++++++ package.json | 13 +- rollup.config.js | 42 +++++ src/Case.js | 173 -------------------- src/Case.mjs | 49 ++++++ src/component.js | 2 - src/toCase.js | 24 --- src/types.mjs | 68 ++++++++ src/utils.mjs | 93 +++++++++++ test/Case.html | 1 - test/Case_test.js | 31 +--- 19 files changed, 877 insertions(+), 386 deletions(-) create mode 100644 dist/Case.js.map create mode 100644 dist/Case.min.mjs create mode 100644 dist/Case.min.mjs.map create mode 100644 dist/Case.mjs create mode 100644 dist/Case.mjs.map create mode 100644 rollup.config.js delete mode 100644 src/Case.js create mode 100644 src/Case.mjs delete mode 100644 src/component.js delete mode 100644 src/toCase.js create mode 100644 src/types.mjs create mode 100644 src/utils.mjs diff --git a/dist/Case.js b/dist/Case.js index af199f7..606cc15 100644 --- a/dist/Case.js +++ b/dist/Case.js @@ -1,171 +1,241 @@ -/*! case - v1.6.3 - 2020-03-24 -* Copyright (c) 2020 Nathan Bubna; Licensed (MIT OR GPL-3.0-or-later) */ -(function() { - "use strict"; - var unicodes = function(s, prefix) { +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = global || self, global.Case = factory()); +}(this, (function () { 'use strict'; + + function unicodes(s, prefix) { prefix = prefix || ''; - return s.replace(/(^|-)/g, '$1\\u'+prefix).replace(/,/g, '\\u'+prefix); - }, - basicSymbols = unicodes('20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7', '00'), - baseLowerCase = 'a-z'+unicodes('DF-F6,F8-FF', '00'), - baseUpperCase = 'A-Z'+unicodes('C0-D6,D8-DE', '00'), - improperInTitle = 'A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via', - regexps = function(symbols, lowers, uppers, impropers) { + return s.replace(/(^|-)/g, '$1\\u' + prefix).replace(/,/g, '\\u' + prefix); + } + + const basicSymbols = unicodes( + '20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7', + '00', + ); + const baseLowerCase = 'a-z' + unicodes('DF-F6,F8-FF', '00'); + const baseUpperCase = 'A-Z' + unicodes('C0-D6,D8-DE', '00'); + const improperInTitle = + 'A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via'; + + function regexps(symbols, lowers, uppers, impropers) { symbols = symbols || basicSymbols; lowers = lowers || baseLowerCase; uppers = uppers || baseUpperCase; impropers = impropers || improperInTitle; return { - capitalize: new RegExp('(^|['+symbols+'])(['+lowers+'])', 'g'), - pascal: new RegExp('(^|['+symbols+'])+(['+lowers+uppers+'])', 'g'), - fill: new RegExp('['+symbols+']+(.|$)','g'), - sentence: new RegExp('(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")(['+lowers+'])', 'g'), - improper: new RegExp('\\b('+impropers+')\\b', 'g'), - relax: new RegExp('([^'+uppers+'])(['+uppers+']*)(['+uppers+'])(?=[^'+uppers+']|$)', 'g'), - upper: new RegExp('^[^'+lowers+']+$'), + capitalize: new RegExp('(^|[' + symbols + '])([' + lowers + '])', 'g'), + pascal: new RegExp( + '(^|[' + symbols + '])+([' + lowers + uppers + '])', + 'g', + ), + fill: new RegExp('[' + symbols + ']+(.|$)', 'g'), + sentence: new RegExp( + '(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")([' + lowers + '])', + 'g', + ), + improper: new RegExp('\\b(' + impropers + ')\\b', 'g'), + relax: new RegExp( + '([^' + + uppers + + '])([' + + uppers + + ']*)([' + + uppers + + '])(?=[^' + + uppers + + ']|$)', + 'g', + ), + upper: new RegExp('^[^' + lowers + ']+$'), hole: /[^\s]\s[^\s]/, apostrophe: /'/g, - room: new RegExp('['+symbols+']') + room: new RegExp('[' + symbols + ']'), }; - }, - re = regexps(), - _ = { - re: re, - unicodes: unicodes, - regexps: regexps, - types: [], - up: String.prototype.toUpperCase, - low: String.prototype.toLowerCase, - cap: function(s) { - return _.up.call(s.charAt(0))+s.slice(1); - }, - decap: function(s) { - return _.low.call(s.charAt(0))+s.slice(1); - }, - deapostrophe: function(s) { - return s.replace(re.apostrophe, ''); - }, - fill: function(s, fill, deapostrophe) { - if (fill != null) { - s = s.replace(re.fill, function(m, next) { - return next ? fill + next : ''; - }); - } - if (deapostrophe) { - s = _.deapostrophe(s); - } - return s; - }, - prep: function(s, fill, pascal, upper) { - s = s == null ? '' : s + '';// force to string - if (!upper && re.upper.test(s)) { - s = _.low.call(s); - } - if (!fill && !re.hole.test(s)) { - var holey = _.fill(s, ' '); - if (re.hole.test(holey)) { - s = holey; - } - } - if (!pascal && !re.room.test(s)) { - s = s.replace(re.relax, _.relax); - } - return s; - }, - relax: function(m, before, acronym, caps) { - return before + ' ' + (acronym ? acronym+' ' : '') + caps; + } + + const re = regexps(); + + const up = String.prototype.toUpperCase; + const low = String.prototype.toLowerCase; + function cap(s) { + return up.call(s.charAt(0)) + s.slice(1); + } + function decap(s) { + return low.call(s.charAt(0)) + s.slice(1); + } + function deapostrophe(s) { + return s.replace(re.apostrophe, ''); + } + function fill(s, fill, _deapostrophe) { + if (fill != null) { + s = s.replace(re.fill, function (m, next) { + return next ? fill + next : ''; + }); } - }, - Case = { - _: _, - of: function(s) { - for (var i=0,m=_.types.length; i 0 && i < s.lastIndexOf(' ') ? _.low.call(small) : small; + if (!pascal && !re.room.test(s)) { + s = s.replace(re.relax, relax); + } + return s; + } + function relax(m, before, acronym, caps) { + return before + ' ' + (acronym ? acronym + ' ' : '') + caps; + } + + var _ = /*#__PURE__*/Object.freeze({ + __proto__: null, + unicodes: unicodes, + regexps: regexps, + re: re, + up: up, + low: low, + cap: cap, + decap: decap, + deapostrophe: deapostrophe, + fill: fill, + prep: prep, + relax: relax + }); + + function lower(s, fill$1, deapostrophe) { + return fill(low.call(prep(s, fill$1)), fill$1, deapostrophe); + } + function snake(s) { + return lower(s, '_', true); + } + function constant(s) { + return upper(s, '_', true); + } + function camel(s) { + return decap(pascal(s)); + } + function kebab(s) { + return lower(s, '-', true); + } + function upper(s, fill$1, deapostrophe) { + return fill(up.call(prep(s, fill$1, false, true)), fill$1, deapostrophe); + } + function capital(s, fill$1, deapostrophe) { + return fill( + prep(s).replace(re.capitalize, function (m, border, letter) { + return border + up.call(letter); + }), + fill$1, + deapostrophe, + ); + } + function header(s) { + return capital(s, '-', true); + } + function pascal(s) { + return fill( + prep(s, false, true).replace(re.pascal, function (m, border, letter) { + return up.call(letter); + }), + '', + true, + ); + } + function title(s) { + return capital(s).replace(re.improper, function (small, p, i, s) { + return i > 0 && i < s.lastIndexOf(' ') ? low.call(small) : small; + }); + } + function sentence(s, names, abbreviations) { + s = lower(s).replace(re.sentence, function (m, prelude, letter) { + return prelude + up.call(letter); + }); + if (names) { + names.forEach(function (name) { + s = s.replace(new RegExp('\\b' + lower(name) + '\\b', 'g'), cap); }); - }, - sentence: function(s, names, abbreviations) { - s = Case.lower(s).replace(re.sentence, function(m, prelude, letter) { - return prelude + _.up.call(letter); + } + if (abbreviations) { + abbreviations.forEach(function (abbr) { + s = s.replace( + new RegExp('(\\b' + lower(abbr) + '\\. +)(\\w)'), + function (m, abbrAndSpace, letter) { + return abbrAndSpace + low.call(letter); + }, + ); }); - if (names) { - names.forEach(function(name) { - s = s.replace(new RegExp('\\b'+Case.lower(name)+'\\b', "g"), _.cap); - }); - } - if (abbreviations) { - abbreviations.forEach(function(abbr) { - s = s.replace(new RegExp('(\\b'+Case.lower(abbr)+'\\. +)(\\w)'), function(m, abbrAndSpace, letter) { - return abbrAndSpace + _.low.call(letter); - }); - }); + } + return s; + } + + var types = /*#__PURE__*/Object.freeze({ + __proto__: null, + lower: lower, + snake: snake, + constant: constant, + camel: camel, + kebab: kebab, + upper: upper, + capital: capital, + header: header, + pascal: pascal, + title: title, + sentence: sentence + }); + + const typesArray = Object.keys(types); + + function of(s) { + for (var i = 0, m = typesArray.length; i < m; i++) { + if (Case[typesArray[i]].apply(Case, arguments) === s) { + return typesArray[i]; } - return s; } - }; + } + + function flip(s) { + return s.replace(/\w/g, function (l) { + return (l == up.call(l) ? low : up).call(l); + }); + } - // TODO: Remove "squish" in a future breaking release. - types.squish = types.pascal; - - // Allow import default - Case.default = Case; + function random(s) { + return s.replace(/\w/g, function (l) { + return (Math.round(Math.random()) ? up : low).call(l); + }); + } - for (var type in types) { - Case.type(type, types[type]); + function type(type, fn) { + Case[type] = fn; + typesArray.push(type); } - // export Case (AMD, commonjs, or global) - var define = typeof define === "function" ? define : function(){}; - define(typeof module === "object" && module.exports ? module.exports = Case : this.Case = Case); -}).call(this); + const utils = { + ..._, + types: typesArray, + }; + + const Case = { + _:utils, + of, + flip, + random, + type, + ...types, + }; + + return Case; + +}))); +//# sourceMappingURL=Case.js.map diff --git a/dist/Case.js.map b/dist/Case.js.map new file mode 100644 index 0000000..5dee3c9 --- /dev/null +++ b/dist/Case.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Case.js","sources":["../src/utils.mjs","../src/types.mjs","../src/Case.mjs"],"sourcesContent":null,"names":["fill","_.fill","_.low","_.prep","_.decap","_.up","_.cap"],"mappings":";;;;;;IAAO,SAAS,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE;IACpC,IAAI,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IAC1B,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;IAC/E,CAAC;AACD;IAC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C,SAAS;IACT,KAAK;IACL,CAAC;AACD;IACA,SAAS,IAAI,CAAC,CAAC,EAAE;IACjB,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE;IACzC,QAAQ,OAAO,CAAC,CAAC,IAAIG,EAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAGH,GAAK,GAAGG,EAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1D,KAAK,CAAC,CAAC;IACP,CAAC;AACD;IACA,SAAS,MAAM,CAAC,CAAC,EAAE;IACnB,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE;IACzC,QAAQ,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAGA,EAAI,GAAGH,GAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAClE,KAAK,CAAC,CAAC;IACP,CAAC;AACD;IACA,SAAS,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE;IACxB,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACpB,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;AACD;IACA,MAAM,KAAK,GAAG;IACd,IAAI,GAAG,CAAC;IACR,IAAI,KAAK,EAAE,UAAU;IACrB,CAAC,CAAC;AACF;AACK,UAAC,IAAI,GAAG;IACb,IAAI,CAAC,CAAC,KAAK;IACX,IAAI,EAAE;IACN,IAAI,IAAI;IACR,IAAI,MAAM;IACV,IAAI,IAAI;IACR,IAAI,GAAG,KAAK;IACZ;;;;;;;;"} \ No newline at end of file diff --git a/dist/Case.min.js b/dist/Case.min.js index 06e0eeb..ff78733 100644 --- a/dist/Case.min.js +++ b/dist/Case.min.js @@ -1,5 +1,2 @@ -/*! case - v1.6.3 - 2020-03-24 -* Copyright (c) 2020 Nathan Bubna; Licensed (MIT OR GPL-3.0-or-later) */ - -(function(){"use strict";function e(e,n){return n=n||"",e.replace(/(^|-)/g,"$1\\u"+n).replace(/,/g,"\\u"+n)}function n(e,n,r,t){return e=e||l,n=n||p,r=r||o,t=t||"A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via",{capitalize:new RegExp("(^|["+e+"])(["+n+"])","g"),pascal:new RegExp("(^|["+e+"])+(["+n+r+"])","g"),fill:new RegExp("["+e+"]+(.|$)","g"),sentence:new RegExp('(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")(['+n+"])","g"),improper:new RegExp("\\b("+t+")\\b","g"),relax:new RegExp("([^"+r+"])(["+r+"]*)(["+r+"])(?=[^"+r+"]|$)","g"),upper:new RegExp("^[^"+n+"]+$"),hole:/[^\s]\s[^\s]/,apostrophe:/'/g,room:new RegExp("["+e+"]")}}var l=e("20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7","00"),p="a-z"+e("DF-F6,F8-FF","00"),o="A-Z"+e("C0-D6,D8-DE","00"),u=n(),c={re:u,unicodes:e,regexps:n,types:[],up:String.prototype.toUpperCase,low:String.prototype.toLowerCase,cap:function(e){return c.up.call(e.charAt(0))+e.slice(1)},decap:function(e){return c.low.call(e.charAt(0))+e.slice(1)},deapostrophe:function(e){return e.replace(u.apostrophe,"")},fill:function(e,r,n){return null!=r&&(e=e.replace(u.fill,function(e,n){return n?r+n:""})),n&&(e=c.deapostrophe(e)),e},prep:function(e,n,r,t){if(e=null==e?"":e+"",!t&&u.upper.test(e)&&(e=c.low.call(e)),!n&&!u.hole.test(e)){var l=c.fill(e," ");u.hole.test(l)&&(e=l)}return r||u.room.test(e)||(e=e.replace(u.relax,c.relax)),e},relax:function(e,n,r,t){return n+" "+(r?r+" ":"")+t}},t={_:c,of:function(e){for(var n=0,r=c.types.length;n0&&t0&&r 0 && i < s.lastIndexOf(' ') ? low.call(small) : small; + }); +} +function sentence(s, names, abbreviations) { + s = lower(s).replace(re.sentence, function (m, prelude, letter) { + return prelude + up.call(letter); + }); + if (names) { + names.forEach(function (name) { + s = s.replace(new RegExp('\\b' + lower(name) + '\\b', 'g'), cap); + }); + } + if (abbreviations) { + abbreviations.forEach(function (abbr) { + s = s.replace( + new RegExp('(\\b' + lower(abbr) + '\\. +)(\\w)'), + function (m, abbrAndSpace, letter) { + return abbrAndSpace + low.call(letter); + }, + ); + }); + } + return s; +} + +var types = /*#__PURE__*/Object.freeze({ + __proto__: null, + lower: lower, + snake: snake, + constant: constant, + camel: camel, + kebab: kebab, + upper: upper, + capital: capital, + header: header, + pascal: pascal, + title: title, + sentence: sentence +}); + +const typesArray = Object.keys(types); + +function of(s) { + for (var i = 0, m = typesArray.length; i < m; i++) { + if (Case[typesArray[i]].apply(Case, arguments) === s) { + return typesArray[i]; + } + } +} + +function flip(s) { + return s.replace(/\w/g, function (l) { + return (l == up.call(l) ? low : up).call(l); + }); +} + +function random(s) { + return s.replace(/\w/g, function (l) { + return (Math.round(Math.random()) ? up : low).call(l); + }); +} + +function type(type, fn) { + Case[type] = fn; + typesArray.push(type); +} + +const utils = { + ..._, + types: typesArray, +}; + +const Case = { + _:utils, + of, + flip, + random, + type, + ...types, +}; + +export default Case; +//# sourceMappingURL=Case.mjs.map diff --git a/dist/Case.mjs.map b/dist/Case.mjs.map new file mode 100644 index 0000000..ae3f174 --- /dev/null +++ b/dist/Case.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"Case.mjs","sources":["../src/utils.mjs","../src/types.mjs","../src/Case.mjs"],"sourcesContent":null,"names":["fill","_.fill","_.low","_.prep","_.decap","_.up","_.cap"],"mappings":"AAAO,SAAS,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE;AACpC,IAAI,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;AAC1B,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;A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AC,CAAC,CAAC;AACjC,SAAS;AACT,KAAK;AACL,CAAC;AACD;AACA,SAAS,IAAI,CAAC,CAAC,EAAE;AACjB,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE;AACzC,QAAQ,OAAO,CAAC,CAAC,IAAIG,EAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAGH,GAAK,GAAGG,EAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAC1D,KAAK,CAAC,CAAC;AACP,CAAC;AACD;AACA,SAAS,MAAM,CAAC,CAAC,EAAE;AACnB,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE;AACzC,QAAQ,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAGA,EAAI,GAAGH,GAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAClE,KAAK,CAAC,CAAC;AACP,CAAC;AACD;AACA,SAAS,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE;AACxB,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AACpB,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AACD;AACA,MAAM,KAAK,GAAG;AACd,IAAI,GAAG,CAAC;AACR,IAAI,KAAK,EAAE,UAAU;AACrB,CAAC,CAAC;AACF;AACK,MAAC,IAAI,GAAG;AACb,IAAI,CAAC,CAAC,KAAK;AACX,IAAI,EAAE;AACN,IAAI,IAAI;AACR,IAAI,MAAM;AACV,IAAI,IAAI;AACR,IAAI,GAAG,KAAK;AACZ;;;;"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6bec878..666f0f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,32 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@babel/code-frame": { + "version": "7.10.1", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.1.tgz", + "integrity": "sha512-IGhtTmpjGbYzcEDOw7DcQtbQSXcG9ftmAXtWTu9V936vDye4xjjekktFAtgZsWpzTj/X01jocB46mTywm/4SZw==", + "dev": true, + "requires": { + "@babel/highlight": "^7.10.1" + } + }, + "@babel/helper-validator-identifier": { + "version": "7.10.1", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.1.tgz", + "integrity": "sha512-5vW/JXLALhczRCWP0PnFDMCJAchlBvM7f4uk/jXritBnIa6E1KmqmtrS3yn1LAnxFBypQ3eneLuXjsnfQsgILw==", + "dev": true + }, + "@babel/highlight": { + "version": "7.10.1", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.1.tgz", + "integrity": "sha512-8rMof+gVP8mxYZApLF/JgNDAkdKa+aJt3ZYxF8z6+j/hpeXL7iMsKCPHa2jNMHu/qqBwzQF4OHNoYi8dMA/rYg==", + "dev": true, + "requires": { + "@babel/helper-validator-identifier": "^7.10.1", + "chalk": "^2.0.0", + "js-tokens": "^4.0.0" + } + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -1608,6 +1634,13 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "dev": true, + "optional": true + }, "fstream": { "version": "0.1.31", "resolved": "https://registry.npmjs.org/fstream/-/fstream-0.1.31.tgz", @@ -2450,12 +2483,45 @@ "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", "dev": true }, + "jest-worker": { + "version": "26.0.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.0.0.tgz", + "integrity": "sha512-pPaYa2+JnwmiZjK9x7p9BoZht+47ecFCDFA/CJxspHzeDvQcfVBLWzCiWyo+EGrSiQMWZtCFo9iSvMZnAAo8vw==", + "dev": true, + "requires": { + "merge-stream": "^2.0.0", + "supports-color": "^7.0.0" + }, + "dependencies": { + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, "js-base64": { "version": "2.1.9", "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.1.9.tgz", "integrity": "sha1-8OgK4DmkvWVLXygfyT8EqRSn/M4=", "dev": true }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + }, "js-yaml": { "version": "3.13.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", @@ -2705,6 +2771,12 @@ "trim-newlines": "^1.0.0" } }, + "merge-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", + "dev": true + }, "micromatch": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", @@ -3313,6 +3385,15 @@ "integrity": "sha512-Cxm7/SS/y/Z3MHWSxXb8lIFqgqBowP5JMlTUFyJN88y0SGQhVmZnqFK/PeuMX9LzUyWsqqhNxIyg0jlzq946yA==", "dev": true }, + "randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dev": true, + "requires": { + "safe-buffer": "^5.1.0" + } + }, "raw-body": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-1.3.4.tgz", @@ -3554,6 +3635,27 @@ } } }, + "rollup": { + "version": "2.17.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.17.1.tgz", + "integrity": "sha512-lVrtCXJ+08Eapa0SfApLmRNWNWm2FsYFnLPIJZJvZz2uI2Gv+dfPyu1zgF7KKF/HYFJDvjxbdCbI8lUVMnG7Sg==", + "dev": true, + "requires": { + "fsevents": "~2.1.2" + } + }, + "rollup-plugin-terser": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-6.1.0.tgz", + "integrity": "sha512-4fB3M9nuoWxrwm39habpd4hvrbrde2W2GG4zEGPQg1YITNkM3Tqur5jSuXlWNzbv/2aMLJ+dZJaySc3GCD8oDw==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.8.3", + "jest-worker": "^26.0.0", + "serialize-javascript": "^3.0.0", + "terser": "^4.7.0" + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -3587,6 +3689,15 @@ "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "dev": true }, + "serialize-javascript": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-3.1.0.tgz", + "integrity": "sha512-JIJT1DGiWmIKhzRsG91aS6Ze4sFUrYbltlkg2onR5OrnNM02Kl/hnY/T4FN2omvyeBbQmMJv+K4cPOpGzOTFBg==", + "dev": true, + "requires": { + "randombytes": "^2.1.0" + } + }, "set-value": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", @@ -3801,6 +3912,24 @@ "urix": "^0.1.0" } }, + "source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, "source-map-url": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz", @@ -3997,6 +4126,25 @@ "uuid": "~1.4.0" } }, + "terser": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-4.8.0.tgz", + "integrity": "sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==", + "dev": true, + "requires": { + "commander": "^2.20.0", + "source-map": "~0.6.1", + "source-map-support": "~0.5.12" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", diff --git a/package.json b/package.json index 3a40893..617d25d 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,14 @@ "case.d.ts" ], "main": "dist/Case.js", + "module": "dist/Case.mjs", + "exports": { + ".": { + "import": "./dist/Case.mjs", + "require": "./dist/Case.js", + "default": "./dist/Case.js" + } + }, "bugs": { "url": "http://github.com/nbubna/Case/issues", "email": "nathan@esharesearch.com" @@ -40,6 +48,7 @@ }, "license": "(MIT OR GPL-3.0-or-later)", "scripts": { + "build": "rollup --config ./rollup.config.js", "test": "grunt qunit" }, "devDependencies": { @@ -52,7 +61,9 @@ "grunt-contrib-qunit": "^3.1.0", "grunt-contrib-uglify": "^4.0.1", "grunt-contrib-watch": "^1.1.0", - "grunt-nuget": "~0.3.1" + "grunt-nuget": "~0.3.1", + "rollup": "^2.17.1", + "rollup-plugin-terser": "^6.1.0" }, "typings": "case.d.ts" } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..fba90b3 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,42 @@ +// @ts-check + +import { terser } from 'rollup-plugin-terser'; + +/** + * @type { import('rollup').RollupOptions } + */ +const config = { + input: './src/Case.mjs', + output: [ + { + file: './dist/Case.js', + format: 'umd', + name: 'Case', + sourcemap: true, + sourcemapExcludeSources: true, + }, + { + file: './dist/Case.mjs', + format: 'esm', + sourcemap: true, + sourcemapExcludeSources: true, + }, + { + file: './dist/Case.min.js', + format: 'umd', + name: 'Case', + sourcemap: true, + sourcemapExcludeSources: true, + plugins: [terser()], + }, + { + file: './dist/Case.min.mjs', + format: 'esm', + sourcemap: true, + sourcemapExcludeSources: true, + plugins: [terser()], + }, + ], +}; + +export default config; diff --git a/src/Case.js b/src/Case.js deleted file mode 100644 index 2f5f5e6..0000000 --- a/src/Case.js +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2016 ESHA Research - * License under the MIT license. - */ -(function() { - "use strict"; - var unicodes = function(s, prefix) { - prefix = prefix || ''; - return s.replace(/(^|-)/g, '$1\\u'+prefix).replace(/,/g, '\\u'+prefix); - }, - basicSymbols = unicodes('20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7', '00'), - baseLowerCase = 'a-z'+unicodes('DF-F6,F8-FF', '00'), - baseUpperCase = 'A-Z'+unicodes('C0-D6,D8-DE', '00'), - improperInTitle = 'A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via', - regexps = function(symbols, lowers, uppers, impropers) { - symbols = symbols || basicSymbols; - lowers = lowers || baseLowerCase; - uppers = uppers || baseUpperCase; - impropers = impropers || improperInTitle; - return { - capitalize: new RegExp('(^|['+symbols+'])(['+lowers+'])', 'g'), - pascal: new RegExp('(^|['+symbols+'])+(['+lowers+uppers+'])', 'g'), - fill: new RegExp('['+symbols+']+(.|$)','g'), - sentence: new RegExp('(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")(['+lowers+'])', 'g'), - improper: new RegExp('\\b('+impropers+')\\b', 'g'), - relax: new RegExp('([^'+uppers+'])(['+uppers+']*)(['+uppers+'])(?=[^'+uppers+']|$)', 'g'), - upper: new RegExp('^[^'+lowers+']+$'), - hole: /[^\s]\s[^\s]/, - apostrophe: /'/g, - room: new RegExp('['+symbols+']') - }; - }, - re = regexps(), - _ = { - re: re, - unicodes: unicodes, - regexps: regexps, - types: [], - up: String.prototype.toUpperCase, - low: String.prototype.toLowerCase, - cap: function(s) { - return _.up.call(s.charAt(0))+s.slice(1); - }, - decap: function(s) { - return _.low.call(s.charAt(0))+s.slice(1); - }, - deapostrophe: function(s) { - return s.replace(re.apostrophe, ''); - }, - fill: function(s, fill, deapostrophe) { - if (fill != null) { - s = s.replace(re.fill, function(m, next) { - return next ? fill + next : ''; - }); - } - if (deapostrophe) { - s = _.deapostrophe(s); - } - return s; - }, - prep: function(s, fill, pascal, upper) { - s = s == null ? '' : s + '';// force to string - if (!upper && re.upper.test(s)) { - s = _.low.call(s); - } - if (!fill && !re.hole.test(s)) { - var holey = _.fill(s, ' '); - if (re.hole.test(holey)) { - s = holey; - } - } - if (!pascal && !re.room.test(s)) { - s = s.replace(re.relax, _.relax); - } - return s; - }, - relax: function(m, before, acronym, caps) { - return before + ' ' + (acronym ? acronym+' ' : '') + caps; - } - }, - Case = { - _: _, - of: function(s) { - for (var i=0,m=_.types.length; i 0 && i < s.lastIndexOf(' ') ? _.low.call(small) : small; - }); - }, - sentence: function(s, names, abbreviations) { - s = Case.lower(s).replace(re.sentence, function(m, prelude, letter) { - return prelude + _.up.call(letter); - }); - if (names) { - names.forEach(function(name) { - s = s.replace(new RegExp('\\b'+Case.lower(name)+'\\b', "g"), _.cap); - }); - } - if (abbreviations) { - abbreviations.forEach(function(abbr) { - s = s.replace(new RegExp('(\\b'+Case.lower(abbr)+'\\. +)(\\w)'), function(m, abbrAndSpace, letter) { - return abbrAndSpace + _.low.call(letter); - }); - }); - } - return s; - } - }; - - // TODO: Remove "squish" in a future breaking release. - types.squish = types.pascal; - - // Allow import default - Case.default = Case; - - for (var type in types) { - Case.type(type, types[type]); - } - // export Case (AMD, commonjs, or global) - var define = typeof define === "function" ? define : function(){}; - define(typeof module === "object" && module.exports ? module.exports = Case : this.Case = Case); - -}).call(this); diff --git a/src/Case.mjs b/src/Case.mjs new file mode 100644 index 0000000..61483fa --- /dev/null +++ b/src/Case.mjs @@ -0,0 +1,49 @@ +import * as _ from './utils.mjs'; +import * as types from './types.mjs'; + +const typesArray = Object.keys(types); + +function of(s) { + for (var i = 0, m = typesArray.length; i < m; i++) { + if (Case[typesArray[i]].apply(Case, arguments) === s) { + return typesArray[i]; + } + } +} + +function flip(s) { + return s.replace(/\w/g, function (l) { + return (l == _.up.call(l) ? _.low : _.up).call(l); + }); +} + +function random(s) { + return s.replace(/\w/g, function (l) { + return (Math.round(Math.random()) ? _.up : _.low).call(l); + }); +} + +function type(type, fn) { + Case[type] = fn; + typesArray.push(type); +} + +const utils = { + ..._, + types: typesArray, +}; + +const Case = { + _:utils, + of, + flip, + random, + type, + ...types, +}; + +// TODO: can't export these +// export {of,flip,random,type,utils as _ }; +// export * from './types.mjs'; + +export default Case; diff --git a/src/component.js b/src/component.js deleted file mode 100644 index 0954d33..0000000 --- a/src/component.js +++ /dev/null @@ -1,2 +0,0 @@ - -module.exports = require('./Case.js'); diff --git a/src/toCase.js b/src/toCase.js deleted file mode 100644 index cadfe0b..0000000 --- a/src/toCase.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2013 ESHA Research - * License under the MIT license. - * - * Use at your own risk; this changes the behavior - * of toUpperCase, toLowerCase and for-in loops on strings (which is itself a bad idea). - */ -(function(Case, _) { - function create(type) { - var fn = 'to'+_.cap(type)+'Case'; - String.prototype[fn] = function() { - Array.prototype.unshift.call(arguments, this); - return Case[type].apply(Case, arguments); - }; - } - for (var i=0,m=_.types.length; i 0 && i < s.lastIndexOf(' ') ? _.low.call(small) : small; + }); +} +export function sentence(s, names, abbreviations) { + s = lower(s).replace(re.sentence, function (m, prelude, letter) { + return prelude + _.up.call(letter); + }); + if (names) { + names.forEach(function (name) { + s = s.replace(new RegExp('\\b' + lower(name) + '\\b', 'g'), _.cap); + }); + } + if (abbreviations) { + abbreviations.forEach(function (abbr) { + s = s.replace( + new RegExp('(\\b' + lower(abbr) + '\\. +)(\\w)'), + function (m, abbrAndSpace, letter) { + return abbrAndSpace + _.low.call(letter); + }, + ); + }); + } + return s; +} diff --git a/src/utils.mjs b/src/utils.mjs new file mode 100644 index 0000000..4652ba1 --- /dev/null +++ b/src/utils.mjs @@ -0,0 +1,93 @@ +export function unicodes(s, prefix) { + prefix = prefix || ''; + return s.replace(/(^|-)/g, '$1\\u' + prefix).replace(/,/g, '\\u' + prefix); +} + +const basicSymbols = unicodes( + '20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7', + '00', +); +const baseLowerCase = 'a-z' + unicodes('DF-F6,F8-FF', '00'); +const baseUpperCase = 'A-Z' + unicodes('C0-D6,D8-DE', '00'); +const improperInTitle = + 'A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via'; + +export function regexps(symbols, lowers, uppers, impropers) { + symbols = symbols || basicSymbols; + lowers = lowers || baseLowerCase; + uppers = uppers || baseUpperCase; + impropers = impropers || improperInTitle; + return { + capitalize: new RegExp('(^|[' + symbols + '])([' + lowers + '])', 'g'), + pascal: new RegExp( + '(^|[' + symbols + '])+([' + lowers + uppers + '])', + 'g', + ), + fill: new RegExp('[' + symbols + ']+(.|$)', 'g'), + sentence: new RegExp( + '(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")([' + lowers + '])', + 'g', + ), + improper: new RegExp('\\b(' + impropers + ')\\b', 'g'), + relax: new RegExp( + '([^' + + uppers + + '])([' + + uppers + + ']*)([' + + uppers + + '])(?=[^' + + uppers + + ']|$)', + 'g', + ), + upper: new RegExp('^[^' + lowers + ']+$'), + hole: /[^\s]\s[^\s]/, + apostrophe: /'/g, + room: new RegExp('[' + symbols + ']'), + }; +} + +export const re = regexps(); + +export const up = String.prototype.toUpperCase; +export const low = String.prototype.toLowerCase; +export function cap(s) { + return up.call(s.charAt(0)) + s.slice(1); +} +export function decap(s) { + return low.call(s.charAt(0)) + s.slice(1); +} +export function deapostrophe(s) { + return s.replace(re.apostrophe, ''); +} +export function fill(s, fill, _deapostrophe) { + if (fill != null) { + s = s.replace(re.fill, function (m, next) { + return next ? fill + next : ''; + }); + } + if (_deapostrophe) { + s = deapostrophe(s); + } + return s; +} +export function prep(s, _fill, pascal, upper) { + s = s == null ? '' : s + ''; // force to string + if (!upper && re.upper.test(s)) { + s = low.call(s); + } + if (!_fill && !re.hole.test(s)) { + var holey = fill(s, ' '); + if (re.hole.test(holey)) { + s = holey; + } + } + if (!pascal && !re.room.test(s)) { + s = s.replace(re.relax, relax); + } + return s; +} +export function relax(m, before, acronym, caps) { + return before + ' ' + (acronym ? acronym + ' ' : '') + caps; +} diff --git a/test/Case.html b/test/Case.html index 887ac53..2a1fce8 100644 --- a/test/Case.html +++ b/test/Case.html @@ -10,7 +10,6 @@ - diff --git a/test/Case_test.js b/test/Case_test.js index b03c1dc..d135008 100644 --- a/test/Case_test.js +++ b/test/Case_test.js @@ -15,19 +15,6 @@ properNames = ['Nathan'], _ = Case._; - function convert(a, b) { - test(a+' to '+b, function() { - expect(2); - var arg = b === "sentence" ? properNames : undefined, - direct = Case[b](types[a], arg), - viaTo = types[a]['to'+_.cap(b)+'Case'](arg), - lossy = direct.length < types[b].length, - expected = lossy ? types[b].replace(/[^\w ]/g,'') : types[b]; - strictEqual(direct, expected); - strictEqual(viaTo, expected); - }); - } - function identify(a) { test('identify '+a, function() { expect(1); @@ -44,12 +31,6 @@ }); } - module('Case conversion'); - for (var a in types) { - for (var b in types) { - convert(a, b); - } - } module('Case identification'); for (var c in types) { @@ -87,16 +68,14 @@ }); module('add type'); - test('add bang', function() { + test('add bang and use bang', function() { ok(!Case.bang, 'should not be Case.bang'); Case.type('bang', function(s) { return Case.upper(s, '!')+'!'; }); ok(Case.bang, 'should be a bang'); - }); - test('use bang', function() { + strictEqual(Case.bang('hi there'), 'HI!THERE!'); - strictEqual('bang'.toBangCase(), 'BANG!'); }); module('issues'); @@ -178,13 +157,9 @@ equal(Case.sentence(''), ''); }); - test('#22 - extra args to Case.of and to[Type]Case', function() { + test('#22 - extra args to Case.of', function() { // make sure Case.of can handle names in sentence case equal(Case.of("Hello, Sue, how is Bob?", ['Sue', 'Bob']), "sentence"); - // a fill argument - equal("best_case_ever".toCapitalCase(". "), "Best. Case. Ever"); - // fill and noApostrophes both - equal("i'm not sure".toUpperCase("/", true), "IM/NOT/SURE"); }); test('outliers', function() {