Moving NanoID from MiniDocs.
This commit is contained in:
parent
f9daa6775f
commit
19c4275dcd
66
src/ExoRepo/NanoID.class.st
Normal file
66
src/ExoRepo/NanoID.class.st
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"
|
||||||
|
I'm run an implementation of the [Nano ID](https://github.com/ai/nanoid) tiny, secure URL-friendly unique string ID generator via its [Nim implementation](https://github.com/icyphox/nanoid.nim).
|
||||||
|
|
||||||
|
The Nim script has hard coded:
|
||||||
|
|
||||||
|
* a [base 58 encoding](https://medium.com/concerning-pharo/understanding-base58-encoding-23e673e37ff6) alphabet to avoid similar looking letter and the use of non-alphanumeric characters.
|
||||||
|
* a 12 characters length output, which gives [a pretty low probability collision](https://zelark.github.io/nano-id-cc/) for the previous alphabet:
|
||||||
|
~616 years needed, in order to have a 1% probability of at least one collision at a speed of 1000 IDs per hour.
|
||||||
|
This is more than enough for our unique IDs applications, mostly in the documentation context,
|
||||||
|
which consists of hand crafted and/or programmatically produced notes ,
|
||||||
|
for example in data narratives, book(lets) and TiddlyWiki tiddlers of tens or hundreds of notes at most,
|
||||||
|
unevenly produced between hours, days and/or weeks..
|
||||||
|
|
||||||
|
The `External` tag is related on its dependency on other programming languages and frameworks,
|
||||||
|
though the dependency should be loaded by just loading a small binary with no dependencies.
|
||||||
|
"
|
||||||
|
Class {
|
||||||
|
#name : #NanoID,
|
||||||
|
#superclass : #Object,
|
||||||
|
#category : #'ExoRepo-External'
|
||||||
|
}
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
NanoID class >> binaryFile [
|
||||||
|
Smalltalk os isWindows
|
||||||
|
ifFalse: [ ^ MiniDocs appFolder / self scriptSourceCode basenameWithoutExtension ]
|
||||||
|
ifTrue: [ ^ ExoRepo userDataFolder / 'NanoId' / 'nanoid' ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
NanoID class >> generate [
|
||||||
|
self binaryFile exists ifFalse: [ NanoID install].
|
||||||
|
Smalltalk os isWindows
|
||||||
|
ifTrue: [ ^ (LibC resultOfCommand:self binaryFile fullName) copyWithoutAll: (Character lf asString) ].
|
||||||
|
OSSUnixSubprocess new
|
||||||
|
command: self binaryFile fullName;
|
||||||
|
redirectStdout;
|
||||||
|
redirectStdout;
|
||||||
|
runAndWaitOnExitDo: [ :process :outString | ^ outString copyWithoutAll: (Character lf asString) ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
NanoID class >> install [
|
||||||
|
"For the moment, only Gnu/Linux and Mac are supported.
|
||||||
|
IMPORTANT: Nimble, Nim's package manager should be installed, as this process doesn't verify its proper installation."
|
||||||
|
self binaryFile exists ifTrue: [ ^ MiniDocs appFolder ].
|
||||||
|
Nimble install: 'nanoid'.
|
||||||
|
Smalltalk os isWindows
|
||||||
|
ifTrue: [ ^ LibC resultOfCommand: 'nanoid c ',self scriptSourceCode fullName ].
|
||||||
|
OSSUnixSubprocess new
|
||||||
|
command: 'nim';
|
||||||
|
arguments: {'c'. self scriptSourceCode fullName};
|
||||||
|
runAndWaitOnExitDo: [ :process :outString |
|
||||||
|
(self scriptSourceCode parent / (self scriptSourceCode) basenameWithoutExtension) moveToPageTitled: MiniDocs appFolder asFileReference.
|
||||||
|
^ MiniDocs appFolder ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
NanoID class >> isInstalled [
|
||||||
|
^ self binaryFile exists
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #accessing }
|
||||||
|
NanoID class >> scriptSourceCode [
|
||||||
|
^ FileLocator image parent / 'pharo-local/iceberg/Offray/MiniDocs/src/nanoIdGen.nim'
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user