JSPM

string-compiler

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q45248F
  • License ISC

This script compiles javascript code from a string and using a pattern string

Package Exports

  • string-compiler

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 (string-compiler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

String-Compiler v0.0.3 beta

This script compiles javascript code from a string and using a pattern string

Install:

$ npm install string-compiler

Import packages:

const { StringParser } = require('string-compiler')

StringParser.rules(/* text */, /* data */)

Testing commands:

$ npm test

Testing: ./test/test.*.js

JSON parse and use string-compiler

const fs = require('fs')
const { StringParser } = require('string-compiler')

let message = JSON.parse(fs.readFileSync('./test/messages/text.json', 'utf8'))

// Template strings are changed to transmitted data
console.log(StringParser.rules(message['test1'], { data: 'Hello World' }))
// Output: "Testing lib: Hello World"

// Or if there is no template line in the text and transfer data, then this data will be ignored
console.log(StringParser.rules(message['test2'], { data: 'Hello World' }))
// Output: "Testing lib!"

// Plain text output
console.log(StringParser.rules(message['test3']))
// Output: "Testing lib!"

// -- use more keys

console.log(StringParser.rules(message['go']['to']['name1'], { name: 'JavaScript' }))
// Output: "Hello JavaScript"
console.log(StringParser.rules(message['go']['to']['name2'], { name: 'JavaScript' }))
// Output: "Hello!"
console.log(StringParser.rules(message['go']['to']['name3']))
// Output: "Hello!"

Use string and use string-compiler

const { StringParser } = require('string-compiler')

// Template strings are changed to transmitted data
console.log(StringParser.rules('New message to the world: ${name}', { name: 'Hello World!' }))
// Output: "New message to the world: Hello World!"

// Or if there is no template line in the text and transfer data, then this data will be ignored
console.log(StringParser.rules('I am a programmer and I am writing?', { name: 'Hello World' }))
// Output: "I am a programmer and I am writing?"

// Plain text output
console.log(StringParser.rules('It turns out that { I } write hello world? $'))
// Output: "It turns out that { I } write hello world? $"