constjsJavaScript 工具
简单的 JavaScript 工具,用于创建 enum (仿真Java),String constants, 以及 bitmap 数据结构:
var ConstJs = require('constjs'); // Enum var Colors = ConstJs.enum("blue red"); var myColor = Colors.blue; console.log(myColor.isBlue()); // output true console.log(myColor.is('blue')); // output true console.log(myColor.is('BLUE')); // output true console.log(myColor.is(0)); // output true console.log(myColor.is(Colors.blue)); // output true console.log(myColor.isRed()); // output false console.log(myColor.is('red')); // output false console.log(myColor._id); // output blue console.log(myColor.name()); // output blue console.log(myColor.toString()); // output blue // String constants var Weekdays = ConstJs.const("Mon, Tue, Wed"); console.log(Weekdays); // output {Mon: 'Mon', Tue: 'Tue', Wed: 'Wed'} var today = Weekdays.Wed; console.log(today); // output: 'Wed'; // Bitmap var ColorFlags = ConstJs.bitmap("blue red"); console.log(ColorFlags.blue); // output false var StyleFlags = ConstJs.bitmap(true, "rustic model minimalist"); console.log(StyleFlags.rustic); // output true var CityFlags = ConstJs.bitmap({Chengdu: true, Sydney: false}); console.log(CityFlags.Chengdu); //output true console.log(CityFlags.Sydney); // output false var DayFlags = ConstJs.bitmap(true, {Mon: false, Tue: true}); console.log(DayFlags.Mon); // output false. Default val wont override specified val if the type is boolean
评论