JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q28405F
  • License MIT

This library provides timestamp and supports custom templates for its output file.

Package Exports

  • @puya/ts
  • @puya/ts/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@puya/ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Timestamper

Timestamper is a Node.js library and CLI tool that provides timestamp functionality and supports custom templates for its output file. It allows you to easily add a timestamp to a JSON file or any other file format based on a template.

Features

  • Add Timestamp: Automatically add a timestamp to a specified output file.
  • Custom Templates: Use custom templates for the output file.
  • Locale Support: Supports different locales for timestamp formatting (e.g., en, fa).
  • CLI and Programmatic Use: Can be used as a command-line tool or imported as a module in your Node.js projects.

Installation

You can install Timestamper globally for CLI use or locally in your project.

Global Installation

Install globally to use the ts command:

npm install -g @puya/ts

Local Installation

Install locally in your project:

npm install @puya/ts

Usage

CLI

Once installed globally, you can use the ts command in your terminal.

ts [options]

Options

  • -l [locale]: The locale to use for formatting the date/time. Default is en.
  • -o [outputfile]: The name of the output file where the result will be saved. Default is info.json.
  • -t [template]: The path to a template file.
  • -f [format]: The format string to use for formatting the date/time. Default is YYYYMMDDHHmm.
  • -so: skip generating output file.
  • -i [inline-template]: Inline template string.

Examples

  1. Add a timestamp using the default settings:

    ts
  2. Add a timestamp to a custom output file with a specific format:

    ts -l en -o result.json -f YYYYMMDDHHmmss
  3. Use a custom template file:

    ts -l fa -o result.json -t template.txt
  4. Use an inline template:

    ts -l fa -o result.json -i "{ test: '{ts}' }"
  5. Get help:

    ts --help

Programmatic Use

You can also use Timestamper as a module in your Node.js projects.

Example 1.

const { Timestamper } = require('@puya/ts');

const result = Timestamper({
    locale: 'en',
    outputFileName: 'result.json',
    template: '{ "hash": "{ts}" }',
    format: 'YYYYMMDDHHmmss'
});

if (result.success) {
    console.log(`Timestamp "result.json" generated successfully`);
} else {
    console.error('Failed to generate timestamp:', result.err);
}

Example 2. No output

const { Timestamper } = require('@puya/ts');

const result = Timestamper({
    locale: 'en',
    skipOutput: true,
    template: '{ "hash": "{ts}" }',
    format: 'YYYYMMDDHHmmss'
});

if (result.success) {
    console.log('Timestamp: ', result.data);
} else {
    console.error('Failed to generate timestamp:', result.err);
}

Variables

You can pass this variables:

  locale: "en", // or "fa"
  outputFileName: "output.json", //file will created at current dir
  templatePath: "", //template file path 
  format: "YYYYMMDDHHmm", //timestamp format
  inlineTemplate: "", //inline template (without path)
  skipOutput: false