README
url-dirname-normalizer
Normalize URLs to be valid filesystem paths for archiving web pages and their assets
Version | Size | Dependencies |
---|---|---|
Usage
dirnameNormalizer
The default exported function is; dirnameNormalizer
.
import dirnameNormalizer from 'url-dirname-normalizer'
// HTML Source document URL from where the asset is embedded
// Ignore document origin if resource has full URL, protocol relative, non TLS
const sourceDocument =
'http://example.org/@ausername/some-lengthy-string-ending-with-a-hash-1a2d8a61510'
/**
* Filesystem path where to write files to
*/
dirnameNormalizer(sourceDocument)
// > "example.org/ausername/some-lengthy-string-ending-with-a-hash"
normalizer
Alongside the default export, there is also a normalizer
with a few methods.
Refer to notes in
pathName in normalizer/path-name.ts
and
searchParams in normalizer/search-params.ts
import { normalizer } from 'url-dirname-normalizer'
const examplePathName = 'http://www.example.org/fOo/Bar/bAAz.html'
normalizer.pathName(examplePathName)
// > "/foo/bar/baaz"
const exampleSearchParams = 'http://example.org/foo?zulu=please&bar=bazz&buzz'
normalizer.searchParams(exampleSearchParams)
// > "/bar/bazz/zulu/please"