codsen-utils 1.0.1 → 1.1.1

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 CHANGED
@@ -3,6 +3,20 @@
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.1.1](https://github.com/codsen/codsen/compare/codsen-utils@1.1.0...codsen-utils@1.1.1) (2022-12-27)
7
+
8
+ ### Bug Fixes
9
+
10
+ - add multiplication sign ([a93a230](https://github.com/codsen/codsen/commit/a93a2302d2385cc32f2cea0825666b683b4402e0))
11
+
12
+ # [1.1.0](https://github.com/codsen/codsen/compare/codsen-utils@1.0.1...codsen-utils@1.1.0) (2022-12-26)
13
+
14
+ ### Features
15
+
16
+ - add `findAllIdx()` ([3722d02](https://github.com/codsen/codsen/commit/3722d02eeca407f1a48c6683fff26eca44a7ad04))
17
+ - add `isWhitespaceChar()` and `thinSpace` ([77e23fe](https://github.com/codsen/codsen/commit/77e23fef4fadae4ff3cb1cdbaef483293b2b9599))
18
+ - add `stringSplice()` ([3d96011](https://github.com/codsen/codsen/commit/3d96011a3163a4e24ab8d6c23d0cf345f0c1f63f))
19
+
6
20
  ## 1.0.1 (2022-12-22)
7
21
 
8
22
  ### Bug Fixes
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @name codsen-utils
3
3
  * @fileoverview Various utility functions
4
- * @version 1.0.1
4
+ * @version 1.1.1
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 o="1.0.1";var l=o,s="\u2018",i="\u2019",p="\u201C",c="\u201D",a="\u2013",m="\u2014",b="\xA0",x="\u2026",f="\u200A",g="\u2032",h="\u2033",y="\\",w="\uFFFD",k="`",j=[".",",",";","!","?"];function C(t){return typeof t=="string"&&t.charCodeAt(0)>=48&&t.charCodeAt(0)<=57}function r(t){return typeof t=="string"&&t.length===1&&t.toUpperCase()!==t.toLowerCase()}function A(t){return!!(t&&typeof t=="string"&&(t.charCodeAt(0)>64&&t.charCodeAt(0)<91||t.charCodeAt(0)>96&&t.charCodeAt(0)<123))}function L(t){return typeof t=="string"&&(t==='"'||t==="'"||t===s||t===i||t===p||t===c)}function D(t){return typeof t!="string"||!r(t)?!1:t===t.toLowerCase()&&t!==t.toUpperCase()}function S(t){return typeof t!="string"||!r(t)?!1:t===t.toUpperCase()&&t!==t.toLowerCase()}var T=t=>typeof t=="string"&&t.length&&t.endsWith("/")?t.slice(0,-1).trim():t;function O(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)}var P=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Q=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"]);export{y as backslash,k as backtick,h as doublePrime,Q as inlineTags,A as isLatinLetter,r as isLetter,D as isLowercaseLetter,C as isNumberChar,O as isPlainObject,L as isQuote,S as isUppercaseLetter,p as leftDoubleQuote,s as leftSingleQuote,j as punctuationChars,x as rawEllipsis,f as rawHairspace,m as rawMDash,a as rawNDash,b as rawNbsp,w as rawReplacementMark,T as removeTrailingSlash,c as rightDoubleQuote,i as rightSingleQuote,g as singlePrime,l as version,P as voidTags};
10
+ var r="1.1.1";var m=r,p="\u2018",c="\u2019",u="\u201C",l="\u201D",f="\u2013",b="\u2014",x="\xA0",g="\u2026",h="\u200A",y="\u2009",w="\u2032",k="\u2033",j="\\",C="\uFFFD",A="`",S="\xD7",D=[".",",",";","!","?"];function L(t){return typeof t=="string"&&t.charCodeAt(0)>=48&&t.charCodeAt(0)<=57}function s(t){return typeof t=="string"&&t.length===1&&t.toUpperCase()!==t.toLowerCase()}function O(t){return!!(t&&typeof t=="string"&&(t.charCodeAt(0)>64&&t.charCodeAt(0)<91||t.charCodeAt(0)>96&&t.charCodeAt(0)<123))}function T(t){return typeof t=="string"&&(t==='"'||t==="'"||t===p||t===c||t===u||t===l)}function P(t){return typeof t!="string"||!s(t)?!1:t===t.toLowerCase()&&t!==t.toUpperCase()}function Q(t){return typeof t!="string"||!s(t)?!1:t===t.toUpperCase()&&t!==t.toLowerCase()}function M(t){return typeof t!="string"||!t?!1:!t[0].trim()}var R=t=>typeof t=="string"&&t.length&&t.endsWith("/")?t.slice(0,-1).trim():t;function U(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 E(t="",e=0,o=0,n=""){return e<0&&(e+=t.length,e<0&&(e=0)),t.slice(0,e)+(n||"")+t.slice(e+o)}function F(t,e){if(typeof t!="string"||typeof e!="string")return[];let o=[],n=-1;for(;(n=t.indexOf(e,n+1))>=0;)o.push(n);return o}var N=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],I=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"]);export{j as backslash,A as backtick,k as doublePrime,g as ellipsis,F as findAllIdx,h as hairspace,I as inlineTags,O as isLatinLetter,s as isLetter,P as isLowercaseLetter,L as isNumberChar,U as isPlainObject,T as isQuote,Q as isUppercaseLetter,M as isWhitespaceChar,u as leftDoubleQuote,p as leftSingleQuote,S as multiplicationSign,D as punctuationChars,b as rawMDash,f as rawNDash,x as rawNbsp,C as rawReplacementMark,R as removeTrailingSlash,l as rightDoubleQuote,c as rightSingleQuote,w as singlePrime,E as stringSplice,y as thinSpace,m as version,N as voidTags};
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @name codsen-utils
3
3
  * @fileoverview Various utility functions
4
- * @version 1.0.1
4
+ * @version 1.1.1
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 n=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var r in e)n(t,r,{get:e[r],enumerable:!0})},f=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!b.call(t,o)&&o!==r&&n(t,o,{get:()=>e[o],enumerable:!(i=a(e,o))||i.enumerable});return t};var g=t=>f(n({},"__esModule",{value:!0}),t);var H={};x(H,{backslash:()=>S,backtick:()=>O,doublePrime:()=>D,inlineTags:()=>q,isLatinLetter:()=>E,isLetter:()=>s,isLowercaseLetter:()=>R,isNumberChar:()=>Q,isPlainObject:()=>N,isQuote:()=>M,isUppercaseLetter:()=>U,leftDoubleQuote:()=>d,leftSingleQuote:()=>c,punctuationChars:()=>P,rawEllipsis:()=>C,rawHairspace:()=>A,rawMDash:()=>k,rawNDash:()=>w,rawNbsp:()=>j,rawReplacementMark:()=>T,removeTrailingSlash:()=>F,rightDoubleQuote:()=>l,rightSingleQuote:()=>u,singlePrime:()=>L,version:()=>y,voidTags:()=>V});var p="1.0.1";var y=p,c="\u2018",u="\u2019",d="\u201C",l="\u201D",w="\u2013",k="\u2014",j="\xA0",C="\u2026",A="\u200A",L="\u2032",D="\u2033",S="\\",T="\uFFFD",O="`",P=[".",",",";","!","?"];function Q(t){return typeof t=="string"&&t.charCodeAt(0)>=48&&t.charCodeAt(0)<=57}function s(t){return typeof t=="string"&&t.length===1&&t.toUpperCase()!==t.toLowerCase()}function E(t){return!!(t&&typeof t=="string"&&(t.charCodeAt(0)>64&&t.charCodeAt(0)<91||t.charCodeAt(0)>96&&t.charCodeAt(0)<123))}function M(t){return typeof t=="string"&&(t==='"'||t==="'"||t===c||t===u||t===d||t===l)}function R(t){return typeof t!="string"||!s(t)?!1:t===t.toLowerCase()&&t!==t.toUpperCase()}function U(t){return typeof t!="string"||!s(t)?!1:t===t.toUpperCase()&&t!==t.toLowerCase()}var F=t=>typeof t=="string"&&t.length&&t.endsWith("/")?t.slice(0,-1).trim():t;function N(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)}var V=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],q=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"]);return g(H);})();
10
+ "use strict";var codsenUtils=(()=>{var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var b=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},x=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of m(e))!f.call(t,r)&&r!==n&&s(t,r,{get:()=>e[r],enumerable:!(o=d(e,r))||o.enumerable});return t};var g=t=>x(s({},"__esModule",{value:!0}),t);var H={};b(H,{backslash:()=>O,backtick:()=>P,doublePrime:()=>L,ellipsis:()=>C,findAllIdx:()=>z,hairspace:()=>A,inlineTags:()=>G,isLatinLetter:()=>U,isLetter:()=>i,isLowercaseLetter:()=>F,isNumberChar:()=>R,isPlainObject:()=>W,isQuote:()=>E,isUppercaseLetter:()=>N,isWhitespaceChar:()=>I,leftDoubleQuote:()=>l,leftSingleQuote:()=>c,multiplicationSign:()=>Q,punctuationChars:()=>M,rawMDash:()=>k,rawNDash:()=>w,rawNbsp:()=>j,rawReplacementMark:()=>T,removeTrailingSlash:()=>V,rightDoubleQuote:()=>a,rightSingleQuote:()=>u,singlePrime:()=>D,stringSplice:()=>q,thinSpace:()=>S,version:()=>y,voidTags:()=>B});var p="1.1.1";var y=p,c="\u2018",u="\u2019",l="\u201C",a="\u201D",w="\u2013",k="\u2014",j="\xA0",C="\u2026",A="\u200A",S="\u2009",D="\u2032",L="\u2033",O="\\",T="\uFFFD",P="`",Q="\xD7",M=[".",",",";","!","?"];function R(t){return typeof t=="string"&&t.charCodeAt(0)>=48&&t.charCodeAt(0)<=57}function i(t){return typeof t=="string"&&t.length===1&&t.toUpperCase()!==t.toLowerCase()}function U(t){return!!(t&&typeof t=="string"&&(t.charCodeAt(0)>64&&t.charCodeAt(0)<91||t.charCodeAt(0)>96&&t.charCodeAt(0)<123))}function E(t){return typeof t=="string"&&(t==='"'||t==="'"||t===c||t===u||t===l||t===a)}function F(t){return typeof t!="string"||!i(t)?!1:t===t.toLowerCase()&&t!==t.toUpperCase()}function N(t){return typeof t!="string"||!i(t)?!1:t===t.toUpperCase()&&t!==t.toLowerCase()}function I(t){return typeof t!="string"||!t?!1:!t[0].trim()}var V=t=>typeof t=="string"&&t.length&&t.endsWith("/")?t.slice(0,-1).trim():t;function W(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 q(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 z(t,e){if(typeof t!="string"||typeof e!="string")return[];let n=[],o=-1;for(;(o=t.indexOf(e,o+1))>=0;)n.push(o);return n}var B=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],G=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"]);return g(H);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codsen-utils",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "Various utility functions",
5
5
  "keywords": [
6
6
  "codsen",
package/types/index.d.ts CHANGED
@@ -6,13 +6,15 @@ declare const rightDoubleQuote = "\u201D";
6
6
  declare const rawNDash = "\u2013";
7
7
  declare const rawMDash = "\u2014";
8
8
  declare const rawNbsp = "\u00A0";
9
- declare const rawEllipsis = "\u2026";
10
- declare const rawHairspace = "\u200A";
9
+ declare const ellipsis = "\u2026";
10
+ declare const hairspace = "\u200A";
11
+ declare const thinSpace = "\u2009";
11
12
  declare const singlePrime = "\u2032";
12
13
  declare const doublePrime = "\u2033";
13
14
  declare const backslash = "\\";
14
15
  declare const rawReplacementMark = "\uFFFD";
15
16
  declare const backtick = "`";
17
+ declare const multiplicationSign = "\u00D7";
16
18
  declare const punctuationChars: string[];
17
19
  declare function isNumberChar(value: unknown): boolean;
18
20
  declare function isLetter(value: unknown): boolean;
@@ -20,6 +22,7 @@ declare function isLatinLetter(value: unknown): boolean;
20
22
  declare function isQuote(value: unknown): boolean;
21
23
  declare function isLowercaseLetter(value: unknown): boolean;
22
24
  declare function isUppercaseLetter(value: unknown): boolean;
25
+ declare function isWhitespaceChar(value: unknown): boolean;
23
26
  declare const removeTrailingSlash: <T>(value: T) => string | T;
24
27
  /**
25
28
  * Tells, is given input a plain object (an object literal,
@@ -28,6 +31,30 @@ declare const removeTrailingSlash: <T>(value: T) => string | T;
28
31
  * @returns boolean
29
32
  */
30
33
  declare function isPlainObject(value: unknown): boolean;
34
+ /**
35
+ * @param str input string
36
+ * @param index starting index
37
+ * @param count how many characters to replace
38
+ * @param add what string to insert
39
+ * @returns string
40
+ * Adapted from https://stackoverflow.com/a/21350614
41
+ */
42
+ declare function stringSplice(
43
+ str?: string,
44
+ index?: number,
45
+ count?: number,
46
+ add?: string
47
+ ): string;
48
+ /**
49
+ * Gives array of indexes of all found substring occurrences
50
+ * @param string source string
51
+ * @param substring what to look for
52
+ * @returns array of findings' position indexes
53
+ * adapted from https://stackoverflow.com/a/10710406
54
+ * console.log(findAllIdx("scissors", "s"));
55
+ * -> [0, 3, 4, 7]
56
+ */
57
+ declare function findAllIdx(value: unknown, substring: unknown): number[];
31
58
  declare const voidTags: string[];
32
59
  declare const inlineTags: Set<string>;
33
60
 
@@ -35,6 +62,9 @@ export {
35
62
  backslash,
36
63
  backtick,
37
64
  doublePrime,
65
+ ellipsis,
66
+ findAllIdx,
67
+ hairspace,
38
68
  inlineTags,
39
69
  isLatinLetter,
40
70
  isLetter,
@@ -43,11 +73,11 @@ export {
43
73
  isPlainObject,
44
74
  isQuote,
45
75
  isUppercaseLetter,
76
+ isWhitespaceChar,
46
77
  leftDoubleQuote,
47
78
  leftSingleQuote,
79
+ multiplicationSign,
48
80
  punctuationChars,
49
- rawEllipsis,
50
- rawHairspace,
51
81
  rawMDash,
52
82
  rawNDash,
53
83
  rawNbsp,
@@ -56,6 +86,8 @@ export {
56
86
  rightDoubleQuote,
57
87
  rightSingleQuote,
58
88
  singlePrime,
89
+ stringSplice,
90
+ thinSpace,
59
91
  version,
60
92
  voidTags,
61
93
  };