Skip to content

Commit

Permalink
Merge pull request #1 from pblasucci/smaller-api
Browse files Browse the repository at this point in the history
New simpler API
  • Loading branch information
pblasucci authored Aug 16, 2023
2 parents 85c47ce + 8858046 commit e3c9ee2
Show file tree
Hide file tree
Showing 46 changed files with 1,321 additions and 2,358 deletions.
8 changes: 1 addition & 7 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"fsdocs-tool": {
"version": "18.1.0",
"version": "18.1.1",
"commands": [
"fsdocs"
]
Expand All @@ -13,12 +13,6 @@
"commands": [
"fantomas"
]
},
"powershell": {
"version": "7.3.6",
"commands": [
"pwsh"
]
}
}
}
6 changes: 0 additions & 6 deletions NuGet.Config

This file was deleted.

27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,12 @@ ananoid

### TO DO

- [x] **icon!**
- [x] design / fabricate
- [x] use in NuGet package
- [x] use in documentation
- [x] api docs
- [x] docs template
- [x] cross-link
- [x] fix toggle bug
- [x] upgrade/review Fantomas
- [x] narrative docs
- [x] docs template
- [x] getting started
- [-] lower-level APIs
- [ ] actual example of taking core from source
- [x] customization
- [-] documentation
- [ ] performance
- [ ] ananoidcc
- [ ] justification
- [-] Source Link
- [ ] ?? fake ??
- [ ] ?? paket ??
- [ ] GH Actions
- [ ] build and test PRs against main
- [ ] CONTRIBUTE
- [ ] CHANGELOG
- [-] README

```sh
dotnet fsdocs watch --port 2023 --input ./docSrc/ --parameters \
fsdocs-license-link https://github.com/pblasucci/ananoid/blob/main/LICENSE.txt \
fsdocs-readme-link https://github.com/pblasucci/ananoid/blob/main/README.md
```
45 changes: 0 additions & 45 deletions ananoid.compat.csharp/Advanced/NanoIdFactory.cs

This file was deleted.

121 changes: 0 additions & 121 deletions ananoid.compat.csharp/Advanced/NanoIdOptions.cs

This file was deleted.

87 changes: 27 additions & 60 deletions ananoid.compat.csharp/Basics/Creation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,75 @@ This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

namespace pblasucci.Ananoid.Compat.Basics;

#pragma warning disable CS1591
// ⮝⮝⮝ missing XMLDoc comments

using Support;


[Properties(Arbitrary = new[] { typeof(Generation) })]
public class Creation
{
[Property(MaxTest = 1)]
public bool all_forms_of_empty_are_equal()
[Property]
public bool All_forms_of_empty_are_equal(NegativeInt input)
{
// By default, a NanoId is empty.
NanoId emptyId = default;
NanoId empty1 = default;

// But using the static member `Empty` is preferred.
return emptyId.Equals(NanoId.Empty);
var empty2 = NanoId.Empty;

// empty instance can be created from sizes less than one.
var empty3 = KnownAlphabets.UrlSafe.MakeNanoId(size: (int)input);

return empty1.Equals(empty2) &&
empty2.Equals(empty3) &&
empty3.Equals(empty1);
}

[Property(MaxTest = 1)]
public bool being_empty_means_having_length_zero()
public bool Being_empty_means_having_length_zero()
{
// NanoId has a fixed length -- even as a string.
return NanoId.Empty.Length is 0 && NanoId.Empty.ToString()!.Length is 0;
}

[Property]
public Property any_number_of_empties_are_equal(PositiveInt input)
public Property Any_number_of_empties_are_equal(PositiveInt input)
{
var count = (int)input;
var items =
from _ in Enumerable.Range(start: 1, count) select default(NanoId);

// The static method `NanoId.IsEmpty()` can check for emptiness, too.
return items.All(NanoId.IsEmpty).Collect(count);
return items.All(n => n.Length < 1).Collect(count);
}

[Property]
public Property nano_id_length_is_options_size(
NanoIdOptions options,
public Property Nano_id_length_is_input_size(
Alphabet alphabet,
NonNegativeInt input
)
{
var size = (int)input;
// NanoIdOptions for known alphabets default to generating 21-character
// strings, but can easily to customized to generate larger or smaller ones.
var resized = options.Resize(size);
var nanoId = NanoId.NewId(resized);

var lengthSize = nanoId.Length == size && nanoId.ToString()!.Length == size;
return lengthSize.Collect((resized, nanoId));
}

[Property]
public Property resizing_options_does_not_change_alphabet(
NanoIdOptions options,
PositiveInt input
)
{
var newSize = (int)input;
// A NanoIdOptions instance can be decomposed into a tuple.
var (alphabet, size) = options;

return Test().When(newSize != size).Collect((alphabet, size, newSize));

bool Test()
{
var resized = options.Resize(newSize);
return resized.Alphabet.Equals(alphabet);
}
}
// An alphabet is really just a factory for generating NanoId instances.
var nanoId = alphabet.MakeNanoId(size);

[Property(MaxTest = 1)]
public bool options_resized_to_zero_generate_empty_nano_ids(
NanoIdOptions options
)
{
var resized = options.Resize(0);
var nanoId = NanoId.NewId(resized);
return NanoId.IsEmpty(nanoId);
return (nanoId.Length == size).Collect((size, nanoId));
}

[Property(MaxTest = 1)]
public Property by_default_new_nanoid_is_21_url_safe_characters()
public Property By_default_new_nanoid_is_21_url_safe_characters()
{
// This is the most common way to get a (non-empty) NanoId instance.
var nanoId = NanoId.NewId();

return NanoIdOptions.UrlSafe switch
{
// Should you wish to patten match, `NanoIdOptions` instances
// expose their alphabet and target size as read-only properties.
{ Alphabet: var alphabet, Size: var size } =>
alphabet
.WillPermit(nanoId)
.And(nanoId.Length == size)
.Collect(nanoId),

// ⮟⮟⮟ Will never match!
_ => false.ToProperty()
};
return KnownAlphabets.UrlSafe
.TryParseNanoId(nanoId.ToString(), out _)
// ⮝⮝⮝ if the alphabet can successfully parse it,
// ... that's a good-enough proxy for "is of this alphabet".
.And(nanoId.Length is 21)
.Collect(nanoId);
}
}
Loading

0 comments on commit e3c9ee2

Please sign in to comment.