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