Skip to content

Commit af09c41

Browse files
authored
Merge branch 'master' into add-starts-with-and-ends-with
2 parents d6adb7f + 03b03a7 commit af09c41

17 files changed

Lines changed: 136 additions & 137 deletions

File tree

.eslintrc.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"parserOptions": {
3-
"ecmaVersion": 5
3+
"ecmaVersion": 6,
4+
"sourceType": "module"
45
},
56
"extends": "eslint:recommended",
6-
"env": {
7-
"commonjs": true
8-
},
97
"rules": {
108
"strict": [2, "global"],
119
"block-scoped-var": 2,

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ jobs:
1313
- uses: actions/checkout@v2
1414

1515
- uses: purescript-contrib/setup-purescript@main
16+
with:
17+
purescript: "unstable"
1618

17-
- uses: actions/setup-node@v1
19+
- uses: actions/setup-node@v2
1820
with:
19-
node-version: "12"
21+
node-version: "14.x"
2022

2123
- name: Install dependencies
2224
run: |

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,28 @@ New features:
1111

1212
Bugfixes:
1313

14+
Other improvements:
15+
- Redefine `Data.String.NonEmpty.CodeUnits.fromFoldable1` in terms of `singleton` (#168 by @postsolar)
16+
17+
## [v6.0.1](https://github.com/purescript/purescript-strings/releases/tag/v6.0.1) - 2022-08-16
18+
19+
Bugfixes:
20+
- Fix `Char`'s `toEnum` implementation (#163 by @JordanMartinez)
21+
22+
## [v6.0.0](https://github.com/purescript/purescript-strings/releases/tag/v6.0.0) - 2022-04-27
23+
24+
Breaking changes:
25+
- Migrate FFI to ES modules (#158 by @kl0tl and @JordanMartinez)
26+
- Replaced polymorphic proxies with monomorphic `Proxy` (#158 by @JordanMartinez)
27+
- In `slice`, drop bounds checking and `Maybe` return type (#145 by Quelklef)
28+
29+
New features:
30+
31+
Bugfixes:
32+
1433
Other improvements:
1534
- Surround code with backticks in documentation (#148)
35+
- Make `RegexFlags` a `newtype` and a `Newtype` instance for it(#159 by @mhmdanas)
1636

1737
## [v5.0.0](https://github.com/purescript/purescript-strings/releases/tag/v5.0.0) - 2021-02-26
1838

bower.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@
1616
"package.json"
1717
],
1818
"dependencies": {
19-
"purescript-arrays": "^6.0.0",
20-
"purescript-control": "^5.0.0",
21-
"purescript-either": "^5.0.0",
22-
"purescript-enums": "^5.0.0",
23-
"purescript-foldable-traversable": "^5.0.0",
24-
"purescript-gen": "^3.0.0",
25-
"purescript-integers": "^5.0.0",
26-
"purescript-maybe": "^5.0.0",
27-
"purescript-newtype": "^4.0.0",
28-
"purescript-nonempty": "^6.0.0",
29-
"purescript-partial": "^3.0.0",
30-
"purescript-prelude": "^5.0.0",
31-
"purescript-tailrec": "^5.0.0",
32-
"purescript-tuples": "^6.0.0",
33-
"purescript-unfoldable": "^5.0.0",
34-
"purescript-unsafe-coerce": "^5.0.0"
19+
"purescript-arrays": "^7.0.0",
20+
"purescript-control": "^6.0.0",
21+
"purescript-either": "^6.0.0",
22+
"purescript-enums": "^6.0.1",
23+
"purescript-foldable-traversable": "^6.0.0",
24+
"purescript-gen": "^4.0.0",
25+
"purescript-integers": "^6.0.0",
26+
"purescript-maybe": "^6.0.0",
27+
"purescript-newtype": "^5.0.0",
28+
"purescript-nonempty": "^7.0.0",
29+
"purescript-partial": "^4.0.0",
30+
"purescript-prelude": "^6.0.0",
31+
"purescript-tailrec": "^6.0.0",
32+
"purescript-tuples": "^7.0.0",
33+
"purescript-unfoldable": "^6.0.0",
34+
"purescript-unsafe-coerce": "^6.0.0"
3535
},
3636
"devDependencies": {
37-
"purescript-assert": "^5.0.0",
38-
"purescript-console": "^5.0.0",
39-
"purescript-minibench": "^3.0.0"
37+
"purescript-assert": "^6.0.0",
38+
"purescript-console": "^6.0.0",
39+
"purescript-minibench": "^4.0.0"
4040
}
4141
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"clean": "rimraf output && rimraf .pulp-cache",
55
"build": "eslint src && pulp build -- --censor-lib --strict",
66
"test": "pulp test && npm run test:run:without_codePointAt",
7-
"test:run:without_codePointAt": "node -e \"delete String.prototype.codePointAt; require('./output/Test.Main/index.js').main();\"",
7+
"test:run:without_codePointAt": "node -e \"delete String.prototype.codePointAt; import('./output/Test.Main/index.js').then(m => m.main());\"",
88
"bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'",
99
"bench:run": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").main()'",
1010
"bench": "npm run bench:build && npm run bench:run"
1111
},
1212
"devDependencies": {
1313
"eslint": "^7.15.0",
14-
"pulp": "^15.0.0",
15-
"purescript-psa": "^0.8.0",
14+
"pulp": "16.0.0-0",
15+
"purescript-psa": "^0.8.2",
1616
"rimraf": "^3.0.2"
1717
}
1818
}

src/Data/String/CodePoints.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use strict";
21
/* global Symbol */
32

43
var hasArrayFrom = typeof Array.from === "function";
@@ -10,13 +9,13 @@ var hasStringIterator =
109
var hasFromCodePoint = typeof String.prototype.fromCodePoint === "function";
1110
var hasCodePointAt = typeof String.prototype.codePointAt === "function";
1211

13-
exports._unsafeCodePointAt0 = function (fallback) {
12+
export const _unsafeCodePointAt0 = function (fallback) {
1413
return hasCodePointAt
1514
? function (str) { return str.codePointAt(0); }
1615
: fallback;
1716
};
1817

19-
exports._codePointAt = function (fallback) {
18+
export const _codePointAt = function (fallback) {
2019
return function (Just) {
2120
return function (Nothing) {
2221
return function (unsafeCodePointAt0) {
@@ -40,7 +39,7 @@ exports._codePointAt = function (fallback) {
4039
};
4140
};
4241

43-
exports._countPrefix = function (fallback) {
42+
export const _countPrefix = function (fallback) {
4443
return function (unsafeCodePointAt0) {
4544
if (hasStringIterator) {
4645
return function (pred) {
@@ -59,7 +58,7 @@ exports._countPrefix = function (fallback) {
5958
};
6059
};
6160

62-
exports._fromCodePointArray = function (singleton) {
61+
export const _fromCodePointArray = function (singleton) {
6362
return hasFromCodePoint
6463
? function (cps) {
6564
// Function.prototype.apply will fail for very large second parameters,
@@ -74,11 +73,11 @@ exports._fromCodePointArray = function (singleton) {
7473
};
7574
};
7675

77-
exports._singleton = function (fallback) {
76+
export const _singleton = function (fallback) {
7877
return hasFromCodePoint ? String.fromCodePoint : fallback;
7978
};
8079

81-
exports._take = function (fallback) {
80+
export const _take = function (fallback) {
8281
return function (n) {
8382
if (hasStringIterator) {
8483
return function (str) {
@@ -96,7 +95,7 @@ exports._take = function (fallback) {
9695
};
9796
};
9897

99-
exports._toCodePointArray = function (fallback) {
98+
export const _toCodePointArray = function (fallback) {
10099
return function (unsafeCodePointAt0) {
101100
if (hasArrayFrom) {
102101
return function (str) {

src/Data/String/CodePoints.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ uncons s = case CU.length s of
207207
-- | ```purescript
208208
-- | >>> length "b 𝐀𝐀 c 𝐀"
209209
-- | 8
210-
-- | -- compare to Data.String:
210+
-- | -- compare to Data.String.CodeUnits:
211211
-- | >>> length "b 𝐀𝐀 c 𝐀"
212212
-- | 11
213213
-- | ```
@@ -314,7 +314,7 @@ lastIndexOf' p i s =
314314

315315
-- | Returns a string containing the given number of code points from the
316316
-- | beginning of the given string. If the string does not have that many code
317-
-- | points, returns the empty string. Operates in constant space and in time
317+
-- | points, returns the entire string. Operates in constant space and in time
318318
-- | linear to the given number.
319319
-- |
320320
-- | ```purescript

src/Data/String/CodeUnits.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
"use strict";
2-
3-
exports.fromCharArray = function (a) {
1+
export const fromCharArray = function (a) {
42
return a.join("");
53
};
64

7-
exports.toCharArray = function (s) {
5+
export const toCharArray = function (s) {
86
return s.split("");
97
};
108

11-
exports.singleton = function (c) {
9+
export const singleton = function (c) {
1210
return c;
1311
};
1412

15-
exports._charAt = function (just) {
13+
export const _charAt = function (just) {
1614
return function (nothing) {
1715
return function (i) {
1816
return function (s) {
@@ -22,27 +20,27 @@ exports._charAt = function (just) {
2220
};
2321
};
2422

25-
exports._toChar = function (just) {
23+
export const _toChar = function (just) {
2624
return function (nothing) {
2725
return function (s) {
2826
return s.length === 1 ? just(s) : nothing;
2927
};
3028
};
3129
};
3230

33-
exports.length = function (s) {
31+
export const length = function (s) {
3432
return s.length;
3533
};
3634

37-
exports.countPrefix = function (p) {
35+
export const countPrefix = function (p) {
3836
return function (s) {
3937
var i = 0;
4038
while (i < s.length && p(s.charAt(i))) i++;
4139
return i;
4240
};
4341
};
4442

45-
exports._indexOf = function (just) {
43+
export const _indexOf = function (just) {
4644
return function (nothing) {
4745
return function (x) {
4846
return function (s) {
@@ -53,7 +51,7 @@ exports._indexOf = function (just) {
5351
};
5452
};
5553

56-
exports._indexOfStartingAt = function (just) {
54+
export const _indexOfStartingAt = function (just) {
5755
return function (nothing) {
5856
return function (x) {
5957
return function (startAt) {
@@ -67,7 +65,7 @@ exports._indexOfStartingAt = function (just) {
6765
};
6866
};
6967

70-
exports._lastIndexOf = function (just) {
68+
export const _lastIndexOf = function (just) {
7169
return function (nothing) {
7270
return function (x) {
7371
return function (s) {
@@ -78,7 +76,7 @@ exports._lastIndexOf = function (just) {
7876
};
7977
};
8078

81-
exports._lastIndexOfStartingAt = function (just) {
79+
export const _lastIndexOfStartingAt = function (just) {
8280
return function (nothing) {
8381
return function (x) {
8482
return function (startAt) {
@@ -91,27 +89,27 @@ exports._lastIndexOfStartingAt = function (just) {
9189
};
9290
};
9391

94-
exports.take = function (n) {
92+
export const take = function (n) {
9593
return function (s) {
9694
return s.substr(0, n);
9795
};
9896
};
9997

100-
exports.drop = function (n) {
98+
export const drop = function (n) {
10199
return function (s) {
102100
return s.substring(n);
103101
};
104102
};
105103

106-
exports._slice = function (b) {
104+
export const slice = function (b) {
107105
return function (e) {
108106
return function (s) {
109107
return s.slice(b,e);
110108
};
111109
};
112110
};
113111

114-
exports.splitAt = function (i) {
112+
export const splitAt = function (i) {
115113
return function (s) {
116114
return { before: s.substring(0, i), after: s.substring(i) };
117115
};

src/Data/String/CodeUnits.purs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ uncons s = Just { head: U.charAt zero s, tail: drop one s }
172172
-- |
173173
-- | ```purescript
174174
-- | length "Hello World" == 11
175+
-- |
176+
-- | length "𝐀A" == 3
177+
-- | -- compare to Data.String.CodePoints:
178+
-- | length "𝐀A" == 2
175179
-- | ```
176180
-- |
177181
foreign import length :: String -> Int
@@ -325,30 +329,17 @@ dropWhile p s = drop (countPrefix p s) s
325329

326330
-- | Returns the substring at indices `[begin, end)`.
327331
-- | If either index is negative, it is normalised to `length s - index`,
328-
-- | where `s` is the input string. `Nothing` is returned if either
332+
-- | where `s` is the input string. `""` is returned if either
329333
-- | index is out of bounds or if `begin > end` after normalisation.
330334
-- |
331335
-- | ```purescript
332-
-- | slice 0 0 "purescript" == Just ""
333-
-- | slice 0 1 "purescript" == Just "p"
334-
-- | slice 3 6 "purescript" == Just "esc"
335-
-- | slice (-4) (-1) "purescript" == Just "rip"
336-
-- | slice (-4) 3 "purescript" == Nothing
336+
-- | slice 0 0 "purescript" == ""
337+
-- | slice 0 1 "purescript" == "p"
338+
-- | slice 3 6 "purescript" == "esc"
339+
-- | slice (-4) (-1) "purescript" == "rip"
340+
-- | slice (-4) 3 "purescript" == ""
337341
-- | ```
338-
slice :: Int -> Int -> String -> Maybe String
339-
slice b e s = if b' < 0 || b' >= l ||
340-
e' < 0 || e' > l ||
341-
b' > e'
342-
then Nothing
343-
else Just (_slice b e s)
344-
where
345-
l = length s
346-
norm x | x < 0 = l + x
347-
| otherwise = x
348-
b' = norm b
349-
e' = norm e
350-
351-
foreign import _slice :: Int -> Int -> String -> String
342+
foreign import slice :: Int -> Int -> String -> String
352343

353344
-- | Splits a string into two substrings, where `before` contains the
354345
-- | characters up to (but not including) the given index, and `after` contains

0 commit comments

Comments
 (0)