douglascrockford / fulfill Goto Github PK
View Code? Open in Web Editor NEWSafer, more cosmopolitan string interpolation.
Safer, more cosmopolitan string interpolation.
fulfill Douglas Crockford 2018-08-10 Public Domain The fulfill JavaScript function is a safer and more internationalizationable alternative to template string interprepolation. It is safer because it does not give the template variables access to all of the variables in the function scope, and it has a default encoder that removes angle brackets. It is more internationalizationable because the string can come from a source other than a string literal in the same file. For example, the string could come from a JSON bundle translation service. It is packaged as a module. fulfill(string, values, encoder) The string can contain symbolic variables in either of two forms: {path} {path:encoding} The path is a name or integer or a series of names or integers separated by periods that finds a value in the values argument. If all goes well, the symbolic variable will be replaced with the encoded value. If anything does not go well, then the symbolic variable is left alone. This makes debugging easier. It also allows for literal braces in the string without escapement. The values argument can be an object or array that supplies the values that will be substituted. It can be a nested data structure. The values can also be a function that returns the value that should be substituted. function values(path, encoding) The encoder can be a function that returns the value encoded as a safe string. function encoder(value, path, encoding) The encoder can also be an object of encoder functions. The property names are encodings. The default encoder removes angle brackets, making things safe for HTML. import fulfill from "./fulfill.js"; const example = fulfill( "{greeting}, {my.noun:upper}!", { greeting: "hello", my: {noun: "world"} }, function initial_caps(value) { return value.slice(0, 1).toUpperCase() + value.slice(1); } ); // example is "Hello, World!"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.