Skip to content

Commit

Permalink
📖 docs: Typos and whatnot
Browse files Browse the repository at this point in the history
  • Loading branch information
masonmark committed Dec 22, 2024
1 parent 64aa9c8 commit 1063a74
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ However, it probably doesn't work on Windows. Such is life...😭

## Happenings

### 👹 2024-12-22: v0.0.3
### 👹 2024-12-22: v0.0.3 ~ v0.0.4

No functionality changes, just various improvements to the docs and formatting.

Expand Down
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axhxrx/write-new-file",
"version": "0.0.3",
"version": "0.0.4",
"exports": "./mod.ts",
"license": "MIT",
"imports": {
Expand Down
8 changes: 4 additions & 4 deletions formatDateForFilenameSuffix.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
Returns a date string suitable for filenames, like "1975-09-05-02-34-56" by default.
Returns a date string suitable for filenames, like `'1974-09-05-02-34-56'` by default.
Although this date format is an abomination before science and mankind, we have a reason for not using the [One True Date Format](https://xkcd.com/1179/) — modern computers suck at naming files.
You *can* make it more (human-)readable, like "1975-09-05 02:34:56" by passing ' ' and ':' for replaceSpaceWith and replaceColonWith, if you are willing to live with the filename consequences.
You *can* make it more (human-)readable, like `'1975-09-05 02:34:56'` by passing `' '` and `':'` for `replaceSpaceWith` and `replaceColonWith`, if you are willing to live with the filename consequences.
By default, though, both are replaced with '-' because this is intended for filenames, and funky chars are sus.
By default, though, both are replaced with `'-'` because this is intended for filenames, and funky chars are sus.
Uses your local timezone because that's usually what you want for files anyway.
Expand All @@ -17,7 +17,7 @@ Uses your local timezone because that's usually what you want for files anyway.
@returns A filename-friendly date string formatted as YYYY-MM-DD{space}HH{colon}mm{colon}ss
@throws {TypeError} If you give it something that's not actually a Date
@throws {TypeError} Should never throw, unless you manage to pass a `date` value that that's not actually a `Date`.
*/
export function formatDateForFilenameSuffix(
date: Date,
Expand Down
10 changes: 6 additions & 4 deletions writeNewFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import { WriteNewOptions } from './WriteNewOptions.ts';
Writes data to a unique file path using a date-based suffix, in a concurrency-safe manner. That is, if some other process or thread writes a file at the same time, we will fail, increment the suffix and try again, until we succeed at writing a new and uniquely-named file.
The logic is:
1. If we can write the file with the proposed filename as-is, we're done. Otherwise:
2. For the "current second" of the clock, try a suffix like:
If we can write the file with the proposed filename as-is, we're done. Otherwise:
1. For the "current second" of the clock, try a suffix like:
`'basename~YYYY-MM-DD HH:mm:ss.ext'`
3. If that fails because it already exists, repeatedly:
2. If that fails because it already exists, repeatedly:
- Sleep 50ms
- If the second is still the same, we try: `'basename~YYYY-MM-DD HH:mm:ss+SSS.ext'` (where `SSS` is the millisecond portion)
- If that also exists, keep looping in 50ms increments until either we succeed or the clock moves on to a new second
4. Once the clock changes to a new second, start over at (1) with the fresh seconds-only string.
3. Once the clock changes to a new second, start over at (1) with the fresh seconds-only string.
This yields filenames that, in lexicographic order (on most OS ), generally tend to match their creation order (even across different platforms), in GUI file browsers or results of `ls`, etc.
Expand Down

0 comments on commit 1063a74

Please sign in to comment.