diff --git a/dist/Case.js b/dist/Case.js index af199f7..83e836a 100644 --- a/dist/Case.js +++ b/dist/Case.js @@ -1,7 +1,9 @@ -/*! case - v1.6.3 - 2020-03-24 -* Copyright (c) 2020 Nathan Bubna; Licensed (MIT OR GPL-3.0-or-later) */ -(function() { - "use strict"; +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = global || self, factory(global.Case = {})); +}(this, (function (exports) { 'use strict'; + var unicodes = function(s, prefix) { prefix = prefix || ''; return s.replace(/(^|-)/g, '$1\\u'+prefix).replace(/,/g, '\\u'+prefix); @@ -154,18 +156,49 @@ return s; } }; + const of = Case.of; + const flip = Case.flip; + const random = Case.random; + const type = Case.type; + + const lower = types.lower; + const snake = types.snake; + const constant = types.constant; + const camel = types.camel; + const kebab = types.kebab; + const upper = types.upper; + const capital = types.capital; + const header = types.header; + const pascal = types.pascal; + const title = types.title; + const sentence = types.sentence; // TODO: Remove "squish" in a future breaking release. - types.squish = types.pascal; - - // Allow import default - Case.default = Case; + /** + * + * @deprecated + */ + const squish = types.pascal; + + exports._ = _; + exports.camel = camel; + exports.capital = capital; + exports.constant = constant; + exports.flip = flip; + exports.header = header; + exports.kebab = kebab; + exports.lower = lower; + exports.of = of; + exports.pascal = pascal; + exports.random = random; + exports.sentence = sentence; + exports.snake = snake; + exports.squish = squish; + exports.title = title; + exports.type = type; + exports.upper = upper; - 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); + Object.defineProperty(exports, '__esModule', { value: true }); -}).call(this); +}))); +//# sourceMappingURL=Case.js.map diff --git a/dist/Case.js.map b/dist/Case.js.map new file mode 100644 index 0000000..d9fb873 --- /dev/null +++ b/dist/Case.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Case.js","sources":["../src/Case.mjs"],"sourcesContent":null,"names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C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE;IACnH,oBAAoB,OAAO,YAAY,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7D,iBAAiB,CAAC,CAAC;IACnB,aAAa,CAAC,CAAC;IACf,SAAS;IACT,QAAQ,OAAO,CAAC,CAAC;IACjB,KAAK;IACL,EAAE;AAGU,UAAC,EAAE,GAAG,IAAI,CAAC,GAAG;AACd,UAAC,IAAI,GAAG,IAAI,CAAC,KAAK;AAClB,UAAC,MAAM,GAAG,IAAI,CAAC,OAAO;AACtB,UAAC,IAAI,GAAG,IAAI,CAAC,KAAK;AAC9B;AACY,UAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,UAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,UAAC,QAAQ,GAAG,KAAK,CAAC,SAAS;AAC3B,UAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,UAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,UAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,UAAC,OAAO,GAAG,KAAK,CAAC,QAAQ;AACzB,UAAC,MAAM,GAAG,KAAK,CAAC,OAAO;AACvB,UAAC,MAAM,GAAG,KAAK,CAAC,OAAO;AACvB,UAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,UAAC,QAAQ,GAAG,KAAK,CAAC,SAAS;AACvC;IACA;IACA;IACA;IACA;IACA;AACY,UAAC,MAAM,GAAG,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/Case.min.js b/dist/Case.min.js index 06e0eeb..51ac244 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&&r0&&r 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; + } +}; +const of = Case.of; +const flip = Case.flip; +const random = Case.random; +const type = Case.type; + +const lower = types.lower; +const snake = types.snake; +const constant = types.constant; +const camel = types.camel; +const kebab = types.kebab; +const upper = types.upper; +const capital = types.capital; +const header = types.header; +const pascal = types.pascal; +const title = types.title; +const sentence = types.sentence; + +// TODO: Remove "squish" in a future breaking release. +/** + * + * @deprecated + */ +const squish = types.pascal; + +export { _, camel, capital, constant, flip, header, kebab, lower, of, pascal, random, sentence, snake, squish, title, type, upper }; +//# sourceMappingURL=Case.mjs.map diff --git a/dist/Case.mjs.map b/dist/Case.mjs.map new file mode 100644 index 0000000..5e7d4e0 --- /dev/null +++ b/dist/Case.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"Case.mjs","sources":["../src/Case.mjs"],"sourcesContent":null,"names":[],"mappings":"AACG,IAAC,QAAQ,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE;AACnC,IAAI,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;AAC1B,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;AAC3E,CAAC,CAAC;AACF,YAAY,GAAG,QAAQ,CAAC,2CAA2C,EAAE,IAAI,CAAC,CAAC;AAC3E,aAAa,GAAG,KAAK,CAAC,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AACpD,aAAa,GAAG,KAAK,CAAC,QAAQ,CAAC,aAAa,EAAE,IAAI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C9B;AACY,MAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,MAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,MAAC,QAAQ,GAAG,KAAK,CAAC,SAAS;AAC3B,MAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,MAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,MAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,MAAC,OAAO,GAAG,KAAK,CAAC,QAAQ;AACzB,MAAC,MAAM,GAAG,KAAK,CAAC,OAAO;AACvB,MAAC,MAAM,GAAG,KAAK,CAAC,OAAO;AACvB,MAAC,KAAK,GAAG,KAAK,CAAC,MAAM;AACrB,MAAC,QAAQ,GAAG,KAAK,CAAC,SAAS;AACvC;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,KAAK,CAAC;;;;"} \ No newline at end of file diff --git a/dist/Case.plus.js b/dist/Case.plus.js deleted file mode 100644 index 3265765..0000000 --- a/dist/Case.plus.js +++ /dev/null @@ -1,189 +0,0 @@ -/*! 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) { - 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); - -(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; - }); - }, - 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..3a1a3a5 --- /dev/null +++ b/src/Case.mjs @@ -0,0 +1,171 @@ + +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; + } +}; + +export {_} +export const of = Case.of; +export const flip = Case.flip; +export const random = Case.random; +export const type = Case.type; + +export const lower = types.lower; +export const snake = types.snake; +export const constant = types.constant; +export const camel = types.camel; +export const kebab = types.kebab; +export const upper = types.upper; +export const capital = types.capital; +export const header = types.header; +export const pascal = types.pascal; +export const title = types.title; +export const sentence = types.sentence; 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