npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gjs-template-filler

v1.2.0

Published

Populates Html template produced by vue-gjs-doc-creator and return html string with populated data

Downloads

69

Readme

gjs-template-filler

Populates Html template produced by vue-gjs-doc-creator and return html string with populated data

Installation

npm i gjs-template-filler

yarn add gjs-template-filler

Usage

import { populateHTMLTemplate } from "gjs-template-filler";

const testHTML = `
<div data-property="first_name">
	[First Name Here]
</div>
<div data-property="last_name">
	[Last Name Here]
</div>
<div data-property="date_of_birth" data-type="date">
	[Date Of Birth Here]
</div>

<span data-property="age" data-type="custom" data-append=" years old"></span>

<span data-property="status" data-default="N/A">[Status Here]</span>

<div data-property="progress" data-type="percentage" data-precision="2">
	[Progress]
</div>

<div data-property="hobbies" data-seperator=",">
 Hobbies: <span data-value></span>
</div>

<div>
	Address: <br/>
	<span data-property="address.street">[Street Here]</span>
	<span data-property="address.city">[City Here]</span>
	<span data-property="address.province">[Province Here]</span>
	<span data-property="address.country">[Country Here]</span>
</div>

<table data-property="employment_details" border="1"  cellpadding="1">
  <caption style="text-align: left; margin-bottom: 5px"><b>Cash Collaterals</b></caption>
  <thead>
	  <tr>
		  <th data-key="employer" style="width: 20%;">&nbsp; Employer</th>
		  <th data-key="address"  style="width: 12%;">&nbsp; Address</th>
			<th data-key="salary" data-type="currency" data-number-seperator="," data-symbol="$" data-precision="2">&nbsp; Salary</th>
	  </tr>
  </thead>
</table>
`;

const data = {
	first_name: "John",
	last_name: "Doe",
	date_of_birth: "1990-09-04",
	age: 31,
	hobbies: ["Coding", "Video Games"],
	progress: 10,
	address: {
		street: "Main Street",
		city: "Mandeville",
		province: "Manchester",
		country: "Jamaica",
	},
	employment_details: [
		{
			employer: "VTDI",
			address: "66 Caledonia Road, Mandeville, Manchester",
			salary: 60000,
		},
	],
};

const populatedHtml = populateHTMLTemplate(testHTML, testData);

Formatters

Formatters are denoted by the data-type attribute on an element and can have the value one of the following number, percentage, currency or date. If the data-type is not provided then the value remains as is. Formatters can also have specific options attached to them for instance, data-precision attribute which specify the number of decimal places to round a number to. See options below.

Formatter Options

Number

Format a value to a number

| Options | Default Value | Description | | -------------- | ------------- | --------------------------------------------------- | | data-precision | 0 | The number of decimal places to round the number to |

Number

Format a value to a percentage

| Options | Default Value | Description | | -------------- | ------------- | --------------------------------------------------- | | data-precision | 0 | The number of decimal places to round the number to |

Currency

Formats a value to a specific currency

| Options | Default Value | Description | | --------------------- | ------------- | --------------------------------------------------- | | data-precision | 0 | The number of decimal places to round the number to | | data-symbol | $ | The currency symbol to display | | data-number-seperator | , | The digit separator |

Date

Tries to format value to the date format provided. If the date is already in the format, the data-type and data-format attribute can be left off.

| Options | Default Value | Description | | ----------- | ------------- | ------------------------------------------------------------- | | data-format | - | See date format options below. Eg. data-format="yyyy-MM-dd" |

Format string can be anything, but the following letters will be replaced (and leading zeroes added if necessary):

  • dd - date.getDate()
  • MM - date.getMonth() + 1
  • yy - date.getFullYear().toString().substring(2, 4)
  • yyyy - date.getFullYear()
  • hh - date.getHours()
  • mm - date.getMinutes()
  • ss - date.getSeconds()
  • SSS - date.getMilliseconds()
  • O - timezone offset in +hm format (note that time will be in UTC if displaying offset)

Custom

Format value to a custom format by appending and/or prepending a custom string to it.

| Options | Default Value | Description | | ------------ | ------------- | ---------------------- | | data-append | | Comes after the value | | data-prepend | | Comes before the value |