Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / exotic   js

Repository URL to install this package:

Version: 2.0.8 

/ README.md

exotic

it can be done in other languages, never before in js

in ocaml

https://reasonml.github.io/guide/javascript/converting/

in scala

https://alvinalexander.com/scala/how-to-cast-objects-class-instance-in-scala-asinstanceof https://twitter.github.io/scala_school/advanced-types.html https://docs.scala-lang.org/style/types.html

in swift

http://www.thomashanning.com/type-casting-in-swift/ https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TypeCasting.html

in C

https://msdn.microsoft.com/en-us/library/system.iconvertible.aspx https://msdn.microsoft.com/en-us/library/dtb69x08(v=vs.110).aspx

in python

http://pybind11.readthedocs.io/en/stable/advanced/cast/custom.html

in ruby

https://idiosyncratic-ruby.com/54-try-converting.html

in go lang

https://play.golang.org/p/sYm1jTCMIf http://www.golangbootcamp.com/book/types https://thenewstack.io/understanding-golang-type-system/

in haskell

http://book.realworldhaskell.org/read/using-typeclasses.html

in erlang

http://erlang.org/doc/reference_manual/data_types.html

in smalltalk

https://www.gnu.org/software/smalltalk/manual/gst.html#Smalltalk-types

in js

https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/Type_conversion http://webreflection.blogspot.ca/2011/09/introduction-to-js-ctypes.html


cast

cast & coerce values

why?

TypeGuards

(the assumption based on research & testing the compiled code, though it is likely there are more things to check and more known unknowns)

  • megamorphic code wrapping the monomorphic code is perfect

  • with the arg casting, it makes a solid decision tree, which ends up just becoming a GO TO LINE# -> easily optimized cast function "

  • this is how typescript should compile

  • this is likely why lodash has internal functions called base

  • the other way to handle it is throw errors with invalid types

  • almost every library has some "isX" util

  • @example isFunction, isNull, isError,

  • they get really hot, and they are really small, so they get inlined blazing fast and it's dope

  • ... but if you have say 3 libraries, and each one has their own isFunction or isNull, that defeats the purpose! need a build function & compat checker to replace & merge as needed for best perf in apps not just libs


resources

is/check

https://tc39.github.io/ecma262/#sec-well-known-intrinsic-objects https://github.com/lodash/lodash/blob/master/.internal/isPrototype.js https://tc39.github.io/ecma262/#sec-property-descriptor-specification-type https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger


https://github.com/infernojs/inferno/blob/master/packages/inferno-shared/src/index.ts https://www.npmjs.com/package/kind-of

https://github.com/lodash/lodash/blob/master/.internal/baseGetTag.js https://github.com/lodash/lodash/blob/master/.internal/getTag.js https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures https://github.com/canjs/can-util/tree/master/js

https://github.com/bitovi/guide-automation https://github.com/bitovi/checklist https://github.com/bitovi/u https://github.com/bitovi/steal-tools-builder https://github.com/addyosmani/es6-tools

https://github.com/madrobby/zepto http://code.jquery.com/jquery-3.2.1.js https://github.com/sstephenson/prototype

https://tc39.github.io/ecma262/#sec-object.isfrozen

https://github.com/deanmao/coerce/blob/master/lib/coerce.js https://github.com/beatgammit/cast/blob/master/lib/cast.js https://github.com/alexlawrence/typed https://www.npmjs.com/package/typecast

http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-intrinsic-objects