UNPKG

@wider/utils_proto

Version:

A set of extensions to basic objects giving uniform behaviour in various technical environments

93 lines (77 loc) 3.42 kB
'use strict'; /** * A test utility that can be run from node directly to demonstrate selected string functions. * *[Source code](./proto_string_test.js.html) * * Run from this package's main directory * * ```cmd * node ./proto_string/test.js * ... test output ... * ``` * * or * * ```cmd * $ node * Welcome to Node.js * > import("./proto_string/test.js").then(() => {process.exit()}) * Promise { pending } * > ... test output ... * $ * ``` * * @module @wider/utils_proto/proto_string/test * * @copyright Copyright (C) 1985..2021 Martin Baker. http://y-d-r.co.uk * @author Martin W Baker * @license ISC Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ class MyString extends String { constructor(value) { super(value); } } import assignString from "./index.js"; assignString(String, { markdown: false }); /*.then(() =>*/ { let s = "default String here we <> are"; console.log(s.wider_HTMLencode("markdown")); s += " -- and some more"; console.log(s.wider_HTMLencode("markdown")); const markupTest = async function () { console.log("# MARKDOWN #2\n\nthis is a successful markdown request #1\n\n* my markdown [here is link](./test.js)\n done using initialising promise".wider_HTMLencode("markdown")); }; markupTest(); // now try assigned to a custom class assignString(MyString); s = new MyString("custom myString here we <> are"); console.log(s.wider_HTMLencode("markdown")); s += " -- and some more"; console.log(s.wider_HTMLencode("markdown")); } const m_moduleName = assignString.$moduleName + "/test"; const m_title = m_moduleName + " demonstration"; console.log(m_title + ": starting test"); const demoString = "here we are in %siteName% running with %siteInitials%"; console.log(m_moduleName + ": original: " + demoString); console.log(m_moduleName + ": asHTML", demoString.wider_asHTML()); console.log(m_moduleName + ": wrapAsOK", demoString.wider_wrapAsOK(m_moduleName, "redo", m_title)); console.log(m_moduleName + ": wrapAsError", demoString.wider_wrapAsError(m_moduleName, "developer", m_title)); try { console.log(m_moduleName + ": standardMarkups: " + demoString.wider_standardMarkups()); } catch (e) { console.log("standardMarkups doesn't work unless the @wider/utils_bundle is installed by another package"); } console.log("# MARKDOWN #1\n\nthis is a markdown request that normally will not work as it is premature".wider_HTMLencode("markdown")); console.log(m_moduleName + ": test complete for " + m_title); console.log("# MARKDOWN #3\n\nthis is usually unsuccessful markdown request \n\n* my markdown [here is link](./test.js)\n done without a promise and without a nodejs loop break".wider_HTMLencode("markdown")); setTimeout(() => { console.log("# MARKDOWN #4\n\nthis is a successful markdown request \n\n* my markdown [here is link](./test.js)\n done later without a promise".wider_HTMLencode("markdown")); console.log("MARKDOWN #5\n\nthis is a successful markdown request triggered as inline \n\n* my markdown [here is link](./test.js)\n done later without a promise".wider_HTMLencode("markdown")); console.log(m_moduleName + ": done"); process.exit(); });