Socket
Socket
Sign inDemoInstall

assets-hash-map

Package Overview
Dependencies
12
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    assets-hash-map

Command-line tool / Node.js utility to recursively generate maps of filepaths and sha-sums - comes in handy for cachebusting.


Version published
Weekly downloads
702
decreased by-14.08%
Maintainers
1
Install size
320 kB
Created
Weekly downloads
 

Readme

Source

assets-hash-map

Command-line tool / Node.js utility to recursively generate maps of filepaths and sha-sums - comes in handy for cachebusting.

Command-line
Install
npm install -g assets-hash-map
Simple usage
assets-hash-map my-dir
Example output:
{
  "public/assets/my-dir/image1.png": "b5e7a2060081a33477a98db33eac9ec4c59ba5db",
  "public/assets/my-dir/image2.png": "a58bdd9dcc965d5b0f36b75f33a5fbcb6f2036ab",
  "public/assets/other-dir/my-font.woff": "a58bdd9dcc965d5b0f36b75f33a5fbcb6f2036ab",
  "public/assets/other-dir/my-font.woff2": "a58bdd9dcc965d5b0f36b75f33a5fbcb6f2036ab"
}
Command-line options
+--------------------------------+
|   Assets Hash Map generator:   |
+--------------------------------+

Generate a JSON assets hash map.
Usage: assets-hash-map [ paths ]

Options:
  -e, --extensions  Filter by file extension (comma separated)
  -x, --exclude     Exclude file extensions (comma separated)
  -b, --base-path   Set base path (filepaths will be relative to this)
  -s, --spaces      Tab spaces used formatting the JSON (defaults to 2)
  -o, --output      Output file (defaults to STDOUT)
  -a, --all         Include hidden files
  -h, --help        Show usage info

Example:
  assets-hash-map /dev/my-project/assets \\
    -e png,jpg,svg \\
    -x html,md \\
    -b /dev/my-project \\
    -s 0
    -o foo.json
Node.js API
Install
npm install assets-hash-map
getHashesMap(filepath)

Returns a Promise, which resolves with an Object containing the hash map for files in the given path.

Fails if called on an unexisting path.

Options:

  • include : {String[]} Only include these extensions (default: null)
  • exclude : {String[]} Extenstions to exclude (default: null)
  • absolute : {Boolean} Use absolute paths in map (default: false)
  • basePath : {String} Used to output relative paths (default: null)
  • all : {Boolean} Include hidden files (default: false)
Example
const { getHashesMap } = require('assets-hash-map')

getHashesMap('./my-project', { include: [ 'png', 'jpg' ] })
.then(hashesMap => {
  console.log(hashesMap)
})

// {
//   'public/assets/my-dir/image1.png': 'b5e7a2060081a33477a98db33eac9ec4c59ba5db',
//   'public/assets/my-dir/image2.png': 'a58bdd9dcc965d5b0f36b75f33a5fbcb6f2036ab',
//   'public/assets/other-dir/image3.jpg': 'a58bdd9dcc965d5b0f36b75f33a5fbcb6f2036ab',
//   'public/assets/other-dir/image4.jpg': 'a58bdd9dcc965d5b0f36b75f33a5fbcb6f2036ab'
// }

FAQs

Last updated on 15 Nov 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc