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

temject

v0.2.4

Published

template + injection = temject

Downloads

10

Readme

temject

template + injection = temject

'Hello, {{name:pascal}}! Today is {{__date}}'  
--> "Hello, World! Today is 2018-12-04"

Build Status Build status FOSSA Status

lukeed/templite: Lightweight templating in 150 bytes

Allows you to denote dynamic portions of a string using double curly brackets ({{ example }}) & then replace them with matching values from your data source.

You may attach an Object or an Array as your data source, which means you may use the object's keys or the array's indices to assign values.

Lastly, you may use dot-notated paths to access (deeply) nested values; eg: foo.bar.baz, 0.0.0, or foo.0.1.bar.

templite('Hello, {{name}}!', { name: 'world' });
//=> Hello, world!

temjecttempliteの機能を備えています。加えて以下の機能があります。

  • テンプレート文字列をパスカルケースやスネークケース等に変換できます
  • テンプレート文字列をdatetime(実行時の日付や時刻)に変換できます

blakeembrey/change-case

Convert strings between camelCase, PascalCase, Title Case, snake_case, lowercase, UPPERCASE, CONSTANT_CASE and more.

const x = 'Hello, {{name:pascal}}! Today is {{__date}}'
const y = { name: 'world' }
temject(x, y)
// -> "Hello, World! Today is 2018-12-04"

install

npm install --save temject

Usage

const { temject } = require('temject')
const x = `
// createdAt: {{__date}}
// path/to/MyProject/{{name}}.js

class {{name:pascal}} {}`

const y = { name: 'myFunction' }
temject(x, y)

// ->
/*
// createdAt: 2018-12-04
// path/to/MyProject/myFunction.js

class MyFunction {}
*/

API - templite

templite本来のapiは以下を参照願います。 (templiteの部分をtemjectに変えるのをお忘れなく)

templite: API

Do not forget to change the templite part to temject.

API - temject original

temject(input, values)

下記のkeyValueInjectordateTimeInjectorをまとめて実行します。特に分ける必要がなければこの関数だけでtemjectの機能は網羅しています。

// example
const { temject } = require('temject')
const x = 'Hello, {{name:pascal}}! Today is {{__date}}'
const y = { name: 'world' }
// -> ' "Hello, World! Today is 2018-12-04"

keyValueInjector(input, values)

templiteの機能はそのまま使えます。さらにchange-case関数で変換する機能を加えています

テンプレート文字列を:で区切ると変換関数を指定できます。例えばパスカルケースに変換するには{{name:pascal}}とします。

You can specify a conversion function by separating the template string with :. For example, to convert it to a Pascal case, we use {{name:pascal}}.

// example
'Hello, {{name:pascal}}!'

変換関数はchange-caseモジュールを使っています。以下の関数名を指定できます。

The conversion function uses the change-case module. The following function names can be specified.

change-case: usage

camel
constant
dot
header
isLower
isUpper
lower
lcFirst
no
param
pascal
path
sentence
snake
swap
title
upper
ucFirst

Example

temject('{{key: camel}}', { key: 'helloWorld' })
/* change the first argument
{{key: camel}} :  helloWorld 
{{key: constant}} :  HELLO_WORLD 
{{key: dot}} :  hello.world 
{{key: header}} :  Hello-World 
{{key: isLower}} :  false 
{{key: isUpper}} :  false 
{{key: lower}} :  helloworld 
{{key: lcFirst}} :  helloWorld 
{{key: no}} :  hello world 
{{key: param}} :  hello-world 
{{key: pascal}} :  HelloWorld 
{{key: path}} :  hello/world 
{{key: sentence}} :  Hello world 
{{key: snake}} :  hello_world 
{{key: swap}} :  HELLOwORLD 
{{key: title}} :  Hello World 
{{key: upper}} :  HELLOWORLD 
{{key: ucFirst}} :  HelloWorld
*/
// example
const {keyValueInjector} = require('temject')
keyValueInjector('Hello, {{name:pascal}}!', {name: 'mick'})
// -> Hello, Mick!

dateTimeInjector(input)

テンプレート文字列内部の先頭を__(アンダースコア2つ)で始めるとdatetimeを注入できます。

You can inject a datetime by beginning the inside of the template string with __ (two underscores).

以下の文字列で日付が注入できます。

You can inject dates with the following strings:

'{{__date}}'

他にも以下の日付形式が使用できます。

The following date formats can be used.

{{__year}} 2018 
{{__date}} 2018-12-04 
{{__Date}} 2018/12/04 
{{__datetime}} 2018-12-04 20:05:24 
{{__Datetime}} 2018/12/04 20:05:24 
{{__month}} 2018-12 
{{__Month}} 2018/12 

また、 date-and-timeのformatが使用できます。

You can also use date-and-time format.

{{__ddd MMM DD YYYY}} :  Tue Dec 04 2018 
{{__hh:mm A [GMT]Z}} :  08:21 p.m. GMT+0900 
Today is {{__dddd}} :  Today is Tuesday

おまけ機能ですが、簡単なhashも生成できます

{{__hash8}} :  3mwe4xGQ 
{{__hash16}} :  VaAv3mwe4xGQj1qB 
{{__hash24}} :  dLy0VaAv3mwe4xGQj1qBrKM4
// example
const { dateTimeInjector } = require('temject')
dateTimeInjector('{{0:camel}}{{0:pascal}}{{0:dot}}', ['toDo'])
// -> 'toDoToDoto.do'

expressions(input)

template内全てのkeyを取得します。 重複は省かれます。

const {expressions} = require('temject');
const str = '{{name}}{{name:pascal}}{{age}}'
expressions(str)
// -> [ 'name', 'age' ]
expressions(str, { ignore: ['name'] })
// -> [ 'age' ]

License

MIT © mick-whats

FOSSA Status