0.0.4 • Published 4 months ago

dollar-syntax v0.0.4

Weekly downloads
-
License
Unlicense
Repository
github
Last release
4 months ago

dollar-syntax

Use the dollar syntax in JavaScript. No dependencies.

Installation

npm

npm install dollar-syntax --save

yarn

yarn add dollar-syntax

Examples

Browser

<html>
	<head>
		<!-- Include the script -->
		<script src="lib/dollar-syntax.js"/>
	</head>
	<body>
		<script>
			const a = 7;
			const b = { value: 7 };
			const c = "7";
			// with a linter, this will not cause a warning
			const unused = "some unused value";
			console.log(number$(a)); // convert
			console.log(number$(b));
			console.log(number$(c));
			console.log(string$(b)); // a string convert
			console.log(object$(a).value); // an object convert
			console.log(object$(c).value);
			console.log(m$(number$, object$)(c).value); // convert to int and then to object
			// here the "unused" variable is "used"
			delete$(unused); // discard
			/*
			 * Output:
			 * 7
			 * 7
			 * 7
			 * "7"
			 * 7
			 * "7"
			 * 7
			 */
		</script>
	</body>
</html>

Node.js

require('dollar-syntax')(global);
const a = 7;
const b = { value: 7 };
const c = "7";
// with a linter, this will not cause a warning
const unused = "some unused value";
console.log(number$(a)); // convert
console.log(number$(b));
console.log(number$(c));
console.log(string$(b)); // a string convert
console.log(object$(a)); // an object convert
console.log(object$(c));
console.log(m$(number$, object$)(c)); // convert to int and then to object
// here the "unused" variable is "used"
delete$(unused); // discard
/*
 * Output:
 * 7
 * 7
 * 7
 * "7"
 * { value: 7 }
 * { value: "7" }
 * { value: 7 }
 */
0.0.4

4 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago