codsen-utils 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/codsen-utils.esm.js +6 -6
- package/dist/codsen-utils.umd.js +6 -6
- package/package.json +1 -1
- package/types/index.d.ts +33 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 1.5.0 (2023-05-13)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- type improvements ([6847c21](https://github.com/codsen/codsen/commit/6847c21ce33b36e56b767ef63504d9233810d2e9))
|
|
11
|
+
- type tweaks ([8173408](https://github.com/codsen/codsen/commit/8173408b57f963055cca991a0cb697c9d2d664e4))
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- add `compareFn()` to tackle `@typescript-eslint/require-array-sort-compare` lint rule ([a25524a](https://github.com/codsen/codsen/commit/a25524a027067208b8e94b30b6745790ec278fbe))
|
|
16
|
+
- add `includes()` ([c6cf14e](https://github.com/codsen/codsen/commit/c6cf14e8a7f3fb2a063fcec3381700798341ad42))
|
|
17
|
+
|
|
6
18
|
# [1.4.0](https://github.com/codsen/codsen/compare/codsen-utils@1.3.1...codsen-utils@1.4.0) (2023-04-16)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/dist/codsen-utils.esm.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name codsen-utils
|
|
3
3
|
* @fileoverview Various utility functions
|
|
4
|
-
* @version 1.
|
|
4
|
+
* @version 1.5.0
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/codsen-utils/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var s="1.
|
|
10
|
+
var s="1.5.0";var h=s,p="\u2018",c="\u2019",l="\u201C",a="\u201D",y="\u2013",w="\u2014",k="\xA0",S="\u2026",C="\u200A",O="\u2009",j="\u2032",A="\u2033",N="\\",E="\uFFFD",T="`",J="\xD7",R=[".",",",";","!","?"];function L(t){return r(t)&&t.charCodeAt(0)>=48&&t.charCodeAt(0)<=57}function f(t){return r(t)&&"\u060B$\u20BC\u17DB\xA5\u20A1\u20B1\xA3\u20AC\xA2\u20B9\uFDFC\u20AA\u20A9\u20AD\u20A8\u20AE\u20A6\u20BD\u20AB\u0E3F\u20A9\u20BA\u20B4".includes(t)}function $(t){let e=new Set(["$U","$b","B/.","BZ$","Br","Bs","C$","CHF","Ft","Gs","J$","KM","K\u010D","L","MT","NT$","P","Q","R","R$","RD$","RM","Rp","S","S/.","TT$","Z$","kn","kr","lei","z\u0142","\u0192","\u0414\u0438\u043D.","\u0434\u0435\u043D","\u043B\u0432","\u062F.\u0625","Lek"]);return r(t)&&!!t.trim()&&(f(t)||e.has(t))}function i(t){return r(t)&&t.length===1&&t.toUpperCase()!==t.toLowerCase()}function D(t){return!!(t&&r(t)&&(t.charCodeAt(0)>64&&t.charCodeAt(0)<91||t.charCodeAt(0)>96&&t.charCodeAt(0)<123))}function F(t){return r(t)&&(t==='"'||t==="'"||t===p||t===c||t===l||t===a)}function P(t){return!r(t)||!i(t)?!1:t===t.toLowerCase()&&t!==t.toUpperCase()}function U(t){return!r(t)||!i(t)?!1:t===t.toUpperCase()&&t!==t.toLowerCase()}function M(t){return!r(t)||!t?!1:!t[0].trim()}var Q=t=>r(t)&&t.length&&t.endsWith("/")?t.slice(0,-1).trim():t;function d(t){if(t==null||typeof t!="object")return!1;let e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:!(Symbol.iterator in t)&&!(Symbol.toStringTag in t)}function V(t="",e=0,n=0,o=""){return e<0&&(e+=t.length,e<0&&(e=0)),t.slice(0,e)+(o||"")+t.slice(e+n)}function r(t){return typeof t=="string"}function B(t){return Number.isFinite(t)}function I(t){return Number.isSafeInteger(t)&&t>=0}function K(t){return typeof t=="boolean"}function q(t){return t===null}function m(t){return t instanceof RegExp}function W(t,e){if(!r(t)||!r(e))return[];let n=[],o=-1;for(;(o=t.indexOf(e,o+1))>=0;)n.push(o);return n}function Z(t=[],e=[]){return!t||!Array.isArray(t)||!t.length?[]:!e||!Array.isArray(e)||!e.length?t:t.filter(n=>!e.includes(n))}function z(t){return t!=null}function G(t){return[...new Set(t)]}function x(t){if(!(typeof t!="string"||!t)){if(t.includes(`\r
|
|
11
11
|
`))return`\r
|
|
12
12
|
`;if(t.includes(`
|
|
13
13
|
`))return`
|
|
14
|
-
`;if(t.includes("\r"))return"\r"}}function
|
|
14
|
+
`;if(t.includes("\r"))return"\r"}}function H(t,e,n=`
|
|
15
15
|
`){if(![`\r
|
|
16
16
|
`,"\r",`
|
|
17
|
-
`].includes(
|
|
18
|
-
`:
|
|
19
|
-
`:
|
|
17
|
+
`].includes(n))throw new Error(`codsen-utils/resolveEolSetting(): the input argument defaultEolChar should be one of EOL values: "\\n", "\\r", or "\\r\\n", but it was given as ${JSON.stringify(n,null,0)}`);return e==="crlf"?`\r
|
|
18
|
+
`:e==="cr"?"\r":e==="lf"?`
|
|
19
|
+
`:x(t)||n}function X(t,e){return d(t)&&r(e)&&e in t}function Y(t,e){return t.localeCompare(e)}var _=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],v=new Set(["a","abbr","acronym","audio","b","bdi","bdo","big","br","button","canvas","cite","code","data","datalist","del","dfn","em","embed","i","iframe","img","input","ins","kbd","label","map","mark","meter","noscript","object","output","picture","progress","q","ruby","s","samp","script","select","slot","small","span","strong","sub","sup","svg","template","textarea","time","u","tt","var","video","wbr"]);function tt(t,e){return!Array.isArray(t)||!t.length?!1:t.some(n=>m(n)&&e.match(n)||typeof n=="string"&&e===n)}export{N as backslash,T as backtick,Y as compareFn,x as detectEol,A as doublePrime,S as ellipsis,z as existy,W as findAllIdx,C as hairspace,X as hasOwnProp,tt as includes,v as inlineTags,K as isBool,f as isCurrencyChar,$ as isCurrencySymbol,I as isInt,D as isLatinLetter,i as isLetter,P as isLowercaseLetter,q as isNull,B as isNum,L as isNumberChar,d as isPlainObject,F as isQuote,m as isRegExp,r as isStr,U as isUppercaseLetter,M as isWhitespaceChar,l as leftDoubleQuote,p as leftSingleQuote,J as multiplicationSign,Z as pullAll,R as punctuationChars,w as rawMDash,y as rawNDash,k as rawNbsp,E as rawReplacementMark,Q as removeTrailingSlash,H as resolveEolSetting,a as rightDoubleQuote,c as rightSingleQuote,j as singlePrime,V as stringSplice,O as thinSpace,G as uniq,h as version,_ as voidTags};
|
package/dist/codsen-utils.umd.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name codsen-utils
|
|
3
3
|
* @fileoverview Various utility functions
|
|
4
|
-
* @version 1.
|
|
4
|
+
* @version 1.5.0
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/codsen-utils/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
"use strict";var codsenUtils=(()=>{var i=Object.defineProperty;var
|
|
10
|
+
"use strict";var codsenUtils=(()=>{var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var n in e)i(t,n,{get:e[n],enumerable:!0})},k=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of h(e))!y.call(t,s)&&s!==n&&i(t,s,{get:()=>e[s],enumerable:!(o=g(e,s))||o.enumerable});return t};var S=t=>k(i({},"__esModule",{value:!0}),t);var ut={};w(ut,{backslash:()=>$,backtick:()=>F,compareFn:()=>rt,detectEol:()=>b,doublePrime:()=>L,ellipsis:()=>E,existy:()=>v,findAllIdx:()=>Y,hairspace:()=>T,hasOwnProp:()=>nt,includes:()=>it,inlineTags:()=>st,isBool:()=>H,isCurrencyChar:()=>d,isCurrencySymbol:()=>Q,isInt:()=>G,isLatinLetter:()=>V,isLetter:()=>u,isLowercaseLetter:()=>I,isNull:()=>X,isNum:()=>z,isNumberChar:()=>M,isPlainObject:()=>m,isQuote:()=>B,isRegExp:()=>x,isStr:()=>r,isUppercaseLetter:()=>K,isWhitespaceChar:()=>q,leftDoubleQuote:()=>a,leftSingleQuote:()=>c,multiplicationSign:()=>P,pullAll:()=>_,punctuationChars:()=>U,rawMDash:()=>A,rawNDash:()=>j,rawNbsp:()=>N,rawReplacementMark:()=>D,removeTrailingSlash:()=>W,resolveEolSetting:()=>et,rightDoubleQuote:()=>f,rightSingleQuote:()=>l,singlePrime:()=>R,stringSplice:()=>Z,thinSpace:()=>J,uniq:()=>tt,version:()=>O,voidTags:()=>ot});var p="1.5.0";var O=p,c="\u2018",l="\u2019",a="\u201C",f="\u201D",j="\u2013",A="\u2014",N="\xA0",E="\u2026",T="\u200A",J="\u2009",R="\u2032",L="\u2033",$="\\",D="\uFFFD",F="`",P="\xD7",U=[".",",",";","!","?"];function M(t){return r(t)&&t.charCodeAt(0)>=48&&t.charCodeAt(0)<=57}function d(t){return r(t)&&"\u060B$\u20BC\u17DB\xA5\u20A1\u20B1\xA3\u20AC\xA2\u20B9\uFDFC\u20AA\u20A9\u20AD\u20A8\u20AE\u20A6\u20BD\u20AB\u0E3F\u20A9\u20BA\u20B4".includes(t)}function Q(t){let e=new Set(["$U","$b","B/.","BZ$","Br","Bs","C$","CHF","Ft","Gs","J$","KM","K\u010D","L","MT","NT$","P","Q","R","R$","RD$","RM","Rp","S","S/.","TT$","Z$","kn","kr","lei","z\u0142","\u0192","\u0414\u0438\u043D.","\u0434\u0435\u043D","\u043B\u0432","\u062F.\u0625","Lek"]);return r(t)&&!!t.trim()&&(d(t)||e.has(t))}function u(t){return r(t)&&t.length===1&&t.toUpperCase()!==t.toLowerCase()}function V(t){return!!(t&&r(t)&&(t.charCodeAt(0)>64&&t.charCodeAt(0)<91||t.charCodeAt(0)>96&&t.charCodeAt(0)<123))}function B(t){return r(t)&&(t==='"'||t==="'"||t===c||t===l||t===a||t===f)}function I(t){return!r(t)||!u(t)?!1:t===t.toLowerCase()&&t!==t.toUpperCase()}function K(t){return!r(t)||!u(t)?!1:t===t.toUpperCase()&&t!==t.toLowerCase()}function q(t){return!r(t)||!t?!1:!t[0].trim()}var W=t=>r(t)&&t.length&&t.endsWith("/")?t.slice(0,-1).trim():t;function m(t){if(t==null||typeof t!="object")return!1;let e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:!(Symbol.iterator in t)&&!(Symbol.toStringTag in t)}function Z(t="",e=0,n=0,o=""){return e<0&&(e+=t.length,e<0&&(e=0)),t.slice(0,e)+(o||"")+t.slice(e+n)}function r(t){return typeof t=="string"}function z(t){return Number.isFinite(t)}function G(t){return Number.isSafeInteger(t)&&t>=0}function H(t){return typeof t=="boolean"}function X(t){return t===null}function x(t){return t instanceof RegExp}function Y(t,e){if(!r(t)||!r(e))return[];let n=[],o=-1;for(;(o=t.indexOf(e,o+1))>=0;)n.push(o);return n}function _(t=[],e=[]){return!t||!Array.isArray(t)||!t.length?[]:!e||!Array.isArray(e)||!e.length?t:t.filter(n=>!e.includes(n))}function v(t){return t!=null}function tt(t){return[...new Set(t)]}function b(t){if(!(typeof t!="string"||!t)){if(t.includes(`\r
|
|
11
11
|
`))return`\r
|
|
12
12
|
`;if(t.includes(`
|
|
13
13
|
`))return`
|
|
14
|
-
`;if(t.includes("\r"))return"\r"}}function
|
|
14
|
+
`;if(t.includes("\r"))return"\r"}}function et(t,e,n=`
|
|
15
15
|
`){if(![`\r
|
|
16
16
|
`,"\r",`
|
|
17
|
-
`].includes(
|
|
18
|
-
`:
|
|
19
|
-
`:b(t)||
|
|
17
|
+
`].includes(n))throw new Error(`codsen-utils/resolveEolSetting(): the input argument defaultEolChar should be one of EOL values: "\\n", "\\r", or "\\r\\n", but it was given as ${JSON.stringify(n,null,0)}`);return e==="crlf"?`\r
|
|
18
|
+
`:e==="cr"?"\r":e==="lf"?`
|
|
19
|
+
`:b(t)||n}function nt(t,e){return m(t)&&r(e)&&e in t}function rt(t,e){return t.localeCompare(e)}var ot=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],st=new Set(["a","abbr","acronym","audio","b","bdi","bdo","big","br","button","canvas","cite","code","data","datalist","del","dfn","em","embed","i","iframe","img","input","ins","kbd","label","map","mark","meter","noscript","object","output","picture","progress","q","ruby","s","samp","script","select","slot","small","span","strong","sub","sup","svg","template","textarea","time","u","tt","var","video","wbr"]);function it(t,e){return!Array.isArray(t)||!t.length?!1:t.some(n=>x(n)&&e.match(n)||typeof n=="string"&&e===n)}return S(ut);})();
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -16,9 +16,15 @@ declare const rawReplacementMark = "\uFFFD";
|
|
|
16
16
|
declare const backtick = "`";
|
|
17
17
|
declare const multiplicationSign = "\u00D7";
|
|
18
18
|
declare const punctuationChars: string[];
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
type JSONValue = string | number | boolean | null | JSONObject | JSONArray;
|
|
20
|
+
type JsonObject = {
|
|
21
|
+
[Key in string]?: JSONValue;
|
|
22
|
+
};
|
|
23
|
+
type JSONArray = JSONValue[];
|
|
24
|
+
interface JSONObject {
|
|
25
|
+
[key: string]: JSONValue;
|
|
21
26
|
}
|
|
27
|
+
type Obj = JSONObject;
|
|
22
28
|
type EolChar = "\n" | "\r" | "\r\n";
|
|
23
29
|
type EolSetting = "lf" | "crlf" | "cr";
|
|
24
30
|
declare function isNumberChar(value: unknown): boolean;
|
|
@@ -37,7 +43,7 @@ declare const removeTrailingSlash: <T>(value: T) => string | T;
|
|
|
37
43
|
* @param value unknown
|
|
38
44
|
* @returns boolean
|
|
39
45
|
*/
|
|
40
|
-
declare function isPlainObject(value: unknown):
|
|
46
|
+
declare function isPlainObject(value: unknown): value is JSONObject;
|
|
41
47
|
/**
|
|
42
48
|
* @param str input string
|
|
43
49
|
* @param index starting index
|
|
@@ -57,6 +63,7 @@ declare function isNum(something: unknown): something is number;
|
|
|
57
63
|
declare function isInt(something: unknown): something is number;
|
|
58
64
|
declare function isBool(something: unknown): something is boolean;
|
|
59
65
|
declare function isNull(something: unknown): something is null;
|
|
66
|
+
declare function isRegExp(something: any): something is RegExp;
|
|
60
67
|
/**
|
|
61
68
|
* Gives array of indexes of all found substring occurrences
|
|
62
69
|
* @param string source string
|
|
@@ -88,15 +95,36 @@ declare function resolveEolSetting(
|
|
|
88
95
|
defaultEolChar?: EolChar
|
|
89
96
|
): EolChar;
|
|
90
97
|
declare function hasOwnProp(obj: unknown, prop: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Related to @typescript-eslint/require-array-sort-compare lint error
|
|
100
|
+
*/
|
|
101
|
+
declare function compareFn(a: string, b: string): number;
|
|
91
102
|
declare const voidTags: string[];
|
|
92
103
|
declare const inlineTags: Set<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Like Array.prototype.includes() but it takes a mix of strings and/or
|
|
106
|
+
* regex'es, and matches that against a string. It's also a friendly API,
|
|
107
|
+
* it will not throw if the inputs are wrong.
|
|
108
|
+
* @param arr - array of zero or more strings or regex'es
|
|
109
|
+
* @param whatToMatch - string to match
|
|
110
|
+
* @returns boolean
|
|
111
|
+
*/
|
|
112
|
+
declare function includes(
|
|
113
|
+
arr: (string | RegExp)[],
|
|
114
|
+
whatToMatch: string
|
|
115
|
+
): boolean;
|
|
93
116
|
|
|
94
117
|
export {
|
|
95
118
|
EolChar,
|
|
96
119
|
EolSetting,
|
|
120
|
+
JSONArray,
|
|
121
|
+
JSONObject,
|
|
122
|
+
JSONValue,
|
|
123
|
+
JsonObject,
|
|
97
124
|
Obj,
|
|
98
125
|
backslash,
|
|
99
126
|
backtick,
|
|
127
|
+
compareFn,
|
|
100
128
|
detectEol,
|
|
101
129
|
doublePrime,
|
|
102
130
|
ellipsis,
|
|
@@ -104,6 +132,7 @@ export {
|
|
|
104
132
|
findAllIdx,
|
|
105
133
|
hairspace,
|
|
106
134
|
hasOwnProp,
|
|
135
|
+
includes,
|
|
107
136
|
inlineTags,
|
|
108
137
|
isBool,
|
|
109
138
|
isCurrencyChar,
|
|
@@ -117,6 +146,7 @@ export {
|
|
|
117
146
|
isNumberChar,
|
|
118
147
|
isPlainObject,
|
|
119
148
|
isQuote,
|
|
149
|
+
isRegExp,
|
|
120
150
|
isStr,
|
|
121
151
|
isUppercaseLetter,
|
|
122
152
|
isWhitespaceChar,
|