warscript 0.0.1-dev.c8d6bc0 → 0.0.1-dev.cc63edd

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "warscript",
4
- "version": "0.0.1-dev.c8d6bc0",
4
+ "version": "0.0.1-dev.cc63edd",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -24,7 +24,7 @@
24
24
  "@warscript/language-extensions": "^0.0.1",
25
25
  "@warscript/tstl-plugin": "^0.0.3",
26
26
  "lua-types": "^2.13.1",
27
- "warpack": "0.0.1-dev.5bdabe5"
27
+ "warpack": "0.0.1-dev.1976a88"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@typescript-eslint/eslint-plugin": "^5.59.11",
package/string.d.ts CHANGED
@@ -103,4 +103,18 @@ declare global {
103
103
  function isNotBlank(string: string): boolean;
104
104
  }
105
105
  }
106
+ declare global {
107
+ namespace string {
108
+ /**
109
+ * Returns the number of characters matching the given predicate.
110
+ */
111
+ function count(string: string, predicate: (char: string) => boolean): number;
112
+ }
113
+ interface String {
114
+ /**
115
+ * Returns the number of characters matching the given predicate.
116
+ */
117
+ count(predicate: (char: string) => boolean): number;
118
+ }
119
+ }
106
120
  export {};
package/string.lua CHANGED
@@ -31,4 +31,13 @@ end
31
31
  _G.string.isNotBlank = function(____string)
32
32
  return (match(____string, "^%s*$")) == nil
33
33
  end
34
+ _G.string.count = function(____string, predicate)
35
+ local result = 0
36
+ for i = 1, #____string do
37
+ if predicate(sub(____string, i, i)) then
38
+ result = result + 1
39
+ end
40
+ end
41
+ return result
42
+ end
34
43
  return ____exports