cafe-utility 7.0.0 → 7.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/index.d.ts +1 -1
- package/index.js +63 -23
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -136,7 +136,7 @@ interface RegexMatch {
|
|
|
136
136
|
}
|
|
137
137
|
declare function indexOfRegex(string: string, regex: RegExp, start?: number): RegexMatch | null;
|
|
138
138
|
declare function lineMatches(haystack: string, needles: (string | RegExp)[], orderMatters?: boolean): boolean;
|
|
139
|
-
declare function linesMatchInOrder(lines: string[], expectations: (string
|
|
139
|
+
declare function linesMatchInOrder(lines: string[], expectations: (string | RegExp)[][], orderMatters?: boolean): boolean;
|
|
140
140
|
declare function csvEscape(string: string): string;
|
|
141
141
|
declare function indexOfEarliest(string: string, searchStrings: string[], start?: number): number;
|
|
142
142
|
declare function findWeightedPair(string: string, start?: number, opening?: string, closing?: string): number;
|
package/index.js
CHANGED
|
@@ -989,7 +989,7 @@ function extractAllBlocks(string, options) {
|
|
|
989
989
|
if (start === -1) {
|
|
990
990
|
return blocks
|
|
991
991
|
}
|
|
992
|
-
const block = extractBlock(string, {
|
|
992
|
+
const block = extractBlock(string, Object.assign(Object.assign({}, options), { start }))
|
|
993
993
|
if (!block) {
|
|
994
994
|
return blocks
|
|
995
995
|
}
|
|
@@ -1366,10 +1366,13 @@ const longNumberUnits = [
|
|
|
1366
1366
|
]
|
|
1367
1367
|
const shortNumberUnits = ['K', 'M', 'B', 't', 'q', 'Q', 's', 'S', 'o', 'n', 'd']
|
|
1368
1368
|
function formatNumber(number, options) {
|
|
1369
|
-
|
|
1370
|
-
const
|
|
1369
|
+
var _a, _b
|
|
1370
|
+
const longFormat =
|
|
1371
|
+
(_a = options === null || options === void 0 ? void 0 : options.longForm) !== null && _a !== void 0 ? _a : false
|
|
1372
|
+
const unitString = (options === null || options === void 0 ? void 0 : options.unit) ? ` ${options.unit}` : ''
|
|
1371
1373
|
const table = longFormat ? longNumberUnits : shortNumberUnits
|
|
1372
|
-
const precision =
|
|
1374
|
+
const precision =
|
|
1375
|
+
(_b = options === null || options === void 0 ? void 0 : options.precision) !== null && _b !== void 0 ? _b : 1
|
|
1373
1376
|
if (number < thresholds[0]) {
|
|
1374
1377
|
return `${number}${unitString}`
|
|
1375
1378
|
}
|
|
@@ -1801,7 +1804,7 @@ class Maybe {
|
|
|
1801
1804
|
async valueOf() {
|
|
1802
1805
|
try {
|
|
1803
1806
|
return await this.value
|
|
1804
|
-
} catch {
|
|
1807
|
+
} catch (_a) {
|
|
1805
1808
|
return null
|
|
1806
1809
|
}
|
|
1807
1810
|
}
|
|
@@ -1871,19 +1874,33 @@ function filterCoordinates(grid, predicate, direction = 'row-first') {
|
|
|
1871
1874
|
}
|
|
1872
1875
|
|
|
1873
1876
|
function isHorizontalLine(tiles, x, y) {
|
|
1874
|
-
|
|
1877
|
+
var _a, _b
|
|
1878
|
+
return (
|
|
1879
|
+
((_a = tiles[x + 1]) === null || _a === void 0 ? void 0 : _a[y]) &&
|
|
1880
|
+
((_b = tiles[x - 1]) === null || _b === void 0 ? void 0 : _b[y]) &&
|
|
1881
|
+
!tiles[x][y - 1] &&
|
|
1882
|
+
!tiles[x][y + 1]
|
|
1883
|
+
)
|
|
1875
1884
|
}
|
|
1876
1885
|
|
|
1877
1886
|
function isVerticalLine(tiles, x, y) {
|
|
1878
|
-
|
|
1887
|
+
var _a, _b
|
|
1888
|
+
return (
|
|
1889
|
+
tiles[x][y + 1] &&
|
|
1890
|
+
tiles[x][y - 1] &&
|
|
1891
|
+
!((_a = tiles[x - 1]) === null || _a === void 0 ? void 0 : _a[y]) &&
|
|
1892
|
+
!((_b = tiles[x + 1]) === null || _b === void 0 ? void 0 : _b[y])
|
|
1893
|
+
)
|
|
1879
1894
|
}
|
|
1880
1895
|
|
|
1881
1896
|
function isLeftmost(tiles, x, y) {
|
|
1882
|
-
|
|
1897
|
+
var _a
|
|
1898
|
+
return !((_a = tiles[x - 1]) === null || _a === void 0 ? void 0 : _a[y])
|
|
1883
1899
|
}
|
|
1884
1900
|
|
|
1885
1901
|
function isRightmost(tiles, x, y) {
|
|
1886
|
-
|
|
1902
|
+
var _a
|
|
1903
|
+
return !((_a = tiles[x + 1]) === null || _a === void 0 ? void 0 : _a[y])
|
|
1887
1904
|
}
|
|
1888
1905
|
|
|
1889
1906
|
function isTopmost(tiles, x, y) {
|
|
@@ -1895,18 +1912,19 @@ function isBottommost(tiles, x, y) {
|
|
|
1895
1912
|
}
|
|
1896
1913
|
|
|
1897
1914
|
function getCorners(tiles, x, y) {
|
|
1915
|
+
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
1898
1916
|
const corners = []
|
|
1899
1917
|
if (!tiles[x][y]) {
|
|
1900
|
-
if (tiles[x - 1]
|
|
1918
|
+
if (((_a = tiles[x - 1]) === null || _a === void 0 ? void 0 : _a[y]) && tiles[x][y - 1]) {
|
|
1901
1919
|
corners.push({ x, y })
|
|
1902
1920
|
}
|
|
1903
|
-
if (tiles[x + 1]
|
|
1921
|
+
if (((_b = tiles[x + 1]) === null || _b === void 0 ? void 0 : _b[y]) && tiles[x][y - 1]) {
|
|
1904
1922
|
corners.push({ x: x + 1, y })
|
|
1905
1923
|
}
|
|
1906
|
-
if (tiles[x - 1]
|
|
1924
|
+
if (((_c = tiles[x - 1]) === null || _c === void 0 ? void 0 : _c[y]) && tiles[x][y + 1]) {
|
|
1907
1925
|
corners.push({ x, y: y + 1 })
|
|
1908
1926
|
}
|
|
1909
|
-
if (tiles[x + 1]
|
|
1927
|
+
if (((_d = tiles[x + 1]) === null || _d === void 0 ? void 0 : _d[y]) && tiles[x][y + 1]) {
|
|
1910
1928
|
corners.push({ x: x + 1, y: y + 1 })
|
|
1911
1929
|
}
|
|
1912
1930
|
return corners
|
|
@@ -1914,16 +1932,32 @@ function getCorners(tiles, x, y) {
|
|
|
1914
1932
|
if (isHorizontalLine(tiles, x, y) || isVerticalLine(tiles, x, y)) {
|
|
1915
1933
|
return []
|
|
1916
1934
|
}
|
|
1917
|
-
if (
|
|
1935
|
+
if (
|
|
1936
|
+
!((_e = tiles[x - 1]) === null || _e === void 0 ? void 0 : _e[y - 1]) &&
|
|
1937
|
+
isLeftmost(tiles, x, y) &&
|
|
1938
|
+
isTopmost(tiles, x, y)
|
|
1939
|
+
) {
|
|
1918
1940
|
corners.push({ x, y })
|
|
1919
1941
|
}
|
|
1920
|
-
if (
|
|
1942
|
+
if (
|
|
1943
|
+
!((_f = tiles[x + 1]) === null || _f === void 0 ? void 0 : _f[y - 1]) &&
|
|
1944
|
+
isRightmost(tiles, x, y) &&
|
|
1945
|
+
isTopmost(tiles, x, y)
|
|
1946
|
+
) {
|
|
1921
1947
|
corners.push({ x: x + 1, y })
|
|
1922
1948
|
}
|
|
1923
|
-
if (
|
|
1949
|
+
if (
|
|
1950
|
+
!((_g = tiles[x - 1]) === null || _g === void 0 ? void 0 : _g[y + 1]) &&
|
|
1951
|
+
isLeftmost(tiles, x, y) &&
|
|
1952
|
+
isBottommost(tiles, x, y)
|
|
1953
|
+
) {
|
|
1924
1954
|
corners.push({ x, y: y + 1 })
|
|
1925
1955
|
}
|
|
1926
|
-
if (
|
|
1956
|
+
if (
|
|
1957
|
+
!((_h = tiles[x + 1]) === null || _h === void 0 ? void 0 : _h[y + 1]) &&
|
|
1958
|
+
isRightmost(tiles, x, y) &&
|
|
1959
|
+
isBottommost(tiles, x, y)
|
|
1960
|
+
) {
|
|
1927
1961
|
corners.push({ x: x + 1, y: y + 1 })
|
|
1928
1962
|
}
|
|
1929
1963
|
return corners
|
|
@@ -1954,22 +1988,28 @@ function findLines(grid, tileSize) {
|
|
|
1954
1988
|
grid,
|
|
1955
1989
|
(x, y) => Boolean(grid[x][y] === 0 && grid[x][y + 1] !== 0),
|
|
1956
1990
|
'row-first'
|
|
1957
|
-
).map(point => ({
|
|
1991
|
+
).map(point => Object.assign(Object.assign({}, point), { dx: 1, dy: 0 }))
|
|
1958
1992
|
const lowerPoints = filterCoordinates(
|
|
1959
1993
|
grid,
|
|
1960
1994
|
(x, y) => Boolean(grid[x][y] === 0 && grid[x][y - 1] !== 0),
|
|
1961
1995
|
'row-first'
|
|
1962
|
-
).map(point => ({
|
|
1996
|
+
).map(point => Object.assign(Object.assign({}, point), { dx: 1, dy: 0 }))
|
|
1963
1997
|
const rightPoints = filterCoordinates(
|
|
1964
1998
|
grid,
|
|
1965
|
-
(x, y) =>
|
|
1999
|
+
(x, y) => {
|
|
2000
|
+
var _a
|
|
2001
|
+
return Boolean(grid[x][y] === 0 && ((_a = grid[x - 1]) === null || _a === void 0 ? void 0 : _a[y]) !== 0)
|
|
2002
|
+
},
|
|
1966
2003
|
'column-first'
|
|
1967
|
-
).map(point => ({
|
|
2004
|
+
).map(point => Object.assign(Object.assign({}, point), { dx: 0, dy: 1 }))
|
|
1968
2005
|
const leftPoints = filterCoordinates(
|
|
1969
2006
|
grid,
|
|
1970
|
-
(x, y) =>
|
|
2007
|
+
(x, y) => {
|
|
2008
|
+
var _a
|
|
2009
|
+
return Boolean(grid[x][y] === 0 && ((_a = grid[x + 1]) === null || _a === void 0 ? void 0 : _a[y]) !== 0)
|
|
2010
|
+
},
|
|
1971
2011
|
'column-first'
|
|
1972
|
-
).map(point => ({
|
|
2012
|
+
).map(point => Object.assign(Object.assign({}, point), { dx: 0, dy: 1 }))
|
|
1973
2013
|
upperPoints.forEach(vector => vector.y++)
|
|
1974
2014
|
leftPoints.forEach(vector => vector.x++)
|
|
1975
2015
|
const verticalLineSegments = group([...rightPoints, ...leftPoints], (current, previous) => {
|