@abcnews/core-hash-converter
v0.2.1
Published
A utility for converting strings to objects with various encodings structures.
Readme
core-hash-converter
Converts a CoreMedia #hashstring into a config object using all available characters.
Current characters supported, as per html4 spec:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
Or as a regex:
/^[a-z]+[a-z0-9\-_:\.]*$/iSo you can parse strings like:
"stringOne:Hello_numberOne:5_lat:-32.3_lng:-141.55_isSomething:true"And they turn into JavaScript objects:
{
stringOne: "Hello",
numberOne: 5,
lat: -32.3,
lng: -141.55,
isSomething: true,
}Installation
On JSR:
# deno, pnpm 10.9+, and yarn 4.9+ with first class JSR support
deno add jsr:@abcnews/core-hash-converter
pnpm add jsr:@abcnews/core-hash-converter
yarn add jsr:@abcnews/core-hash-converter
# npm, bun, and older versions of yarn or pnpm
npx jsr add @abcnews/core-hash-converter
bunx jsr add @abcnews/core-hash-converter
yarn dlx jsr add @abcnews/core-hash-converter
pnpm dlx jsr add @abcnews/core-hash-converterOr NPM:
npm install @abcnews/core-hash-converterUsage
import { parse } from "@abcnews/core-hash-converter";
const config = parse(
"stringOne:Hello_numberOne:5_lat:-32.3_lng:-141.55_isSomething:true_nothing:null",
);
console.log(config);In a CoreMedia artile you can create a mount point with #mymount_myNumer:42 and then use mount-utils to select it with selectMounts('mymount') and then parse the getMountValue string with parse(mountValue).
Development
Pushes to main with a new version number will automatically be pushed to JSR.
Build for NPM with deno task build-npm (will read your deno.json version number).
Then npm login with your (ABC approved) NPM account and npm publish --access public to publish.
Notes
This tool is meant for use with ABC News Digital CMS CoreMedia, but could be helpful for others to use too.
